Endpoint resource exceptions are handled as a RestException. A RestException class can be instantiated through utility methods in RestUtils, allowing an endpoint to specify a response status code with an error. Exceptions are automatically rendered by the framework output producer into the correct format before returning back to the client. The RestExceptionMapper instance of the Jersey ExceptionMapper builds a response from the RestException that is returned to the client.

If you add error conditions to your endpoint, you should build a RestException, setting HTTP response codes, error messages, debug information and, optionally, error codes that are returned from your endpoint method.

The framework can also handle other types of exception thrown by endpoint methods. It wraps the exceptions and converts them into RestExceptions. Every REST method should be constructed with an error message, which should be stored as resource strings in a property file residing in your custom module. Once you have constructed an error message, you can create string constants that refer to the error string keys within your endpoint class. Additionally, you can refer to a new constant class if the String constants are shared with multiple endpoints. For example:

protected static final String ERROR_INVALID_DATE_TIME =
    "noProfileRequestToCreateProfile"
// Use the existing resource bundle utility if it is available or create the new
// resource bundle utility if it is not there.
// Example: An excerpt from ProfileServiceUtils class

public final static String RESOURCE_BUNDLE_NAME =
  "atg.mybundle.BundleResources";

  /** Resource bundle **/
  public static java.util.ResourceBundle sResourceBundle =
      ResourceUtils.getBundle(RESOURCE_BUNDLE_NAME,
      java.util.Locale.getDefault());

public static String getStringResource(String pResource)
    throws MissingResourceException
  {
    String ret = ResourceUtils.getMsgResource
        (pResource,
         RESOURCE_BUNDLE_NAME,
         sResourceBundle);
  }

public static String getMessage(String pString, Object[] pArgs) {
    return MessageFormat.format(pString, pArgs);
}

To define a custom response code with a particular exception type, add a response code with an exception-type HTTP response code in the RestExceptionRegistry class.


Copyright © 1997, 2017 Oracle and/or its affiliates. All rights reserved. Legal Notices