public final class RestContext extends BeanContext
Modifier and Type | Field and Description |
---|---|
static String |
REST_allowBodyParam
Configuration property: Allow body URL parameter.
|
static String |
REST_allowedMethodParams
Configuration property: Allowed method parameters.
|
static String |
REST_allowHeaderParams
Configuration property: Allow header URL parameters.
|
static String |
REST_callHandler
Configuration property: REST call handler.
|
static String |
REST_children
Configuration property: Children.
|
static String |
REST_classpathResourceFinder
Configuration property: Classpath resource finder.
|
static String |
REST_clientVersionHeader
Configuration property: Client version header.
|
static String |
REST_consumes
Configuration property: Supported content media types.
|
static String |
REST_contextPath
Configuration property: Resource context path.
|
static String |
REST_converters
Configuration property: Class-level response converters.
|
static String |
REST_defaultCharset
Configuration property: Default character encoding.
|
static String |
REST_defaultRequestHeaders
Configuration property: Default request headers.
|
static String |
REST_defaultResponseHeaders
Configuration property: Default response headers.
|
static String |
REST_encoders
Configuration property: Compression encoders.
|
static String |
REST_guards
Configuration property: Class-level guards.
|
static String |
REST_infoProvider
Configuration property: REST info provider.
|
static String |
REST_logger
Configuration property: REST logger.
|
static String |
REST_maxInput
Configuration property: The maximum allowed input size (in bytes) on HTTP requests.
|
static String |
REST_messages
Configuration property: Messages.
|
static String |
REST_mimeTypes
Configuration property: MIME types.
|
static String |
REST_paramResolvers
Configuration property: Java method parameter resolvers.
|
static String |
REST_parsers
Configuration property: Parsers.
|
static String |
REST_partParser
Configuration property: HTTP part parser.
|
static String |
REST_partSerializer
Configuration property: HTTP part serializer.
|
static String |
REST_path
Configuration property: Resource path.
|
static String |
REST_produces
Configuration property: Supported accept media types.
|
static String |
REST_renderResponseStackTraces
Configuration property: Render response stack traces in responses.
|
static String |
REST_resourceResolver
Configuration property: REST resource resolver.
|
static String |
REST_responseHandlers
Configuration property: Response handlers.
|
static String |
REST_serializers
Configuration property: Serializers.
|
static String |
REST_staticFileResponseHeaders
Configuration property: Static file response headers.
|
static String |
REST_staticFiles
Configuration property: Static file mappings.
|
static String |
REST_useClasspathResourceCaching
Configuration property: Use classpath resource caching.
|
static String |
REST_useStackTraceHashes
Configuration property: Use stack trace hashes.
|
static String |
REST_widgets
Configuration property: HTML Widgets.
|
BEAN_beanClassVisibility, BEAN_beanConstructorVisibility, BEAN_beanDictionary, BEAN_beanDictionary_add, BEAN_beanDictionary_remove, BEAN_beanFieldVisibility, BEAN_beanFilters, BEAN_beanFilters_add, BEAN_beanFilters_remove, BEAN_beanMapPutReturnsOldValue, BEAN_beanMethodVisibility, BEAN_beansRequireDefaultConstructor, BEAN_beansRequireSerializable, BEAN_beansRequireSettersForGetters, BEAN_beansRequireSomeProperties, BEAN_beanTypePropertyName, BEAN_debug, BEAN_excludeProperties, BEAN_ignoreInvocationExceptionsOnGetters, BEAN_ignoreInvocationExceptionsOnSetters, BEAN_ignorePropertiesWithoutSetters, BEAN_ignoreUnknownBeanProperties, BEAN_ignoreUnknownNullBeanProperties, BEAN_implClasses, BEAN_includeProperties, BEAN_locale, BEAN_mediaType, BEAN_notBeanClasses, BEAN_notBeanClasses_add, BEAN_notBeanClasses_remove, BEAN_notBeanPackages, BEAN_notBeanPackages_add, BEAN_notBeanPackages_remove, BEAN_pojoSwaps, BEAN_pojoSwaps_add, BEAN_pojoSwaps_remove, BEAN_propertyNamer, BEAN_sortProperties, BEAN_timeZone, BEAN_useInterfaceProxies, BEAN_useJavaBeanIntrospector, DEFAULT, DEFAULT_SORTED
Constructor and Description |
---|
RestContext(RestContextBuilder builder)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
allowMethodParam(String m)
Returns
Method GET parameter value can be used to override
the method name in the HTTP header. |
protected void |
checkForInitException()
Throws a
RestException if an exception occurred in the constructor of this object. |
BeanSessionArgs |
createDefaultSessionArgs()
Unused.
|
BeanSession |
createSession(BeanSessionArgs args)
Unused.
|
protected void |
destroy()
Calls
Servlet.destroy() on any child resources defined on this resource. |
protected RestParam[] |
findParams(Method method,
UrlPathPattern pathPattern,
boolean isPreOrPost)
Finds the
RestParam instances to handle resolving objects on the calls to the specified Java method. |
BeanContext |
getBeanContext()
Returns the
BeanContext object used for parsing path variables and header values. |
protected RestCallHandler |
getCallHandler()
Returns the REST call handler used by this resource.
|
Map<String,RestJavaMethod> |
getCallMethods()
Returns the REST Java methods defined in this resource.
|
protected Map<String,RestCallRouter> |
getCallRouters()
Returns a map of HTTP method names to call routers.
|
RestContext |
getChildResource(String path)
Returns the context of the child resource associated with the specified path.
|
Map<String,RestContext> |
getChildResources()
Returns the child resources associated with this servlet.
|
<T> T |
getClasspathResource(Class<?> baseClass,
Class<T> c,
MediaType mediaType,
String name,
Locale locale)
Same as
getClasspathResource(Class, MediaType, String, Locale) , except overrides the class used
for retrieving the classpath resource. |
InputStream |
getClasspathResource(Class<?> baseClass,
String name,
Locale locale)
Same as
getClasspathResource(String, Locale) , but allows you to override the class used for looking
up the classpath resource. |
<T> T |
getClasspathResource(Class<T> c,
MediaType mediaType,
String name,
Locale locale)
Reads the input stream from
getClasspathResource(String, Locale) and parses it into a POJO using the parser
matched by the specified media type. |
InputStream |
getClasspathResource(String name,
Locale locale)
Same as
Class.getResourceAsStream(String) except if it doesn't find the resource on this class, searches
up the parent hierarchy chain. |
String |
getClasspathResourceAsString(Class<?> baseClass,
String name,
Locale locale)
Same as
getClasspathResourceAsString(String, Locale) , but allows you to override the class used for looking
up the classpath resource. |
String |
getClasspathResourceAsString(String name,
Locale locale)
Reads the input stream from
getClasspathResource(String, Locale) into a String. |
String |
getClientVersionHeader()
Returns the name of the client version header name used by this resource.
|
Config |
getConfig()
Returns the config file associated with this servlet.
|
List<MediaType> |
getConsumes()
Returns the explicit list of supported content types for this resource.
|
String |
getContextPath()
Returns the context path of the resource.
|
RestConverter[] |
getConverters()
Returns the converters associated with this resource at the class level.
|
String |
getDefaultCharset()
Returns the default charset to use on requests and responses when not specified on the request.
|
Map<String,Object> |
getDefaultRequestHeaders()
Returns the default request headers for this resource.
|
Map<String,Object> |
getDefaultResponseHeaders()
Returns the default response headers for this resource.
|
EncoderGroup |
getEncoders()
Returns the encoders associated with this resource.
|
RestGuard[] |
getGuards()
Returns the guards associated with this resource at the class level.
|
RestInfoProvider |
getInfoProvider()
Returns the REST information provider used by this resource.
|
RestLogger |
getLogger()
Returns the logger to use for this resource.
|
long |
getMaxInput()
Returns the maximum request input size in bytes.
|
String |
getMediaTypeForName(String name)
Returns the media type for the specified file name.
|
MessageBundle |
getMessages()
Returns the resource bundle used by this resource.
|
RestContext |
getParentContext()
Returns the parent resource context (if this resource was initialized from a parent).
|
ParserGroup |
getParsers()
Returns the parsers registered with this resource.
|
HttpPartParser |
getPartParser()
Returns the HTTP-part parser associated with this resource.
|
HttpPartSerializer |
getPartSerializer()
Returns the HTTP-part serializer associated with this resource.
|
String |
getPath()
Returns the path for this resource as defined by the
@RestResource.path() annotation or
RestContextBuilder.path(String) method concatenated with those on all parent classes. |
List<MediaType> |
getProduces()
Returns the explicit list of supported accept types for this resource.
|
RestContextProperties |
getProperties()
Returns the class-level properties associated with this servlet.
|
Object |
getResource()
Returns the resource object.
|
protected RestResourceResolver |
getResourceResolver()
Returns the resource resolver associated with this context.
|
protected ResponseHandler[] |
getResponseHandlers()
Returns the response handlers associated with this resource.
|
RestParam[] |
getRestParams(Method method)
Returns the parameters defined on the specified Java method.
|
RestServlet |
getRestServlet()
Returns the resource object as a
RestServlet . |
SerializerGroup |
getSerializers()
Returns the serializers registered with this resource.
|
String |
getServletInitParameter(String name)
Returns the servlet init parameter returned by
ServletConfig.getInitParameter(String) . |
int |
getStackTraceOccurrence(Throwable e)
Returns the number of times this exception was thrown based on a hash of its stacktrace.
|
VarResolver |
getVarResolver()
Returns the variable resolver for this servlet.
|
Map<String,Widget> |
getWidgets()
The widgets used for resolving
|
boolean |
hasChildResources()
Returns
|
boolean |
isAllowBodyParam()
Returns whether it's safe to pass the HTTP body as a
|
boolean |
isAllowHeaderParams()
Returns whether it's safe to pass header values in as GET parameters.
|
boolean |
isRenderResponseStackTraces()
Returns whether it's safe to render stack traces in HTTP responses.
|
boolean |
isStaticFile(String p)
Returns
|
StreamResource |
resolveStaticFile(String pathInfo)
Resolve a static resource file.
|
_class, asMap, builder, create, createBeanSession, createBeanSession, createDefaultBeanSessionArgs, createSession, createSession, dumpCacheStats, getBeanMeta, getBeanRegistry, getBeanTypePropertyName, getClassMeta, getClassMeta, getClassMetaForObject, getExcludeProperties, getImplClassConstructor, getIncludeProperties, hasSameCache, isBean, isNotABean, newInstance, newInstance, newInstanceFromOuter, object, resolveClassMeta, string
equals, getArrayProperty, getArrayProperty, getBooleanProperty, getClassArrayProperty, getClassArrayProperty, getClassArrayProperty, getClassListProperty, getClassListProperty, getClassMapProperty, getClassMapProperty, getClassProperty, getClassSetProperty, getClassSetProperty, getInstanceArrayProperty, getInstanceArrayProperty, getInstanceArrayProperty, getInstanceProperty, getInstanceProperty, getInstanceProperty, getIntegerProperty, getListProperty, getListProperty, getLongProperty, getMapProperty, getProperty, getProperty, getPropertyKeys, getPropertyStore, getSetProperty, getSetProperty, getStringProperty, hashCode, toString
public static final String REST_allowBodyParam
Boolean
When enabled, the HTTP body content on PUT and POST requests can be passed in as text using the
For example:
?body=(name='John%20Smith',age=45)
public static final String REST_allowedMethodParams
String
When specified, the HTTP method can be overridden by passing in a
For example:
?method=OPTIONS
Note that per the HTTP specification, special care should be taken when allowing non-safe (POST, PUT, DELETE) methods to be invoked through GET requests.
public static final String REST_allowHeaderParams
Boolean
When enabled, headers such as
For example:
?Accept=text/json&Content-Type=text/json
public static final String REST_callHandler
RestCallHandler
| Class<? extends RestCallHandler
>
BasicRestCallHandler
This class handles the basic lifecycle of an HTTP REST call.
Subclasses can be used to customize how these HTTP calls are handled.
public T(RestContext)
public T()
public static final String REST_children
List<Class | Object | RestChild
>
Defines children of this resource.
A REST child resource is simply another servlet or object that is initialized as part of the ascendant resource and has a
servlet path directly under the ascendant resource object path.
The main advantage to defining servlets as REST children is that you do not need to define them in the
web.xml
file of the web application.
This can cut down on the number of entries that show up in the web.xml
file if you are defining
large numbers of servlets.
Child resources must specify a value for @RestResource.path()
that identifies the subpath of the child resource
relative to the ascendant path UNLESS you use the RestContextBuilder.child(String, Object)
method to register it.
Child resources can be nested arbitrarily deep using this technique (i.e. children can also have children).
A child resource will be initialized immediately after the ascendant servlet/resource is initialized.
The child resource receives the same servlet config as the ascendant servlet/resource.
This allows configuration information such as servlet initialization parameters to filter to child
resources.
As a rule, methods defined on the HttpServletRequest
object will behave as if the child
servlet were deployed as a top-level resource under the child's servlet path.
For example, the getServletPath()
and getPathInfo()
methods on the
HttpServletRequest
object will behave as if the child resource were deployed using the
child's servlet path.
Therefore, the runtime behavior should be equivalent to deploying the child servlet in the
web.xml
file of the web application.
REST_resourceResolver
which
by default is BasicRestResourceResolver
which requires the class have one of the following
constructors:
public T(RestContextBuilder)
public T()
public static final String REST_classpathResourceFinder
ClasspathResourceFinder
ClasspathResourceFinderBasic
Used to retrieve localized files from the classpath.
Used by the following methods:
RestContext
getClasspathResource(String,Locale)
getClasspathResource(Class,String,Locale)
getClasspathResource(Class,MediaType,String,Locale)
getClasspathResource(Class,Class,MediaType,String,Locale)
getClasspathResourceAsString(String,Locale)
getClasspathResourceAsString(Class,String,Locale)
resolveStaticFile(String)
RestRequest
It also affects the behavior of the REST_staticFiles
property.
ClasspathResourceFinderBasic
which provides basic support for finding localized
resources on the classpath and JVM working directory.
ClasspathResourceFinderRecursive
is another option that also recursively searches for resources
up the class-hierarchy.
public T(RestContext)
public T()
public static final String REST_clientVersionHeader
String
Specifies the name of the header used to denote the client version on HTTP requests.
The client version is used to support backwards compatibility for breaking REST interface changes.
Used in conjunction with @RestMethod.clientVersion()
annotation.
public static final String REST_contextPath
String
Overrides the context path value for this resource and any child resources.
This setting is useful if you want to use
Affects the following methods:
RestRequest.getContextPath()
- Returns the overridden context path for the resource.
RestRequest.getServletPath()
- Includes the overridden context path for the resource.
public static final String REST_converters
List<RestConverter
| Class<? extends RestConverter
>>
Associates one or more converters
with a resource class.
These converters get called immediately after execution of the REST method in the same order specified in the
annotation.
The object passed into this converter is the object returned from the Java method or passed into
the RestResponse.setOutput(Object)
method.
Can be used for performing post-processing on the response object before serialization.
When multiple converters are specified, they're executed in the order they're specified in the annotation (e.g. first the results will be traversed, then the resulting node will be searched/sorted).
Traversable
- Allows URL additional path info to address individual elements in a POJO tree.
Queryable
- Allows query/view/sort functions to be performed on POJOs.
Introspectable
- Allows Java public methods to be invoked on the returned POJOs.
public T(BeanContext)
public T()
public static final String REST_defaultCharset
String
The default character encoding for the request and response if not specified on the request.
public static final String REST_defaultRequestHeaders
Map<String,String>
Specifies default values for request headers if they're not passed in through the request.
RestRequest.getHeader(String)
when the header is not present on the request.
Accept
header when one is not
specified so that a particular default Serializer
is picked.
public static final String REST_defaultResponseHeaders
Map<String,String>
Specifies default values for response headers if they're not set after the Java REST method is called.
RestResponse.setHeader(String, String)
programmatically in each of
the Java methods.
public static final String REST_encoders
List<Encoder
| Class<? extends Encoder
>>
These can be used to enable various kinds of compression (e.g.
public T(BeanContext)
public T()
public static final String REST_guards
List<RestGuard
| Class<? extends RestGuard
>>
Associates one or more RestGuards
with all REST methods defined in this class.
These guards get called immediately before execution of any REST method in this class.
If multiple guards are specified, ALL guards must pass.
Note that this is different than matchers were only ONE matcher needs to pass.
public T(RestContext)
public T()
public static final String REST_infoProvider
RestInfoProvider
| Class<? extends RestInfoProvider
>
BasicRestInfoProvider
Class used to retrieve title/description/swagger information about a resource.
public T(RestContext)
public T()
public static final String REST_logger
RestLogger
| Class<? extends RestLogger
>
BasicRestLogger
Specifies the logger to use for logging.
Two implementations are provided by default:
BasicRestLogger
- Default logging.
NoOpRestLogger
- Logging disabled.
Loggers are accessible through the following:
public static final String REST_maxInput
String
Useful for alleviating DoS attacks by throwing an exception when too much input is received instead of resulting in out-of-memory errors which could affect system stability.
public static final String REST_messages
List<MessageBundleLocation
>
Identifies the location of the resource bundle for this class.
This annotation is used to provide localized messages for the following methods:
Messages are also available by passing either of the following parameter types into your Java method:
ResourceBundle
- Basic Java resource bundle.
MessageBundle
- Extended resource bundle with several convenience methods.
Messages passed into Java methods already have their locale set to that of the incoming request.
The value can be a relative path like
public static final String REST_mimeTypes
Set<String>
Defines MIME-type file type mappings.
Used for specifying the content type on file resources retrieved through the following methods:
RestContext.resolveStaticFile(String)
RestRequest.getClasspathReaderResource(String,boolean,MediaType)
RestRequest.getClasspathReaderResource(String,boolean)
RestRequest.getClasspathReaderResource(String)
This list appends to the existing list provided by ExtendedMimetypesFileTypeMap
.
public static final String REST_paramResolvers
List<RestParam
| Class<? extends RestParam
>>
By default, the Juneau framework will automatically Java method parameters of various types (e.g.
RestRequest
, Accept
, Reader
).
This setting allows you to provide your own resolvers for your own class types that you want resolved.
For example, if you want to pass in instances of MySpecialObject
to your Java method, define
the following resolver:
public T(BeanContext)
public T()
RestParam
for the list of predefined parameter resolvers.
public static final String REST_parsers
List<Parser
| Class<? extends Parser
>>
Adds class-level parsers to this resource.
Parsers are used to convert the body of HTTP requests into POJOs.
Any of the Juneau framework parsers can be used in this setting.
The parser selected is based on the request Content-Type
header matched against the values returned by the following method
using a best-match algorithm:
BasicRestServlet
which comes
preconfigured with the following parsers:
public static final String REST_partParser
HttpPartParser
| Class<? extends HttpPartParser
>
UonPartParser
Specifies the HttpPartParser
to use for parsing headers, query/form parameters, and URI parts.
The default value is UonPartParser
which allows for both plain-text and URL-Encoded-Object-Notation values.
If your parts contain text that can be confused with UON (e.g. SimplePartParser
which treats everything as plain text.
public static final String REST_partSerializer
HttpPartSerializer
| Class<? extends HttpPartSerializer
>
SimpleUonPartSerializer
Specifies the HttpPartSerializer
to use for serializing headers, query/form parameters, and URI parts.
The default value is SimpleUonPartSerializer
which serializes UON notation for beans and maps, and
plain text for everything else.
Other options include:
SimplePartSerializer
- Always serializes to plain text.
UonPartSerializer
- Always serializers to UON.
public static final String REST_path
String
Identifies the URL subpath relative to the ascendant resource.
This setting is critical for the routing of HTTP requests from ascendant to child resources.
web.xml
files).
@RestResource.children()
annotation.
public static final String REST_renderResponseStackTraces
Boolean
Render stack traces in HTTP response bodies when errors occur.
BasicRestCallHandler.renderError(HttpServletRequest, HttpServletResponse, RestException)
.
public static final String REST_resourceResolver
RestResourceResolver
| Class<? extends RestResourceResolver
>
BasicRestResourceResolver
The resolver used for resolving instances of child resources.
Can be used to provide customized resolution of REST resource class instances (e.g. resources retrieve from Spring).
public T(RestContext)
public T()
public static final String REST_responseHandlers
List<ResponseHandler
| Class<? extends ResponseHandler
>>
Specifies a list of ResponseHandler
classes that know how to convert POJOs returned by REST methods or
set via RestResponse.setOutput(Object)
into appropriate HTTP responses.
By default, the following response handlers are provided out-of-the-box:
StreamableHandler
- Streamable
objects.
WritableHandler
- Writable
objects.
ReaderHandler
- Reader
objects.
InputStreamHandler
- InputStream
objects.
RedirectHandler
- Redirect
objects.
ZipFileListResponseHandler
- ZipFileList
objects.
DefaultHandler
- All other POJOs.
public T(RestContext)
public T()
public static final String REST_serializers
List<Serializer
| Class<? extends Serializer
>>
Adds class-level serializers to this resource.
Serializer are used to convert POJOs to HTTP response bodies.
Any of the Juneau framework serializers can be used in this setting.
The serializer selected is based on the request Accept
header matched against the values returned by the following method
using a best-match algorithm:
BasicRestServlet
which comes
preconfigured with the following serializers:
public static final String REST_staticFileResponseHeaders
Map<String,String>
{'Cache-Control' : 'max-age=86400, public }
Used to customize the headers on responses returned for statically-served files.
REST_staticFiles
for information about statically-served files.
public static final String REST_staticFiles
List<StaticFileMapping>
Used to define paths and locations of statically-served files such as images or HTML documents from the classpath or file system.
An example where this class is used is in the RestResource.staticFiles()
annotation:
In the example above, given a GET request to the following URL...
/myresource/htdocs/foobar.html
foobar.html
file in the following ordered locations:
com.foo.mypackage.docs
package.
[working-dir]/docs
directory.
REST_classpathResourceFinder
for configuring how classpath resources are located and retrieved.
REST_mimeTypes
for configuring the media types based on file extension.
REST_staticFileResponseHeaders
for configuring response headers on statically served files.
REST_useClasspathResourceCaching
for configuring static file caching.
getClasspathResource(String,Locale)
for retrieving static files.
public static final String REST_produces
List<String>
Overrides the media types inferred from the serializers that identify what media types can be produced by the resource.
An example where this might be useful if you have serializers registered that handle media types that you
don't want exposed in the Swagger documentation.
This affects the returned values from the following:
RestContext.getProduces()
RestRequest.getProduces()
RestInfoProvider.getSwagger(RestRequest)
- Affects produces field.
public static final String REST_consumes
List<String>
Overrides the media types inferred from the parsers that identify what media types can be consumed by the resource.
An example where this might be useful if you have parsers registered that handle media types that you
don't want exposed in the Swagger documentation.
This affects the returned values from the following:
RestContext.getConsumes()
RestRequest.getConsumes()
RestInfoProvider.getSwagger(RestRequest)
- Affects consumes field.
public static final String REST_useClasspathResourceCaching
Boolean
When enabled, resources retrieved via getClasspathResource(String, Locale)
(and related
methods) will be cached in memory to speed subsequent lookups.
REST_staticFiles
for information about static files.
public static final String REST_useStackTraceHashes
Boolean
When enabled, the number of times an exception has occurred will be tracked based on stack trace hashsums.
Affects the following methods:
RestContext.getStackTraceOccurrance(Throwable)
RestCallHandler.handleError(HttpServletRequest, HttpServletResponse, RestException)
RestException.getOccurrence()
- Returns the number of times this exception occurred.
public static final String REST_widgets
List<Widget
| Class<? extends Widget
>>
Defines widgets that can be used in conjunction with string variables of the form
Widget.getHtml(RestRequest)
.
Widget.getScript(RestRequest)
.
Widget.getStyle(RestRequest)
.
The following examples shows how to associate a widget with a REST method and then have it rendered in the links and aside section of the page:
public RestContext(RestContextBuilder builder) throws Exception
builder
- The servlet configuration object.Exception
- If any initialization problems were encountered.protected RestResourceResolver getResourceResolver()
The resource resolver is used for instantiating child resource classes.
public VarResolver getVarResolver()
Variable resolvers are used to replace variables in property values. They can be nested arbitrarily deep. They can also return values that themselves contain other variables.
A typical usage pattern involves using variables inside the @HtmlDoc
annotation:
public Config getConfig()
The config file is identified via one of the following:
public StreamResource resolveStaticFile(String pathInfo) throws IOException
The location of static resources are defined via:
pathInfo
- The unencoded path info.IOException
public InputStream getClasspathResource(String name, Locale locale) throws IOException
Class.getResourceAsStream(String)
except if it doesn't find the resource on this class, searches
up the parent hierarchy chain.
If the resource cannot be found in the classpath, then an attempt is made to look in the JVM working directory.
If the locale
is specified, then we look for resources whose name matches that locale.
For example, if looking for the resource
name
- The resource name.locale
- Optional locale.
IOException
public InputStream getClasspathResource(Class<?> baseClass, String name, Locale locale) throws IOException
getClasspathResource(String, Locale)
, but allows you to override the class used for looking
up the classpath resource.
baseClass
- Overrides the default class to use for retrieving the classpath resource.
name
- The resource name.locale
- Optional locale.
IOException
public String getClasspathResourceAsString(String name, Locale locale) throws IOException
getClasspathResource(String, Locale)
into a String.
name
- The resource name.locale
- Optional locale.
IOException
- If resource could not be found.public String getClasspathResourceAsString(Class<?> baseClass, String name, Locale locale) throws IOException
getClasspathResourceAsString(String, Locale)
, but allows you to override the class used for looking
up the classpath resource.
baseClass
- Overrides the default class to use for retrieving the classpath resource.
name
- The resource name.locale
- Optional locale.
IOException
- If resource could not be found.public <T> T getClasspathResource(Class<T> c, MediaType mediaType, String name, Locale locale) throws IOException, javax.servlet.ServletException
getClasspathResource(String, Locale)
and parses it into a POJO using the parser
matched by the specified media type.
Useful if you want to load predefined POJOs from JSON files in your classpath.
c
- The class type of the POJO to create.mediaType
- The media type of the data in the stream (e.g. name
- The resource name (e.g. "htdocs/styles.css").locale
- Optional locale.
IOException
javax.servlet.ServletException
- If the media type was unknown or the input could not be parsed into a POJO.public <T> T getClasspathResource(Class<?> baseClass, Class<T> c, MediaType mediaType, String name, Locale locale) throws IOException, javax.servlet.ServletException
getClasspathResource(Class, MediaType, String, Locale)
, except overrides the class used
for retrieving the classpath resource.
baseClass
- Overrides the default class to use for retrieving the classpath resource.
c
- The class type of the POJO to create.mediaType
- The media type of the data in the stream (e.g. name
- The resource name (e.g. "htdocs/styles.css").locale
- Optional locale.
IOException
javax.servlet.ServletException
- If the media type was unknown or the input could not be parsed into a POJO.public String getPath()
@RestResource.path()
annotation or
RestContextBuilder.path(String)
method concatenated with those on all parent classes.
If path is not specified, returns
Path always starts with
public Map<String,Widget> getWidgets()
Widget.getName()
.public RestLogger getLogger()
public MessageBundle getMessages()
public RestInfoProvider getInfoProvider()
protected RestCallHandler getCallHandler()
protected Map<String,RestCallRouter> getCallRouters()
public Object getResource()
This is the instance of the class annotated with the @RestResource
annotation, usually
an instance of RestServlet
.
public RestServlet getRestServlet()
RestServlet
.RestServlet
, or RestServlet
.protected void checkForInitException() throws RestException
RestException
if an exception occurred in the constructor of this object.RestException
- The initialization exception wrapped in a RestException
.public RestContext getParentContext()
From this object, you can get access to the parent resource class itself using getResource()
or
getRestServlet()
public BeanContext getBeanContext()
BeanContext
object used for parsing path variables and header values.public RestContextProperties getProperties()
Properties at the class level are defined via the following:
Map
is mutable.
init()
method.
RestContextProperties
.public SerializerGroup getSerializers()
public ParserGroup getParsers()
Parsers at the class level are defined via the following:
public String getServletInitParameter(String name)
ServletConfig.getInitParameter(String)
.name
- The init parameter name.public Map<String,RestContext> getChildResources()
@RestResource.path()
annotation defined on the child resource.public int getStackTraceOccurrence(Throwable e)
e
- The exception to check.0
if REST_useStackTraceHashes
setting is not enabled.public boolean isRenderResponseStackTraces()
public boolean isAllowHeaderParams()
public boolean isAllowBodyParam()
public String getDefaultCharset()
public long getMaxInput()
public String getClientVersionHeader()
public boolean allowMethodParam(String m)
Method
GET parameter value can be used to override
the method name in the HTTP header.
m
- The method name, upper-cased.public HttpPartParser getPartParser()
public HttpPartSerializer getPartSerializer()
public EncoderGroup getEncoders()
public List<MediaType> getProduces()
Accept
header values for this resource.
public List<MediaType> getConsumes()
Content-Type
header values for this resource.
public Map<String,Object> getDefaultRequestHeaders()
public Map<String,Object> getDefaultResponseHeaders()
public RestConverter[] getConverters()
public RestGuard[] getGuards()
protected ResponseHandler[] getResponseHandlers()
public boolean hasChildResources()
public RestContext getChildResource(String path)
path
- The path of the child resource to resolve.public String getContextPath()
public RestParam[] getRestParams(Method method)
method
- The Java method to check.public String getMediaTypeForName(String name)
name
- The file name.public boolean isStaticFile(String p)
Static files are files pulled from the classpath and served up directly to the browser.
p
- The URL path remainder after the servlet match.public Map<String,RestJavaMethod> getCallMethods()
These are the methods annotated with the @RestMethod
annotation.
protected RestParam[] findParams(Method method, UrlPathPattern pathPattern, boolean isPreOrPost) throws javax.servlet.ServletException
RestParam
instances to handle resolving objects on the calls to the specified Java method.method
- The Java method being called.pathPattern
- The parsed URL path pattern.isPreOrPost
- Whether this is a HookEvent.PRE_CALL
or HookEvent.POST_CALL
.javax.servlet.ServletException
- If an annotation usage error was detected.protected void destroy()
Servlet.destroy()
on any child resources defined on this resource.public BeanSession createSession(BeanSessionArgs args)
createSession
in class BeanContext
args
- The session arguments.public BeanSessionArgs createDefaultSessionArgs()
createDefaultSessionArgs
in class BeanContext
Copyright © 2018 Apache. All rights reserved.