ServerResource
Code IndexAdd Codota to your IDE (free)

Best Java code snippets using org.restlet.resource.ServerResource (Showing top 20 results out of 315)

  • Common ways to obtain ServerResource
private void myMethod () {
ServerResource s =
  • Finder finder;finder.find(null, null)
  • Smart code suggestions by Codota
}
origin: org.restlet.osgi/org.restlet

/**
 * Returns the first annotation descriptor matching the given method.
 * 
 * @param method
 *            The method to match.
 * @param query
 *            The query parameters.
 * @param entity
 *            The request entity or null.
 * @return The annotation descriptor.
 * @throws IOException
 */
private MethodAnnotationInfo getAnnotation(Method method, Form query,
    Representation entity) throws IOException {
  if (isAnnotated()) {
    return AnnotationUtils.getInstance().getMethodAnnotation(
        getAnnotations(), method, query, entity,
        getMetadataService(), getConverterService());
  }
  return null;
}
origin: org.restlet.jee/org.restlet.ext.wadl

@Override
protected void doInit() throws ResourceException {
  super.doInit();
  this.autoDescribing = true;
}
origin: org.restlet.osgi/org.restlet

Method method = getMethod();
  setStatus(Status.CLIENT_ERROR_BAD_REQUEST, "No method specified");
} else {
  if (method.equals(Method.PUT)) {
    result = put(getRequestEntity());
  } else if (method.equals(Method.PATCH)) {
    result = patch(getRequestEntity());
  } else if (isExisting()) {
    if (method.equals(Method.GET)) {
      result = get();
    } else if (method.equals(Method.POST)) {
      result = post(getRequestEntity());
    } else if (method.equals(Method.DELETE)) {
      result = delete();
    } else if (method.equals(Method.HEAD)) {
      result = head();
    } else if (method.equals(Method.OPTIONS)) {
      result = options();
    } else {
      result = doHandle(method, getQuery(), getRequestEntity());
    doError(Status.CLIENT_ERROR_NOT_FOUND);
origin: org.restlet.osgi/org.restlet

/**
 * Returns a modifiable list of exposed variants for the current request
 * method. You can declare variants manually by updating the result list ,
 * by overriding this method. By default, the variants will be provided
 * based on annotated methods.
 * 
 * @return The modifiable list of variants.
 * @throws IOException
 */
public List<Variant> getVariants() {
  return getVariants(getMethod());
}
origin: org.restlet.osgi/org.restlet

Representation result = null;
if ((getVariants() != null) && (!getVariants().isEmpty())) {
  Variant preferredVariant = getPreferredVariant(getVariants());
    doError(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
    result = describeVariants();
  } else {
    updateDimensions();
    result = doHandle(preferredVariant);
  result = doHandle();
origin: org.restlet.osgi/org.restlet

/**
 * Indicates the communication options available for this resource. This
 * method is only invoked if content negotiation has been disabled as
 * indicated by the {@link #isNegotiated()}, otherwise the {@link #options(Variant)} method is invoked.<br>
 * <br>
 * The default behavior is to set the response status to
 * {@link org.restlet.data.Status#CLIENT_ERROR_METHOD_NOT_ALLOWED}.
 * 
 * @return The optional response entity.
 */
protected Representation options() throws ResourceException {
  Representation result = null;
  MethodAnnotationInfo annotationInfo;
  try {
    annotationInfo = getAnnotation(Method.OPTIONS);
    // Updates the list of allowed methods
    updateAllowedMethods();
    if (annotationInfo != null) {
      result = doHandle(annotationInfo, null);
    } else {
      doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
    }
  } catch (IOException e) {
    throw new ResourceException(e);
  }
  return result;
}
origin: org.restlet.osgi/org.restlet

if (!isExisting() && getMethod().isSafe()) {
  doError(Status.CLIENT_ERROR_NOT_FOUND);
} else {
  try {
    if (isConditional()) {
      result = doConditionalHandle();
    } else if (isNegotiated()) {
      result = doNegotiatedHandle();
    } else {
      result = doHandle();
      getResponse().setEntity(result);
    doCatch(t);
  } finally {
    if (Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.equals(getStatus())) {
      updateAllowedMethods();
    } else if (Status.SUCCESS_OK.equals(getStatus())
        && (getResponseEntity() == null || !getResponseEntity()
            .isAvailable())) {
      getLogger()
          .fine("A response with a 200 (Ok) status should have an entity. "
              + "Changing the status to 204 (No content).");
      setStatus(Status.SUCCESS_NO_CONTENT);
origin: org.restlet.osgi/org.restlet

if (isAnnotated() && hasAnnotations()) {
  List<Variant> annoVariants = null;
  method = (Method.HEAD.equals(method)) ? Method.GET : method;
  for (AnnotationInfo annotationInfo : getAnnotations()) {
    try {
      if (annotationInfo instanceof MethodAnnotationInfo) {
            .isCompatible(method, getQuery(),
                getRequestEntity(),
                getMetadataService(),
                getConverterService())) {
          annoVariants = methodAnnotationInfo
              .getResponseVariants(
                  getMetadataService(),
                  getConverterService());
            if ((getRequest().getEntity() != null)
                && getRequest().getEntity()
                    .isAvailable()) {
              MediaType emt = getRequest()
                  .getEntity().getMediaType();
              List<MediaType> amts = getMetadataService()
                  .getAllMediaTypes(
                      methodAnnotationInfo
      getLogger().log(Level.FINE,
          "Unable to get variants from annotation", e);
origin: org.restlet.osgi/org.restlet

if (getConditions().hasSome()) {
  RepresentationInfo resultInfo = null;
    if (isNegotiated()) {
      Variant preferredVariant = getPreferredVariant(getVariants(Method.GET));
          && getConnegService().isStrict()) {
        doError(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
      } else {
        resultInfo = doGetInfo(preferredVariant);
      resultInfo = doGetInfo();
      if ((getStatus() == null)
          || (getStatus().isSuccess() && !Status.SUCCESS_NO_CONTENT
              .equals(getStatus()))) {
        doError(Status.CLIENT_ERROR_NOT_FOUND);
      } else {
      Status status = getConditions().getStatus(getMethod(),
          resultInfo);
          doError(status);
        } else {
          setStatus(status);
    Status status = getConditions().getStatus(getMethod(),
        resultInfo);
origin: org.restlet.jee/org.restlet.ext.wadl

  ServerResource resource) {
MetadataService metadataService = resource.getMetadataService();
List<AnnotationInfo> annotations = resource.isAnnotated() ? AnnotationUtils
    .getInstance().getAnnotations(resource.getClass()) : null;
                  resource.getMetadataService(),
                  resource.getConverterService());
            List<Variant> responseVariants = mai
                .getResponseVariants(
                    resource.getMetadataService(),
                    resource.getConverterService());
origin: org.restlet.jee/org.restlet.ext.platform

resource.setName(serverResource.getName());
resource.setDescription(serverResource.getDescription());
origin: org.restlet.osgi/org.restlet.ext.platform

private static void completeOperationProduces(Operation operation,
    MethodAnnotationInfo mai, ServerResource sr,
    MetadataService metadataService) {
  if (metadataService != null) {
    try {
      List<Variant> responseVariants = mai.getResponseVariants(
          metadataService, sr.getConverterService());
      if (responseVariants == null || responseVariants.isEmpty()) {
        if (mai.getJavaMethod().getReturnType() != Void.TYPE) {
          LOGGER.warning("Method has no response variant: "
              + mai.getJavaMethod());
        }
        return;
      }
      // une representation per variant ?
      for (Variant variant : responseVariants) {
        if (variant.getMediaType() == null) {
          LOGGER.warning("Variant has no media type: " + variant);
          continue;
        }
        operation.getProduces().add(
            variant.getMediaType().getName());
      }
    } catch (IOException e) {
      throw new ResourceException(e);
    }
  }
}
origin: org.restlet.osgi/org.restlet

/**
 * Returns the annotation descriptors.
 * 
 * @return The annotation descriptors.
 */
private List<AnnotationInfo> getAnnotations() {
  return isAnnotated() ? AnnotationUtils.getInstance().getAnnotations(
      getClass()) : null;
}
origin: org.restlet.osgi/org.restlet

/**
 * Apply a patch entity to the current representation of the resource
 * retrieved by calling {@link #get()}. By default, the
 * {@link ConverterService#applyPatch(Representation, Representation)} method is used and then the
 * {@link #put(Representation)} method called.
 * 
 * @param entity
 *            The patch entity to apply.
 * @return The optional result entity.
 * @throws ResourceException
 * @see <a href="https://tools.ietf.org/html/rfc5789">HTTP PATCH method</a>
 */
protected Representation patch(Representation entity)
    throws ResourceException {
  AnnotationInfo annotationInfo;
  try {
    annotationInfo = getAnnotation(Method.PATCH);
    if (annotationInfo != null) {
      return doHandle(Method.PATCH, getQuery(), entity);
    } else {
      // Default implementation
      return put(getConverterService().applyPatch(get(), entity));
      // doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
    }
  } catch (IOException e) {
    throw new ResourceException(e);
  }
}
origin: org.restlet.jse/org.restlet.ext.platform

/**
 * Automatically describes a method by discovering the resource's
 * annotations.
 * 
 */
private static void completeOperation(CollectInfo collectInfo,
    Operation operation, MethodAnnotationInfo mai, ServerResource sr,
    List<? extends IntrospectionHelper> introspectionHelper) {
  // Loop over the annotated Java methods
  MetadataService metadataService = sr.getMetadataService();
  // Retrieve thrown classes
  completeOperationThrows(collectInfo, operation, mai,
      introspectionHelper);
  // Describe the input
  completeOperationInput(collectInfo, operation, mai, sr,
      introspectionHelper, metadataService);
  // Describe query parameters, if any.
  completeOperationQueryParameter(operation, mai);
  // Describe the success response
  completeOperationOutput(collectInfo, operation, mai,
      introspectionHelper);
  // Produces
  completeOperationProduces(operation, mai, sr, metadataService);
}
origin: org.restlet.osgi/org.restlet

  result = doHandle(((VariantInfo) variant).getAnnotationInfo(),
      variant);
} else {
  result = put(getConverterService().applyPatch(get(), entity),
      variant);
origin: org.restlet.osgi/org.restlet

/**
 * Returns the preferred variant among a list of available variants. The
 * selection is based on the client preferences using the
 * {@link org.restlet.service.ConnegService#getPreferredVariant(List, Request, org.restlet.service.MetadataService)}
 * method.
 * 
 * @param variants
 *            The available variants.
 * @return The preferred variant.
 */
protected Variant getPreferredVariant(List<Variant> variants) {
  Variant result = null;
  // If variants were found, select the best matching one
  if ((variants != null) && (!variants.isEmpty())) {
    result = getConnegService().getPreferredVariant(variants,
        getRequest(), getMetadataService());
  }
  return result;
}
origin: org.restlet.osgi/org.restlet

if (getAnnotation(method) != null) {
  MethodAnnotationInfo annotationInfo = getAnnotation(method,
      query, entity);
    result = doHandle(annotationInfo, null);
  } else {
    doError(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
  doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
origin: org.restlet.osgi/org.restlet

/**
 * Returns a full representation for a given variant. A variant parameter is
 * passed to indicate which representation should be returned if any.<br>
 * <br>
 * This method is only invoked if content negotiation has been enabled as
 * indicated by the {@link #isNegotiated()}, otherwise the {@link #get()} method is invoked.<br>
 * <br>
 * The default behavior is to set the response status to
 * {@link org.restlet.data.Status#CLIENT_ERROR_METHOD_NOT_ALLOWED}.<br>
 * 
 * @param variant
 *            The variant whose full representation must be returned.
 * @return The resource's representation.
 * @see #get(Variant)
 * @throws ResourceException
 */
protected Representation get(Variant variant) throws ResourceException {
  Representation result = null;
  if (variant instanceof VariantInfo) {
    result = doHandle(((VariantInfo) variant).getAnnotationInfo(),
        variant);
  } else {
    doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
  }
  return result;
}
origin: org.restlet.osgi/org.restlet

/**
 * Indicates the communication options available for this resource. A
 * variant parameter is passed to indicate which representation should be
 * returned if any.<br>
 * <br>
 * This method is only invoked if content negotiation has been enabled as
 * indicated by the {@link #isNegotiated()}, otherwise the {@link #options()} method is invoked.<br>
 * <br>
 * The default behavior is to set the response status to
 * {@link org.restlet.data.Status#CLIENT_ERROR_METHOD_NOT_ALLOWED}.<br>
 * 
 * @param variant
 *            The variant of the response entity.
 * @return The optional response entity.
 * @see #get(Variant)
 */
protected Representation options(Variant variant) throws ResourceException {
  Representation result = null;
  // Updates the list of allowed methods
  updateAllowedMethods();
  if (variant instanceof VariantInfo) {
    result = doHandle(((VariantInfo) variant).getAnnotationInfo(),
        variant);
  } else {
    doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
  }
  return result;
}
org.restlet.resourceServerResource

Javadoc

Base class for server-side resources. It acts as a wrapper to a given call, including the incoming Request and the outgoing Response.

It's life cycle is managed by a Finder created either explicitly or more likely implicitly when your ServerResource subclass is attached to a Filter or a Router via the Filter#setNext(Class)or Router#attach(String,Class) methods for example. After instantiation using the default constructor, the final #init(Context,Request,Response) method is invoked, setting the context, request and response. You can intercept this by overriding the #doInit() method. Then, if the response status is still a success, the #handle() method is invoked to actually handle the call. Finally, the final #release() method is invoked to do the necessary clean-up, which you can intercept by overriding the #doRelease() method. During this life cycle, if any exception is caught, then the #doCatch(Throwable) method is invoked.

Note that when an annotated method manually sets the response entity, if this entity is available then it will be preserved and the result of the annotated method ignored.

In addition, there are two ways to declare representation variants, one is based on the #getVariants() method and another one on the annotated methods. Both approaches can't however be used at the same time for now.

Concurrency note: contrary to the org.restlet.Uniform class and its main Restlet subclass where a single instance can handle several calls concurrently, one instance of ServerResource is created for each call handled and accessed by only one thread at a time.

Most used methods

  • isAnnotated
    Indicates if annotations are supported. The default value is true.
  • doInit
  • getConverterService
  • getMetadataService
  • getDescription
    Returns the description.
  • getName
    Returns the display name.
  • doError
    By default, it sets the status on the response.
  • getVariants
    Returns a modifiable list of exposed variants for the given method. You can declare variants manuall
  • handle
    Handles any call to this resource. The default implementation check the #isConditional() and #isNego
  • post
    Posts a representation to the resource at the target URI reference. A variant parameter is passed to
  • updateAllowedMethods
    Invoked when the list of allowed methods needs to be updated. The #getAllowedMethods() or the #setAl
  • delete
    Deletes the resource and all its representations. A variant parameter is passed to indicate which re
  • updateAllowedMethods,
  • delete,
  • describeVariants,
  • doCatch,
  • doConditionalHandle,
  • doHandle,
  • doNegotiatedHandle,
  • get,
  • getAllowedMethods,
  • getApplication

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSharedPreferences (Context)
  • addToBackStack (FragmentTransaction)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ

For IntelliJ IDEA,
Android Studio or Eclipse

  • Search for JavaScript code betaCodota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutBlogContact Us
  • Plugin user guideTerms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)