org.restlet.data.Request类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(265)

本文整理了Java中org.restlet.data.Request类的一些代码示例,展示了Request类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request类的具体详情如下:
包路径:org.restlet.data.Request
类名称:Request

Request介绍

[英]Generic request sent by client connectors. It is then received by server connectors and processed by Restlets. This request can also be processed by a chain of Restlets, on both client and server sides. Requests are uniform across all types of connectors, protocols and components.
[中]客户端连接器发送的通用请求。然后由服务器连接器接收,并由RESTlet处理。这个请求也可以由客户端和服务器端的RESTlet链来处理。所有类型的连接器、协议和组件的请求都是统一的。

代码示例

代码示例来源:origin: internetarchive/heritrix3

/**
 * Constructs a nested Map data structure with the information represented
 * by this Resource. The result is particularly suitable for use with with
 * {@link XmlMarshaller}.
 * 
 * @return the nested Map data structure
 */
protected ScriptModel makeDataModel() {
  
  String baseRef = getRequest().getResourceRef().getBaseRef().toString();
  if(!baseRef.endsWith("/")) {
    baseRef += "/";
  }
  Reference baseRefRef = new Reference(baseRef);
  
  ScriptModel model = new ScriptModel(scriptingConsole,
      new Reference(baseRefRef, "..").getTargetRef().toString(),
      getAvailableScriptEngines());
  return model;
}

代码示例来源:origin: internetarchive/heritrix3

public JobRelatedResource(Context ctx, Request req, Response res) throws ResourceException {
  super(ctx, req, res);
  cj = getEngine().getJob((String)req.getAttributes().get("job"));
  if(cj==null) {
    throw new ResourceException(404);
  }
}

代码示例来源:origin: internetarchive/heritrix3

/**
 * If client can accept text/html, always prefer it. WebKit-based browsers
 * claim to want application/xml, but we don't want to give it to them. See
 * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a>
 */
public Variant getPreferredVariant() {
  boolean addExplicitTextHtmlPreference = false;
  for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) {
    if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) {
      mediaTypePreference.setQuality(Float.MAX_VALUE);
      addExplicitTextHtmlPreference = false;
      break;
    } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) {
      addExplicitTextHtmlPreference = true;
    }
  }
  
  if (addExplicitTextHtmlPreference) {
    List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes();
    acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE));
    getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes);
  }
  
  
  return super.getPreferredVariant();
}

代码示例来源:origin: internetarchive/heritrix3

public void acceptRepresentation(Representation entity) throws ResourceException {
  if (appCtx == null) {
    throw new ResourceException(404);
  }
  // copy op?
  Form form = getRequest().getEntityAsForm();
  beanPath = form.getFirstValue("beanPath");
  
  String newVal = form.getFirstValue("newVal");
  if(newVal!=null) {
    int i = beanPath.indexOf(".");
    String beanName = i<0?beanPath:beanPath.substring(0,i);
    Object namedBean = appCtx.getBean(beanName);
    BeanWrapperImpl bwrap = new BeanWrapperImpl(namedBean);
    String propPath = beanPath.substring(i+1);
    Object coercedVal = bwrap.convertIfNecessary(newVal, bwrap.getPropertyValue(propPath).getClass()); 
    bwrap.setPropertyValue(propPath, coercedVal);
  }
  Reference ref = getRequest().getResourceRef();
  ref.setPath(getBeansRefPath());
  ref.addSegment(beanPath);
  getResponse().redirectSeeOther(ref);
}

代码示例来源:origin: internetarchive/heritrix3

protected void writeHtml(Writer writer) {
    
    String baseRef = getRequest().getResourceRef().getBaseRef().toString();
    if(!baseRef.endsWith("/")) {
      baseRef += "/";
    }
    Configuration tmpltCfg = getTemplateConfiguration();

    ViewModel viewModel = new ViewModel();
    viewModel.setFlashes(Flash.getFlashes(getRequest()));
    viewModel.put("baseRef",baseRef);
    viewModel.put("staticRef", getStaticRef(""));
    viewModel.put("baseResourceRef",getRequest().getRootRef().toString()+"/engine/static/");
    viewModel.put("model", makeDataModel());
    viewModel.put("selectedEngine", chosenEngine);

    try {
      Template template = tmpltCfg.getTemplate("Script.ftl");
      template.process(viewModel, writer);
      writer.flush();
    } catch (IOException e) { 
      throw new RuntimeException(e); 
    } catch (TemplateException e) { 
      throw new RuntimeException(e); 
    }

  }
}

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

