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

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

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

Restlet介绍

[英]Uniform class that provides a context and life cycle support. It has many subclasses that focus on specific ways to process calls. The context property is typically provided by a parent Component as a way to encapsulate access to shared features such as logging and client connectors.

Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.
[中]提供上下文和生命周期支持的统一类。它有许多子类,专注于处理调用的特定方式。context属性通常由父组件提供,作为封装对共享功能(如日志记录和客户端连接器)的访问的一种方式。
并发性注意:这个类或其子类的实例可以由多个线程同时调用,因此必须是线程安全的。在成员变量中存储状态时,应该特别小心。

代码示例

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

/**
 * Constructor.
 * 
 * @param context
 *            The context from which the client dispatcher will be
 *            retrieved.
 * @param categoriesUri
 *            The feed URI.
 * @throws IOException
 */
public Categories(Context context, String categoriesUri) throws IOException {
  this(context.getClientDispatcher()
      .handle(new Request(Method.GET, categoriesUri)).getEntity());
}

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

@Override
public synchronized void start() throws Exception {
  wrappedRestlet.start();
}

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

/**
 * Checks the context and sets it if necessary.
 * 
 * @param target
 *            The target Restlet.
 */
protected void checkContext(Restlet target) {
  if ((target.getContext() == null) && (this.parentContext != null)) {
    target.setContext(this.parentContext.createChildContext());
  }
}

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

/**
 * Attempts to {@link #stop()} the Restlet if it is still started.
 */
@Override
protected void finalize() throws Throwable {
  if (isStarted()) {
    stop();
  }
  super.finalize();
}

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

/**
 * Sets the outbound root Restlet.
 * 
 * @param outboundRoot
 *            The outbound root Restlet.
 */
public synchronized void setOutboundRoot(Restlet outboundRoot) {
  this.outboundRoot = outboundRoot;
  if ((outboundRoot != null) && (outboundRoot.getContext() == null)) {
    outboundRoot.setContext(getContext());
  }
}

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

Response response = this.context.getClientDispatcher().handle(
    new Request(Method.GET, targetUri));