protected String buildUploadFailedHtmlResponse(Throwable t, Request request, Response response) {
 try {
  handleException(request, response, t);
 }
 catch (ResourceException e) {
  getLogger().debug("Got error while uploading artifact", t);
  StringBuilder resp = new StringBuilder();
  resp.append("<html><body><error>");
  resp.append(StringEscapeUtils.escapeHtml(e.getMessage()));
  resp.append("</error></body></html>");
  String forceSuccess = request.getResourceRef().getQueryAsForm().getFirstValue("forceSuccess");
  if (!"true".equals(forceSuccess)) {
   response.setStatus(e.getStatus());
  }
  return resp.toString();
 }
 // We have an error at this point, can't get here
 return null;
}

代码示例来源:origin: internetarchive/heritrix3

/**
 * Constructs a nested Map data structure with the information represented
 * by this Resource. The result is particularly suitable for use with with
 * {@link XmlMarshaller}.
 * 
 * @return the nested Map data structure
 */
protected CrawlJobModel makeDataModel() {
  String baseRef = getRequest().getResourceRef().getBaseRef().toString();
  if (!baseRef.endsWith("/")) {
    baseRef += "/";
  }
  return new CrawlJobModel(cj,baseRef);
}

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

protected boolean isDescribe( Request request )
{
  // check do we need describe
  return request.getResourceRef().getQueryAsForm().getFirst( IS_DESCRIBE_PARAMETER ) != null;
}

代码示例来源:origin: org.sonatype.nexus/nexus-it-helper-plugin

public Object get(Context context, Request request, Response response, Variant variant)
   throws ResourceException
 {
  Form form = request.getResourceRef().getQueryAsForm();
  final long timeout = Long.parseLong(form.getFirstValue("timeout", "60000"));
  try {
   final long startTime = System.currentTimeMillis();
   while (System.currentTimeMillis() - startTime <= timeout) {
    if (!((ManagerImpl) manager).isUpdatePrefixFileJobRunning()) {
     response.setStatus(Status.SUCCESS_OK);
     return "Ok";
    }
    Thread.sleep(500);
   }
  }
  catch (final InterruptedException ignore) {
   // ignore
  }
  response.setStatus(Status.SUCCESS_ACCEPTED);
  return "Still munching on them...";
 }
}

代码示例来源:origin: org.restlet/org.restlet

Response response) {
final Reference baseRef = request.getResourceRef().getBaseRef();
request.setResourceRef(targetRef);
request.getAttributes().remove("org.restlet.http.headers");
getContext().getClientDispatcher().handle(request, response);
response.setEntity(rewrite(response.getEntity()));
response.getAttributes().remove("org.restlet.http.headers");
  final Template rt = new Template(this.targetTemplate);
  rt.setLogger(getLogger());
  final int matched = rt.parse(response.getLocationRef().toString(),
      request);
    final String remainingPart = (String) request.getAttributes()
        .get("rr");
      response.setLocationRef(baseRef.toString() + remainingPart);

代码示例来源:origin: org.sonatype.nexus/nexus-it-helper-plugin

@Override
 public Object get(Context context, Request request, Response response, Variant variant)
   throws ResourceException
 {
  Form form = request.getResourceRef().getQueryAsForm();

  int requestedStatus = Integer.parseInt(form.getFirstValue("status"));

  throw new ResourceException(requestedStatus);
 }
}

代码示例来源:origin: internetarchive/heritrix3

public List<Variant> getVariants() {
  List<Variant> variants = super.getVariants();
  Form f = getRequest().getResourceRef().getQueryAsForm();
  String format = f.getFirstValue("format");
  if("textedit".equals(format)) {
    if(variants.isEmpty()) {
              FileRepresentation)v,
              this,
              f.getFirstValue("pos"),
              f.getFirstValue("lines"),
              f.getFirstValue("reverse")));
        };

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

public String getRestRepoRemoteStatus( ProxyRepository repository, Request request, Response response )
  throws ResourceException
{
  Form form = request.getResourceRef().getQueryAsForm();
  boolean forceCheck = form.getFirst( "forceCheck" ) != null;
  RemoteStatus rs =
    repository.getRemoteStatus( new ResourceStoreRequest( RepositoryItemUid.PATH_ROOT ), forceCheck );
  if ( RemoteStatus.UNKNOWN.equals( rs ) )
  {
    // set status to ACCEPTED, since we have incomplete info
    response.setStatus( Status.SUCCESS_ACCEPTED );
  }
  return rs == null ? null : rs.toString();
}