if (response.getStatus().isSuccess()
    && response.isEntityAvailable()) {
  try {
    result = new StreamSource(response.getEntity().getStream());
    result.setSystemId(targetUri);
    this.context.getLogger().log(Level.WARNING,
        "I/O error while getting the response stream", e);

代码示例来源:origin: com.whizzosoftware.hobson.hub/hobson-hub-setup

public void handle(Request request, Response response) {
    if (request.getResourceRef().getScheme().equalsIgnoreCase("clap")) {
      request.getAttributes().put("org.restlet.clap.classLoader", bundleClassLoader);
    }
    dispatcher.handle(request, response);
  }
}

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

/**
 * Deletes a resource.
 * 
 * @param uri
 *            The resource URI.
 * @return The result status.
 */
public Status deleteResource(String uri) {
  return getClientDispatcher().handle(new Request(Method.DELETE, uri))
      .getStatus();
}

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

Response.setCurrent(response);
if (getContext() != null) {
  Context.setCurrent(getContext());
if (isStopped()) {
  try {
    start();
  } catch (Exception e) {
    if (getContext() != null) {
      getContext().getLogger().log(Level.WARNING,
          UNABLE_TO_START, e);
    } else {
      Context.getCurrentLogger().log(Level.WARNING,
          UNABLE_TO_START, e);
    response.setStatus(Status.SERVER_ERROR_INTERNAL);
  if (!isStarted()) {
    getContext().getLogger().log(Level.WARNING, UNABLE_TO_START);
    response.setStatus(Status.SERVER_ERROR_INTERNAL);

代码示例来源:origin: org.metaeffekt.dcc/dcc-agent-core

@Override
public void handle(Request request, Response response) {
  LOG.debug("MethodRouter [{}] received request method: [{}]"
      , uriPattern, request.getMethod());
  Restlet target = routes.get(request.getMethod());
  if (target != null) {
    target.handle(request, response);
  } else {
    LOG.debug("No route for request method: [{}]", request.getMethod());
    response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
  }
}

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

@Override
public Representation put(Representation entity) throws ResourceException {
  if (!this.directory.isModifiable()) {
    setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED, "The directory is not modifiable.");
    return null;
  }
  // Transfer of PUT calls is only allowed if the readOnly flag is not set.
  Request contextRequest = new Request(Method.PUT, this.targetUri);
  // Add support of partial PUT calls.
  contextRequest.getRanges().addAll(getRanges());
  contextRequest.setEntity(entity);
  Response contextResponse = new Response(contextRequest);
  contextRequest.setResourceRef(this.targetUri);
  getClientDispatcher().handle(contextRequest, contextResponse);
  setStatus(contextResponse.getStatus());
  return null;
}

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

/**
 * Posts a member to the collection resulting in the creation of a new
 * resource.
 * 
 * @param member
 *            The member representation to post.
 * @return The reference of the new resource.
 * @throws Exception
 */
public Reference postMember(Representation member) throws Exception {
  final Request request = new Request(Method.POST, getHref(), member);
  final Response response = getWorkspace().getService()
      .getClientDispatcher().handle(request);
  if (response.getStatus().equals(Status.SUCCESS_CREATED)) {
    return response.getLocationRef();
  }
  throw new Exception(
      "Couldn't post the member representation. Status returned: "
          + response.getStatus());
}

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

/**
 * Retrieves a resource representation.
 * 
 * @param uri
 *            The resource URI.
 * @return The resource representation.
 */
public Representation getResource(String uri) {
  return getClientDispatcher().handle(new Request(Method.GET, uri))
      .getEntity();
}

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

/**
 * Returns a representation of the resource at the target URI. Leverages the
 * client dispatcher of the parent directory's context.
 * 
 * @param resourceUri
 *            The URI of the target resource.
 * @param acceptedMediaType
 *            The accepted media type or null.
 * @return A response with the representation if success.
 */
protected Response getRepresentation(String resourceUri, MediaType acceptedMediaType) {
  Request request = new Request(Method.GET, resourceUri);
  if (acceptedMediaType != null) {
    request.getClientInfo().accept(acceptedMediaType);
  }
  return getClientDispatcher().handle(request);
}

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

@Override
public void handle(Request request, Response response) {
  super.handle(request, response);
  if (getFirstInboundFilter() != null) {
    getFirstInboundFilter().handle(request, response);
  } else {
    final Restlet next = this.inboundNext;
    if (next != null) {
      next.handle(request, response);
    } else {
      response.setStatus(Status.SERVER_ERROR_INTERNAL);
      getHelped()
          .getLogger()
          .log(Level.SEVERE,
              "The "
                  + getHelped().getClass().getName()
                  + " class has no Restlet defined to process calls. Maybe it wasn't properly started.");
    }
  }
}

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

/**
 * Handles a call by invoking the next Restlet if it is available.
 * 
 * @param request
 *            The request to handle.
 * @param response
 *            The response to update.
 */
@Override
public void handle(Request request, Response response) {
  super.handle(request, response);
  Restlet next = getNext(request, response);
  if (next != null) {
    doHandle(next, request, response);
  } else {
    response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
  }
}

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

/**
 * Handles the case, if no resource class was found. If a Restlet to handle
 * this case was given (see {@link #setNoResourceClHandler(Restlet)}), it is
 * called. Otherwise a {@link WebApplicationException} with status 404 is
 * thrown (see spec, section 3.7.2, item 2e)
 * 
 * @throws WebApplicationException
 * @throws RequestHandledException
 */
public void resourceNotFound() throws WebApplicationException,
    RequestHandledException {
  if (this.noResourceClHandler != null) {
    this.noResourceClHandler.handle(Request.getCurrent(),
        org.restlet.Response.getCurrent());
    throw new RequestHandledException();
  }
  throw new WebApplicationException(Status.NOT_FOUND);
}

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

@Override
public void handle(Request request, Response response) {
  wrappedRestlet.handle(request, response);
}

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

/**
 * Returns the helped Restlet logger.
 * 
 * @return The helped Restlet logger.
 */
public Logger getLogger() {
  return (getHelped().getContext() != null) ? getHelped().getContext()
      .getLogger() : Context.getCurrentLogger();
}

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

/**
 * Returns a representation of the resource at the target URI. Leverages the
 * client dispatcher of the parent directory's context.
 * 
 * @param resourceUri
 *            The URI of the target resource.
 * @return A response with the representation if success.
 */
private Response getRepresentation(String resourceUri) {
  return getClientDispatcher().handle(
      new Request(Method.GET, resourceUri));
}

相关文章