代码示例来源:origin: org.geowebcache/gwc-rest

/**
 * GET outputs an existing layer
 * 
 * @param req
 * @param resp
 * @throws RestletException
 * @throws
 */
protected void doGet(Request req, Response resp) throws RestletException {
  String layerName = (String) req.getAttributes().get("layer");
  final String formatExtension = (String) req.getAttributes().get("extension");
  Representation representation;
  if (layerName == null) {
    String restRoot = req.getResourceRef().getParentRef().toString();
    if (restRoot.endsWith("/")) {
      restRoot = restRoot.substring(0, restRoot.length() - 1);
    }
    representation = listLayers(formatExtension, restRoot);
  } else {
    try {
      layerName = URLDecoder.decode(layerName, "UTF-8");
    } catch (UnsupportedEncodingException uee) {
    }
    representation = doGetInternal(layerName, formatExtension);
  }
  resp.setEntity(representation);
}

代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-launcher

final Request request = new Request();
request.setResourceRef(url.toString());
request.setMethod(method);
 request.setEntity(representation);
  request.getClientInfo().getAcceptedMediaTypes().add(
    new Preference<MediaType>(representation.getMediaType()));

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

@Override
public Object upload(Context context, Request request, Response response, List<FileItem> files)
  throws ResourceException
{
 // NEXUS-4151: Do not accept upload/deploy requests with media type (Content-Type) of
 // "application/x-www-form-urlencoded", since ad 1, it's wrong, ad 2, we do know
 // Jetty's Request object "eats" up it's body to parse request parameters, invoked
 // way earlier in security filters
 if (request.isEntityAvailable()) {
  MediaType mt = request.getEntity().getMediaType();
  if (mt != null && MediaType.APPLICATION_WWW_FORM.isCompatible(mt)) {
   throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Content-type of \"" + mt.toString()
     + "\" is not acceptable for uploads!");
  }
 }
 try {
  final ResourceStoreRequest req = getResourceStoreRequest(request);
  for (FileItem fileItem : files) {
   getResourceStore(request).storeItem(req, fileItem.getInputStream(), null);
  }
 }
 catch (Exception t) {
  handleException(request, response, t);
 }
 return null;
}

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

public static String findIP( Request request )
{
  Form form = (Form) request.getAttributes().get( "org.restlet.http.headers" );
  String forwardedIP = getFirstForwardedIp( form.getFirstValue( FORWARD_HEADER ) );
  if ( forwardedIP != null )
  {
    return forwardedIP;
  }
  List<String> ipAddresses = request.getClientInfo().getAddresses();
  return resolveIp( ipAddresses );
}

代码示例来源:origin: org.restlet/org.restlet

/**
 * Sets the reference that the client should follow for redirections or
 * resource creations. If you pass a relative location URI, it will be
 * resolved with the current base reference of the request's resource
 * reference (see {@link Request#getResourceRef()} and
 * {@link Reference#getBaseRef()}.
 * 
 * @param locationUri
 *            The URI to set.
 */
public void setLocationRef(String locationUri) {
  Reference baseRef = null;
  if (getRequest().getResourceRef() != null) {
    if (getRequest().getResourceRef().getBaseRef() != null) {
      baseRef = getRequest().getResourceRef().getBaseRef();
    } else {
      baseRef = getRequest().getResourceRef();
    }
  }
  setLocationRef(new Reference(baseRef, locationUri).getTargetRef());
}

代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-launcher

@Override
public HttpClientCall create(Request request) {
 HttpClientCall result = null;
 try {
  result = new Hc4MethodCall(this, request.getMethod().toString(),
    request.getResourceRef().toString(), request
    .isEntityAvailable());
 }
 catch (IOException ioe) {
  getLogger().log(Level.WARNING,
    "Unable to create the HTTP client call", ioe);
 }
 return result;
}

代码示例来源:origin: internetarchive/heritrix3

public String getBeansRefPath() {
  Reference ref = getRequest().getResourceRef();
  String path = ref.getPath(); 
  int i = path.indexOf("/beans/");
  if(i>0) {
    return path.substring(0,i+"/beans/".length());
  }
  if(!path.endsWith("/")) {
    path += "/";
  }
  return path; 
}

相关文章