Repository: incubator-juneau Updated Branches: refs/heads/master db0cf72ba -> 07843d641
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletContext.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletContext.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletContext.java deleted file mode 100644 index f01c339..0000000 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletContext.java +++ /dev/null @@ -1,306 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest; - -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.internal.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.serializer.*; - -/** - * Configurable properties on the {@link RestServlet} class. - * <p> - * Properties can be set on the {@link RestServlet} class using the {@link RestResource#properties} or {@link RestMethod#properties} annotations. - * <p> - * These properties can also be passed in as servlet init parameters or system properties. - * <p> - * Some of these properties are only applicable on the servlet class, and others can be specified on the servlet class or method.<br> - * These distinctions are noted below. - * <p> - * See {@link PropertyStore} for more information about context properties. - */ -public final class RestServletContext extends Context { - - /** - * <b>Configuration property:</b> Enable header URL parameters. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RestServlet.allowHeaderParams"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * <p> - * When enabled, headers such as <js>"Accept"</js> and <js>"Content-Type"</js> to be passed in as URL query parameters. - * For example: <js>"?Accept=text/json&Content-Type=text/json"</js> - * <p> - * Parameter names are case-insensitive. - * <p> - * Useful for debugging REST interface using only a browser. - * <p> - * Applicable to servlet class only. - */ - public static final String REST_allowHeaderParams = "RestServlet.allowHeaderParams"; - - /** - * <b>Configuration property:</b> Enable <js>"method"</js> URL parameter for specific HTTP methods. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RestServlet.allowMethodParam"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>""</js> - * </ul> - * <p> - * When specified, the HTTP method can be overridden by passing in a <js>"method"</js> URL parameter on a regular GET request. - * For example: <js>"?method=OPTIONS"</js> - * <p> - * Format is a comma-delimited list of HTTP method names that can be passed in as a method parameter. - * Parameter name is case-insensitive. - * Use "*" to represent all methods. - * For backwards compatibility, "true" also means "*". - * <p> - * Note that per the <a class="doclink" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">HTTP specification</a>, special care should - * be taken when allowing non-safe (POST, PUT, DELETE) methods to be invoked through GET requests. - * <p> - * Applicable to servlet class only. - * <p> - * Example: <js>"HEAD,OPTIONS"</js> - */ - public static final String REST_allowMethodParam = "RestServlet.allowMethodParam"; - - /** - * <b>Configuration property:</b> Enable <js>"body"</js> URL parameter. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RestServlet.allowBodyParam"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * <p> - * When enabled, the HTTP body content on PUT and POST requests can be passed in as text using the <js>"body"</js> URL parameter. - * For example: <js>"?body={name:'John%20Smith',age:45}"</js> - * <p> - * Parameter name is case-insensitive. - * <p> - * Useful for debugging PUT and POST methods using only a browser. - * <p> - * Applicable to servlet class only. - */ - public static final String REST_allowBodyParam = "RestServlet.allowBodyParam"; - - /** - * <b>Configuration property:</b> Render stack traces. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RestServlet.renderResponseStackTraces"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> - * </ul> - * <p> - * Render stack traces in HTTP response bodies when errors occur. - * <p> - * When enabled, Java stack traces will be rendered in the output response. - * Useful for debugging, although allowing stack traces to be rendered may cause security concerns. - * <p> - * Applicable to servlet class only. - */ - public static final String REST_renderResponseStackTraces = "RestServlet.renderResponseStackTraces"; - - /** - * <b>Configuration property:</b> Use stack trace hashes. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RestServlet.useStackTraceHashes"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>true</jk> - * </ul> - * <p> - * When enabled, the number of times an exception has occurred will be determined based on stack trace hashsums, - * made available through the {@link RestException#getOccurrence()} method. - * <p> - * Applicable to servlet class only. - */ - public static final String REST_useStackTraceHashes = "RestServlet.useStackTraceHashes"; - - /** - * <b>Configuration property:</b> Default character encoding. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RestServlet.defaultCharset"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"utf-8"</js> - * </ul> - * <p> - * The default character encoding for the request and response if not specified on the request. - * <p> - * Applicable to servlet class and methods. - */ - public static final String REST_defaultCharset = "RestServlet.defaultCharset"; - - /** - * <b>Configuration property:</b> Expected format of request parameters. - * <p> - * <ul> - * <li><b>Name:</b> <js>"RestServlet.paramFormat"</js> - * <li><b>Data type:</b> <code>String</code> - * <li><b>Default:</b> <js>"UON"</js> - * </ul> - * <p> - * Possible values: - * <ul class='spaced-list'> - * <li><js>"UON"</js> - URL-Encoded Object Notation.<br> - * This notation allows for request parameters to contain arbitrarily complex POJOs. - * <li><js>"PLAIN"</js> - Plain text.<br> - * This treats request parameters as plain text.<br> - * Only POJOs directly convertable from <l>Strings</l> can be represented in parameters when using this mode. - * </ul> - * <p> - * Note that the parameter value <js>"(foo)"</js> is interpreted as <js>"(foo)"</js> when using plain mode, but - * <js>"foo"</js> when using UON mode. - * <p> - * The format can also be specified per-parameter using the {@link FormData#format() @FormData.format()} and {@link Query#format() @Query.format()} - * annotations. - * <p> - * Applicable to servlet class and methods. - */ - public static final String REST_paramFormat = "RestServlet.paramFormat"; - - //-------------------------------------------------------------------------------- - // Automatically added properties. - //-------------------------------------------------------------------------------- - - /** - * The request servlet path. - * <p> - * Automatically added to properties return by {@link RestServlet#createRequestProperties(org.apache.juneau.ObjectMap, RestRequest)} - * and are therefore available through {@link SerializerSession#getProperties()} and {@link ParserSession#getProperties()}. - * <p> - * Equivalent to the value returned by {@link RestRequest#getServletPath()} - */ - public static final String REST_servletPath = "RestServlet.servletPath"; - - /** - * The request servlet URI. - * <p> - * Equivalent to the value returned by {@link RestRequest#getServletURI()} - */ - public static final String REST_servletURI = "RestServlet.servletURI"; - - /** - * The request servlet URI. - * <p> - * Equivalent to the value returned by {@link RestRequest#getRelativeServletURI()} - */ - public static final String REST_relativeServletURI = "RestServlet.relativeServletURI"; - - /** - * The request URI path info. - * <p> - * Automatically added to properties return by {@link RestServlet#createRequestProperties(org.apache.juneau.ObjectMap, RestRequest)} - * and are therefore available through {@link SerializerSession#getProperties()} and {@link ParserSession#getProperties()}. - * <p> - * Equivalent to the value returned by {@link RestRequest#getPathInfo()} - */ - public static final String REST_pathInfo = "RestServlet.pathInfo"; - - /** - * The request URI. - * <p> - * Automatically added to properties return by {@link RestServlet#createRequestProperties(org.apache.juneau.ObjectMap, RestRequest)} - * and are therefore available through {@link SerializerSession#getProperties()} and {@link ParserSession#getProperties()}. - * <p> - * Equivalent to the value returned by {@link RestRequest#getRequestURI()} - */ - public static final String REST_requestURI = "RestServlet.requestURI"; - - /** - * The request method. - * <p> - * Automatically added to properties return by {@link RestServlet#createRequestProperties(org.apache.juneau.ObjectMap, RestRequest)} - * and are therefore available through {@link SerializerSession#getProperties()} and {@link ParserSession#getProperties()}. - * <p> - * Equivalent to the value returned by {@link RestRequest#getMethod()} - */ - public static final String REST_method = "RestServlet.method"; - - /** - * The localized servlet title. - * <p> - * Automatically added to properties return by {@link RestServlet#createRequestProperties(org.apache.juneau.ObjectMap, RestRequest)} - * and are therefore available through {@link SerializerSession#getProperties()} and {@link ParserSession#getProperties()}. - * <p> - * Equivalent to the value returned by {@link RestRequest#getServletTitle()} - */ - public static final String REST_servletTitle = "RestServlet.servletTitle"; - - /** - * The localized servlet description. - * <p> - * Automatically added to properties return by {@link RestServlet#createRequestProperties(org.apache.juneau.ObjectMap, RestRequest)} - * and are therefore available through {@link SerializerSession#getProperties()} and {@link ParserSession#getProperties()}. - * <p> - * Equivalent to the value returned by {@link RestRequest#getServletDescription()} - */ - public static final String REST_servletDescription = "RestServlet.servletDescription"; - - /** - * The localized method summary. - * <p> - * Automatically added to properties return by {@link RestServlet#createRequestProperties(org.apache.juneau.ObjectMap, RestRequest)} - * and are therefore available through {@link SerializerSession#getProperties()} and {@link ParserSession#getProperties()}. - * <p> - * Equivalent to the value returned by {@link RestRequest#getMethodSummary()} - */ - public static final String REST_methodSummary = "RestServlet.methodSummary"; - - /** - * The localized method description. - * <p> - * Automatically added to properties return by {@link RestServlet#createRequestProperties(org.apache.juneau.ObjectMap, RestRequest)} - * and are therefore available through {@link SerializerSession#getProperties()} and {@link ParserSession#getProperties()}. - * <p> - * Equivalent to the value returned by {@link RestRequest#getMethodDescription()} - */ - public static final String REST_methodDescription = "RestServlet.methodDescription"; - - final boolean allowHeaderParams, allowBodyParam, renderResponseStackTraces, useStackTraceHashes; - final String defaultCharset, paramFormat; - final Set<String> allowMethodParams; - - /** - * Constructor. - * <p> - * Typically only called from {@link PropertyStore#getContext(Class)}. - * - * @param ps The property store that created this context. - */ - public RestServletContext(PropertyStore ps) { - super(ps); - allowHeaderParams = ps.getProperty(REST_allowHeaderParams, boolean.class, true); - allowBodyParam = ps.getProperty(REST_allowBodyParam, boolean.class, true); - renderResponseStackTraces = ps.getProperty(REST_renderResponseStackTraces, boolean.class, false); - useStackTraceHashes = ps.getProperty(REST_useStackTraceHashes, boolean.class, true); - defaultCharset = ps.getProperty(REST_defaultCharset, String.class, "utf-8"); - paramFormat = ps.getProperty(REST_paramFormat, String.class, ""); - - Set<String> s = new LinkedHashSet<String>(); - for (String m : StringUtils.split(ps.getProperty(REST_allowMethodParam, String.class, ""), ',')) - if (m.equals("true")) // For backwards compatibility when this was a boolean field. - s.add("*"); - else - s.add(m.toUpperCase()); - allowMethodParams = Collections.unmodifiableSet(s); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java index 8af7efe..8117108 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletDefault.java @@ -13,7 +13,7 @@ package org.apache.juneau.rest; import static org.apache.juneau.html.HtmlDocSerializerContext.*; -import static org.apache.juneau.rest.RestServletContext.*; +import static org.apache.juneau.rest.RestContext.*; import org.apache.juneau.dto.swagger.*; import org.apache.juneau.html.*; @@ -211,9 +211,4 @@ public abstract class RestServletDefault extends RestServlet { public Swagger getOptions(RestRequest req) { return req.getSwagger(); } - - @Override /* RestServlet */ - public boolean hasOptionsPage() { - return true; - } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletGroupDefault.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletGroupDefault.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletGroupDefault.java index 872d372..0864d54 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletGroupDefault.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestServletGroupDefault.java @@ -35,7 +35,7 @@ public abstract class RestServletGroupDefault extends RestServletDefault { */ @RestMethod(name="GET", path="/", description="Child resources") public ChildResourceDescriptions getChildren(RestRequest req) { - return new ChildResourceDescriptions(this, req); + return new ChildResourceDescriptions(getContext(), req); } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/RestUtils.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/RestUtils.java b/juneau-rest/src/main/java/org/apache/juneau/rest/RestUtils.java index b8f017b..713da69 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/RestUtils.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/RestUtils.java @@ -245,4 +245,13 @@ public final class RestUtils { throw new RuntimeException("Could not find servlet path in request URI. URI=["+requestURI+"], servletPath=["+servletPath+"]", e); } } + + static String[] parseHeader(String s) { + int i = s.indexOf(':'); + if (i == -1) + return null; + String name = s.substring(0, i).trim().toLowerCase(Locale.ENGLISH); + String val = s.substring(i+1).trim(); + return new String[]{name,val}; + } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java index 055b805..9a16812 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/FormData.java @@ -86,7 +86,7 @@ public @interface FormData { * <li><js>"PLAIN"</js> - Plain text.<br> * This treats request parameters as plain text.<br> * Only POJOs directly convertable from <l>Strings</l> can be represented in parameters when using this mode. - * <li><js>"INHERIT"</js> (default) - Inherit from the {@link RestServletContext#REST_paramFormat} property on the servlet method or class. + * <li><js>"INHERIT"</js> (default) - Inherit from the {@link RestContext#REST_paramFormat} property on the servlet method or class. * </ul> * <p> * Note that the parameter value <js>"(foo)"</js> is interpreted as <js>"(foo)"</js> when using plain mode, but http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java index 4bac857..8e411d3 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/Query.java @@ -82,7 +82,7 @@ public @interface Query { * <li><js>"PLAIN"</js> - Plain text.<br> * This treats request parameters as plain text.<br> * Only POJOs directly convertable from <l>Strings</l> can be represented in parameters when using this mode. - * <li><js>"INHERIT"</js> (default) - Inherit from the {@link RestServletContext#REST_paramFormat} property on the servlet method or class. + * <li><js>"INHERIT"</js> (default) - Inherit from the {@link RestContext#REST_paramFormat} property on the servlet method or class. * </ul> * <p> * Note that the parameter value <js>"(foo)"</js> is interpreted as <js>"(foo)"</js> when using plain mode, but http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java index 6b0a991..4856070 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestMethod.java @@ -502,4 +502,9 @@ public @interface RestMethod { * </ul> */ String clientVersion() default ""; + + /** + * TODO + */ + String[] links() default ""; } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java index 13adbc2..b49bdd3 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/annotation/RestResource.java @@ -20,7 +20,8 @@ import java.lang.annotation.*; import javax.servlet.http.*; import org.apache.juneau.*; -import org.apache.juneau.encoders.*; +import org.apache.juneau.encoders.Encoder; +import org.apache.juneau.ini.*; import org.apache.juneau.jena.*; import org.apache.juneau.json.*; import org.apache.juneau.parser.*; @@ -31,8 +32,10 @@ import org.apache.juneau.utils.*; import org.apache.juneau.xml.*; /** - * Optionally used to associate metadata on an instance of {@link RestServlet}. + * Used to denote that a class is a REST resource and to associate metadata on it. * <p> + * Usually used on a subclass of {@link RestServlet}, but can be used to annotate any class that you want to expose as a REST resource. + * * Refer to <a class='doclink' href='../package-summary.html#TOC'>org.apache.juneau.rest</a> doc for information on using this class. */ @Documented @@ -46,9 +49,8 @@ public @interface RestResource { * <p> * This annotation is used to provide localized messages for the following methods: * <ul> - * <li>{@link RestServlet#getMessage(java.util.Locale, String, Object...)} - * <li>{@link RestServlet#getTitle(RestRequest)} - * <li>{@link RestServlet#getDescription(RestRequest)} + * <li>{@link RestRequest#getMessage(String, Object...)} + * <li>{@link RestContext#getMessages()} * </ul> * <p> * Refer to the {@link MessageBundle} class for a description of the message key formats @@ -69,7 +71,9 @@ public @interface RestResource { * <p> * Typically, guards will be used for permissions checking on the user making the request, * but it can also be used for other purposes like pre-call validation of a request. - */ + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addGuards(Class...)}/{@link RestConfig#addGuards(RestGuard...)} methods. + */ Class<? extends RestGuard>[] guards() default {}; /** @@ -82,6 +86,8 @@ public @interface RestResource { * Can be used for performing post-processing on the response object before serialization. * <p> * Default converter implementations are provided in the <a class='doclink' href='../converters/package-summary.html#TOC'>org.apache.juneau.rest.converters</a> package. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addConverters(Class...)}/{@link RestConfig#addConverters(RestConverter...)} methods. */ Class<? extends RestConverter>[] converters() default {}; @@ -90,14 +96,16 @@ public @interface RestResource { * <p> * Shortcut to add bean filters to the bean contexts of the objects returned by the following methods: * <ul> - * <li>{@link RestServlet#getBeanContext()} - * <li>{@link RestServlet#getSerializers()} - * <li>{@link RestServlet#getParsers()} + * <li>{@link RestContext#getBeanContext()} + * <li>{@link RestContext#getSerializers()} + * <li>{@link RestContext#getParsers()} * </ul> * <p> * If the specified class is an instance of {@link BeanFilterBuilder}, then a filter built from that builder is added. * Any other classes are wrapped in a {@link InterfaceBeanFilterBuilder} to indicate that subclasses should * be treated as the specified class type. + * <p> + * The programmatic equivalent to this annotation is the {@link RestConfig#addBeanFilters(Class...)} method. */ Class<?>[] beanFilters() default {}; @@ -106,13 +114,15 @@ public @interface RestResource { * <p> * Shortcut to add POJO swaps to the bean contexts of the objects returned by the following methods: * <ul> - * <li>{@link RestServlet#getBeanContext()} - * <li>{@link RestServlet#getSerializers()} - * <li>{@link RestServlet#getParsers()} + * <li>{@link RestContext#getBeanContext()} + * <li>{@link RestContext#getSerializers()} + * <li>{@link RestContext#getParsers()} * </ul> * <p> * If the specified class is an instance of {@link PojoSwap}, then that swap is added. * Any other classes are wrapped in a {@link SurrogateSwap}. + * <p> + * The programmatic equivalent to this annotation is the {@link RestConfig#addPojoSwaps(Class...)} method. */ Class<?>[] pojoSwaps() default {}; @@ -121,14 +131,14 @@ public @interface RestResource { * <p> * Shortcut for specifying class-level properties on this servlet to the objects returned by the following methods: * <ul> - * <li>{@link RestServlet#getBeanContext()} - * <li>{@link RestServlet#getSerializers()} - * <li>{@link RestServlet#getParsers()} + * <li>{@link RestContext#getBeanContext()} + * <li>{@link RestContext#getSerializers()} + * <li>{@link RestContext#getParsers()} * </ul> * <p> * Any of the following property names can be specified: * <ul> - * <li>{@link RestServletContext} + * <li>{@link RestContext} * <li>{@link BeanContext} * <li>{@link SerializerContext} * <li>{@link ParserContext} @@ -144,6 +154,8 @@ public @interface RestResource { * <p> * In some cases, properties can be overridden at runtime through the {@link RestResponse#setProperty(String, Object)} method * or through a {@link Properties @Properties} annotated method parameter. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#setProperty(String, Object)}/{@link RestConfig#setProperties(java.util.Map)} methods. */ Property[] properties() default {}; @@ -151,6 +163,8 @@ public @interface RestResource { * Specifies a list of {@link Serializer} classes to add to the list of serializers available for this servlet. * <p> * This annotation can only be used on {@link Serializer} classes that have no-arg constructors. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addSerializers(Class...)}/{@link RestConfig#addSerializers(Serializer...)} methods. */ Class<? extends Serializer>[] serializers() default {}; @@ -158,6 +172,8 @@ public @interface RestResource { * Specifies a list of {@link Parser} classes to add to the list of parsers available for this servlet. * <p> * This annotation can only be used on {@link Parser} classes that have no-arg constructors. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addParsers(Class...)}/{@link RestConfig#addParsers(Parser...)} methods. */ Class<? extends Parser>[] parsers() default {}; @@ -167,6 +183,8 @@ public @interface RestResource { * HTTP responses. * <p> * See {@link ResponseHandler} for details. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addResponseHandlers(Class...)}/{@link RestConfig#addResponseHandlers(ResponseHandler...)} methods. */ Class<? extends ResponseHandler>[] responseHandlers() default {}; @@ -185,6 +203,8 @@ public @interface RestResource { * ... * } * </p> + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addEncoders(Class...)}/{@link RestConfig#addEncoders(Encoder...)} methods. */ Class<? extends Encoder>[] encoders() default {}; @@ -208,6 +228,8 @@ public @interface RestResource { * ... * } * </p> + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addDefaultRequestHeader(String, Object)}/{@link RestConfig#addDefaultRequestHeaders(String...)} methods. */ String[] defaultRequestHeaders() default {}; @@ -230,6 +252,8 @@ public @interface RestResource { * ... * } * </p> + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addDefaultResponseHeader(String, Object)}/{@link RestConfig#addDefaultResponseHeaders(String...)} methods. */ String[] defaultResponseHeaders() default {}; @@ -270,6 +294,8 @@ public @interface RestResource { * </p> * </dd> * </dl> + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addChildResource(String, Object)}/{@link RestConfig#addChildResources(Class...)}/{@link RestConfig#addChildResources(Object...)} methods. */ Class<?>[] children() default {}; @@ -281,6 +307,8 @@ public @interface RestResource { * <p> * This annotation is ignored on top-level servlets (i.e. servlets defined in <code>web.xml</code> files). * Therefore, implementers can optionally specify a path value for documentation purposes. + * <p> + * The programmatic equivalent to this annotation is the {@link RestConfig#setPath(String)} method. */ String path() default ""; @@ -288,7 +316,7 @@ public @interface RestResource { * Optional servlet title. * <p> * It is used to populate the Swagger title field and to display on HTML pages. - * This value can be retrieved programmatically through the {@link RestServlet#getTitle(RestRequest)} method. + * This value can be retrieved programmatically through the {@link RestRequest#getServletTitle()} method. * <p> * The default value pulls the label from the <code>label</code> entry in the servlet resource bundle. * (e.g. <js>"title = foo"</js> or <js>"MyServlet.title = foo"</js>). @@ -296,6 +324,8 @@ public @interface RestResource { * This field can contain variables (e.g. "$L{my.localized.variable}"). * <p> * Corresponds to the swagger field <code>/info/title</code>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestInfoProvider#getTitle(RestRequest)} method. */ String title() default ""; @@ -303,7 +333,7 @@ public @interface RestResource { * Optional servlet description. * <p> * It is used to populate the Swagger description field and to display on HTML pages. - * This value can be retrieved programmatically through the {@link RestServlet#getDescription(RestRequest)} method. + * This value can be retrieved programmatically through the {@link RestRequest#getServletDescription()} method. * <p> * The default value pulls the description from the <code>description</code> entry in the servlet resource bundle. * (e.g. <js>"description = foo"</js> or <js>"MyServlet.description = foo"</js>). @@ -311,6 +341,8 @@ public @interface RestResource { * This field can contain variables (e.g. "$L{my.localized.variable}"). * <p> * Corresponds to the swagger field <code>/info/description</code>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestInfoProvider#getDescription(RestRequest)} method. */ String description() default ""; @@ -318,7 +350,6 @@ public @interface RestResource { * Optional servlet terms-of-service for this API. * <p> * It is used to populate the Swagger terms-of-service field. - * This value can be retrieved programmatically through the {@link RestServlet#getTermsOfService(RestRequest)} method. * <p> * The default value pulls the description from the <code>termsOfService</code> entry in the servlet resource bundle. * (e.g. <js>"termsOfService = foo"</js> or <js>"MyServlet.termsOfService = foo"</js>). @@ -326,6 +357,8 @@ public @interface RestResource { * This field can contain variables (e.g. "$L{my.localized.variable}"). * <p> * Corresponds to the swagger field <code>/info/termsOfService</code>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestInfoProvider#getTermsOfService(RestRequest)} method. */ String termsOfService() default ""; @@ -333,7 +366,6 @@ public @interface RestResource { * Optional contact information for the exposed API. * <p> * It is used to populate the Swagger contact field and to display on HTML pages. - * This value can be retrieved programmatically through the {@link RestServlet#getContact(RestRequest)} method. * <p> * A simplified JSON string with the following fields: * <p class='bcode'> @@ -355,6 +387,8 @@ public @interface RestResource { * This field can contain variables (e.g. "$L{my.localized.variable}"). * <p> * Corresponds to the swagger field <code>/info/contact</code>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestInfoProvider#getContact(RestRequest)} method. */ String contact() default ""; @@ -362,7 +396,6 @@ public @interface RestResource { * Optional license information for the exposed API. * <p> * It is used to populate the Swagger license field and to display on HTML pages. - * This value can be retrieved programmatically through the {@link RestServlet#getLicense(RestRequest)} method. * <p> * A simplified JSON string with the following fields: * <p class='bcode'> @@ -383,6 +416,8 @@ public @interface RestResource { * This field can contain variables (e.g. "$L{my.localized.variable}"). * <p> * Corresponds to the swagger field <code>/info/license</code>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestInfoProvider#getLicense(RestRequest)} method. */ String license() default ""; @@ -390,7 +425,6 @@ public @interface RestResource { * Provides the version of the application API (not to be confused with the specification version). * <p> * It is used to populate the Swagger version field and to display on HTML pages. - * This value can be retrieved programmatically through the {@link RestServlet#getVersion(RestRequest)} method. * <p> * The default value pulls the description from the <code>version</code> entry in the servlet resource bundle. * (e.g. <js>"version = 2.0"</js> or <js>"MyServlet.version = 2.0"</js>). @@ -398,6 +432,8 @@ public @interface RestResource { * This field can contain variables (e.g. "$L{my.localized.variable}"). * <p> * Corresponds to the swagger field <code>/info/version</code>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestInfoProvider#getVersion(RestRequest)} method. */ String version() default ""; @@ -405,7 +441,6 @@ public @interface RestResource { * Optional tagging information for the exposed API. * <p> * It is used to populate the Swagger tags field and to display on HTML pages. - * This value can be retrieved programmatically through the {@link RestServlet#getTags(RestRequest)} method. * <p> * A simplified JSON string with the following fields: * <p class='bcode'> @@ -432,6 +467,8 @@ public @interface RestResource { * This field can contain variables (e.g. "$L{my.localized.variable}"). * <p> * Corresponds to the swagger field <code>/tags</code>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestInfoProvider#getTags(RestRequest)} method. */ String tags() default ""; @@ -439,7 +476,6 @@ public @interface RestResource { * Optional external documentation information for the exposed API. * <p> * It is used to populate the Swagger external documentation field and to display on HTML pages. - * This value can be retrieved programmatically through the {@link RestServlet#getExternalDocs(RestRequest)} method. * <p> * A simplified JSON string with the following fields: * <p class='bcode'> @@ -460,6 +496,8 @@ public @interface RestResource { * This field can contain variables (e.g. "$L{my.localized.variable}"). * <p> * Corresponds to the swagger field <code>/tags</code>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestInfoProvider#getExternalDocs(RestRequest)} method. */ String externalDocs() default ""; @@ -469,6 +507,8 @@ public @interface RestResource { * The configuration file . * <p> * This field can contain variables (e.g. "$L{my.localized.variable}"). + * <p> + * The programmatic equivalent to this annotation is the {@link RestConfig#setConfigFile(ConfigFile)} method. */ String config() default ""; @@ -517,6 +557,8 @@ public @interface RestResource { * Multiple stylesheets can be specified as a comma-delimited list. * When multiple stylesheets are specified, their contents will be concatenated and return in the order specified * in the list. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#addStyleSheet(Object...)}/{@link RestConfig#addStyleSheet(Class, String)} methods. */ String stylesheet() default ""; @@ -547,6 +589,8 @@ public @interface RestResource { * <li><code>org.apache.juneau.rest.mydocs</code> package (since <code>RestServletDefault</code> is in <code>org.apache.juneau.rest</code>). * <li><code>[working-dir]/mydocs</code> directory. * </ol> + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#setFavIcon(Object)}/{@link RestConfig#setFavIcon(Class, String)} methods. */ String favicon() default ""; @@ -558,8 +602,6 @@ public @interface RestResource { * Mappings are cumulative from parent to child. Child resources can override mappings made on parent resources. * <p> * If the file cannot be located, the request will return {@link HttpServletResponse#SC_NOT_FOUND}. - * <p> - * The media type on the response is determined by the {@link RestServlet#getMimetypesFileTypeMap()} method. * * <h5 class='section'>Example:</h5> * <p class='bcode'> @@ -581,6 +623,8 @@ public @interface RestResource { * <li><code>org.apache.juneau.rest.docs</code> package (since <code>RestServletDefault</code> is in <code>org.apache.juneau.rest</code>). * <li><code>[working-dir]/docs</code> directory. * </ol> + * <p> + * The programmatic equivalent to this annotation is the {@link RestConfig#addStaticFiles(Class, String)} method. */ String staticFiles() default ""; @@ -591,10 +635,66 @@ public @interface RestResource { * changes. Used in conjunction with {@link RestMethod#clientVersion()} annotation. * <p> * If not specified, uses <js>"X-Client-Version"</js>. + * <p> + * The programmatic equivalent to this annotation is the {@link RestConfig#setClientVersionHeader(String)} method. */ String clientVersionHeader() default ""; /** + * Specifies the resolver class to use for resolving child resources by class name. + * <p> + * The default implementation simply instantiates the class using one of the following constructors: + * <ul> + * <li><code><jk>public</jk> T(RestConfig)</code> + * <li><code><jk>public</jk> T()</code> + * </ul> + * The former constructor can be used to get access to the {@link RestConfig} object to get access to the + * config file and initialization information or make programmatic modifications to the resource before + * full initialization. + * <p> + * Non-<code>RestServlet</code> classes can also add the following two methods to get access to the + * {@link RestConfig} and {@link RestContext} objects: + * <ul> + * <li><jk>public void</jk> init(RestConfig);</code> + * <li><jk>public void</jk> init(RestContext);</code> + * </ul> + * <p> + * Subclasses can be used to provide customized resolution of REST resource class instances. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#setResourceResolver(Class)}/{@link RestConfig#setResourceResolver(RestResourceResolver)} methods. + */ + Class<? extends RestResourceResolver> resourceResolver() default RestResourceResolver.class; + + /** + * Specifies the logger class to use for logging. + * <p> + * The default logger performs basic error logging to the Java logger. + * Subclasses can be used to customize logging behavior on the resource. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#setLogger(Class)}/{@link RestConfig#setLogger(RestLogger)} methods. + */ + Class<? extends RestLogger> logger() default RestLogger.Normal.class; + + /** + * Specifies the REST call handler class. + * <p> + * This class handles the basic lifecycle of an HTTP REST call. + * Subclasses can be used to customize how these HTTP calls are handled. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#setCallHandler(Class)}/{@link RestConfig#setCallHandler(RestCallHandler)} methods. + */ + Class<? extends RestCallHandler> callHandler() default RestCallHandler.class; + + /** + * Specifies the class used to retrieve title/description/swagger information about a resource. + * <p> + * Subclasses can be used to customize the documentation on a resource. + * <p> + * The programmatic equivalent to this annotation are the {@link RestConfig#setInfoProvider(Class)}/{@link RestConfig#setInfoProvider(RestInfoProvider)} methods. + */ + Class<? extends RestInfoProvider> infoProvider() default RestInfoProvider.class; + + /** * TODO */ String[] links() default ""; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaDefault.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaDefault.java b/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaDefault.java index fdfd0bb..be489da 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaDefault.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaDefault.java @@ -13,7 +13,7 @@ package org.apache.juneau.rest.jena; import static org.apache.juneau.html.HtmlDocSerializerContext.*; -import static org.apache.juneau.rest.RestServletContext.*; +import static org.apache.juneau.rest.RestContext.*; import org.apache.juneau.dto.swagger.*; import org.apache.juneau.html.*; @@ -252,9 +252,4 @@ public abstract class RestServletJenaDefault extends RestServlet { public Swagger getOptions(RestRequest req) { return req.getSwagger(); } - - @Override /* RestServlet */ - public boolean hasOptionsPage() { - return true; - } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaGroupDefault.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaGroupDefault.java b/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaGroupDefault.java index 8c6e635..130ab25 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaGroupDefault.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/jena/RestServletJenaGroupDefault.java @@ -36,6 +36,6 @@ public abstract class RestServletJenaGroupDefault extends RestServletJenaDefault */ @RestMethod(name="GET", path="/", description="Child resources") public ChildResourceDescriptions getChildren(RestRequest req) { - return new ChildResourceDescriptions(this, req); + return new ChildResourceDescriptions(getContext(), req); } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ChildResourceDescriptions.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ChildResourceDescriptions.java b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ChildResourceDescriptions.java index 216b34d..23ed8bf 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ChildResourceDescriptions.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/labels/ChildResourceDescriptions.java @@ -29,25 +29,25 @@ public class ChildResourceDescriptions extends LinkedList<ResourceDescription> { /** * Constructor. * - * @param servlet The servlet that this bean describes. + * @param context The servlet context that this bean describes. * @param req The HTTP servlet request. */ - public ChildResourceDescriptions(RestServlet servlet, RestRequest req) { - this(servlet, req, false); + public ChildResourceDescriptions(RestContext context, RestRequest req) { + this(context, req, false); } /** * Constructor. * - * @param servlet The servlet that this bean describes. + * @param context The servlet context that this bean describes. * @param req The HTTP servlet request. * @param sort If <jk>true</jk>, list will be ordered by name alphabetically. * Default is to maintain the order as specified in the annotation. */ - public ChildResourceDescriptions(RestServlet servlet, RestRequest req, boolean sort) { + public ChildResourceDescriptions(RestContext context, RestRequest req, boolean sort) { String uri = req.getTrimmedRequestURI(); - for (Map.Entry<String,RestServlet> e : servlet.getChildResources().entrySet()) - add(new ResourceDescription(uri, e.getKey(), e.getValue().getTitle(req))); + for (Map.Entry<String,RestContext> e : context.getChildResources().entrySet()) + add(new ResourceDescription(uri, e.getKey(), e.getValue().getInfoProvider().getTitle(req))); if (sort) Collections.sort(this); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/package.html b/juneau-rest/src/main/java/org/apache/juneau/rest/package.html index da2ff80..79c7753 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/package.html +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/package.html @@ -1053,7 +1053,7 @@ </p> <ul> <li>Annotations: {@link org.apache.juneau.rest.annotation.RestResource#title()}, {@link org.apache.juneau.rest.annotation.RestResource#description()} - <li>By overriding methods on the servlet class: {@link org.apache.juneau.rest.RestServlet#getTitle(RestRequest)}, {@link org.apache.juneau.rest.RestServlet#getDescription(RestRequest)} + <li>By overriding methods on the servlet class: {@link org.apache.juneau.rest.RestInfoProvider#getTitle(RestRequest)}, {@link org.apache.juneau.rest.RestInfoProvider#getDescription(RestRequest)} <li>By defining properties in the resource bundle. <li>By specifying them in a Swagger JSON file. </ul> @@ -1139,8 +1139,8 @@ <jk>public class</jk> ExampleResource <jk>extends</jk> RestServletDefault { </p> <p> - Another option is to override the {@link org.apache.juneau.rest.RestServlet#getTitle(RestRequest)} - and {@link org.apache.juneau.rest.RestServlet#getDescription(RestRequest)} methods. + Another option is to override the {@link org.apache.juneau.rest.RestInfoProvider#getTitle(RestRequest)} + and {@link org.apache.juneau.rest.RestInfoProvider#getDescription(RestRequest)} methods. </p> <h6 class='topic'>Method Description, Input, and Responses</h6> <p> @@ -1213,13 +1213,13 @@ <td><ck>label</ck></td> <td>Servlet label</td> <td>{@link org.apache.juneau.rest.annotation.RestResource#title() @RestResource.title()}</td> - <td>{@link org.apache.juneau.rest.RestServlet#getTitle(RestRequest)}</td> + <td>{@link org.apache.juneau.rest.RestInfoProvider#getTitle(RestRequest)}</td> </tr> <tr> <td><ck>description</ck></td> <td>Servlet description</td> <td>{@link org.apache.juneau.rest.annotation.RestResource#description() @RestResource.description()}</td> - <td>{@link org.apache.juneau.rest.RestServlet#getDescription(RestRequest)}</td> + <td>{@link org.apache.juneau.rest.RestInfoProvider#getDescription(RestRequest)}</td> </tr> <tr> <td><ck>[javaMethodName].summary</ck></td> @@ -1297,7 +1297,7 @@ <ul class='javahierarchy'> <li class='n'>{@link org.apache.juneau.rest.annotation.RestResource#serializers() @RestResource.serializers()} - Annotation on servlet class. <li class='n'>{@link org.apache.juneau.rest.annotation.RestMethod#serializers() @RestMethod.serializers()} - Annotation on individual servlet methods. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#createSerializers(ObjectMap,Class[],Class[])} - Override method to set the serializers programmatically. + <li class='m'>{@link org.apache.juneau.rest.RestConfig#addSerializers(Class[])} - Override method to set the serializers programmatically. </ul> <p> The following are equivalent ways of defining serializers used by a servlet... @@ -1356,7 +1356,7 @@ <ul class='javahierarchy'> <li class='n'>{@link org.apache.juneau.rest.annotation.RestResource#parsers() @RestResource.parsers()} - Annotation on servlet class. <li class='n'>{@link org.apache.juneau.rest.annotation.RestMethod#parsers() @RestMethod.parsers()} - Annotation on individual servlet methods. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#createParsers(ObjectMap,Class[],Class[])} - Override method to set the parsers programmatically. + <li class='m'>{@link org.apache.juneau.rest.RestConfig#addParsers(Class[])} - Override method to set the parsers programmatically. </ul> <p> The following are equivalent ways of defining parsers used by a servlet... @@ -1464,22 +1464,22 @@ } </p> <p> - In particular, the {@link org.apache.juneau.rest.RestServletContext} class has a variety of properties + In particular, the {@link org.apache.juneau.rest.RestContext} class has a variety of properties for controlling the behavior of the {@link org.apache.juneau.rest.RestServlet} class itself. </p> <p> There are also ways to provide properties programmatically. </p> <ul class='spaced-list'> - <li>By overriding the {@link org.apache.juneau.rest.RestServlet#createProperties()} method. - <li>By overriding the {@link org.apache.juneau.rest.RestServlet#createSerializers(ObjectMap,Class[],Class[])} and - {@link org.apache.juneau.rest.RestServlet#createParsers(ObjectMap,Class[],Class[])} methods and setting properties on the + <li>By overriding the {@link org.apache.juneau.rest.RestConfig#setProperties(Map)} method. + <li>By overriding the {@link org.apache.juneau.rest.RestConfig#addSerializers(Class[])} and + {@link org.apache.juneau.rest.RestConfig#addParsers(Class[])} methods and setting properties on the serializers and parsers directly. </ul> <h6 class='topic'>Additional Information</h6> <ul class='javahierarchy'> - <li class='c'>{@link org.apache.juneau.rest.RestServletContext} + <li class='c'>{@link org.apache.juneau.rest.RestContext} <br>Properties associated with the {@link org.apache.juneau.rest.RestServlet} class. <li class='n'>{@link org.apache.juneau.rest.annotation.RestMethod#serializersInherit @RestMethod.serializersInherit()} <br>Controls how serializers inherit properties from the servlet class. @@ -1531,9 +1531,9 @@ Transforms can also be defined programmatically through the following: </p> <ul class='spaced-list'> - <li>By overriding the {@link org.apache.juneau.rest.RestServlet#createBeanFilters()} and {@link org.apache.juneau.rest.RestServlet#createPojoSwaps()} methods. - <li>By overriding the {@link org.apache.juneau.rest.RestServlet#createSerializers(ObjectMap,Class[],Class[])} and - {@link org.apache.juneau.rest.RestServlet#createParsers(ObjectMap,Class[],Class[])} methods and setting transforms on the + <li>By overriding the {@link org.apache.juneau.rest.RestConfig#addBeanFilters(Class[])} and {@link org.apache.juneau.rest.RestConfig#addPojoSwaps(Class[])} methods. + <li>By overriding the {@link org.apache.juneau.rest.RestConfig#addSerializers(Class[])} and + {@link org.apache.juneau.rest.RestConfig#addParsers(Class[])} methods and setting transforms on the serializers and parsers directly. </ul> @@ -1601,7 +1601,7 @@ When guards are associated at the class-level, it's equivalent to associating guards on all Java methods on the servlet. </p> <p> - Class-level guards can also be created programmatically by overriding the {@link org.apache.juneau.rest.RestServlet#createGuards(ObjectMap)} method. + Class-level guards can also be created programmatically by overriding the {@link org.apache.juneau.rest.RestConfig#addGuards(Class[])} method. </p> <h6 class='topic'>Additional Information</h6> <ul class='javahierarchy'> @@ -1692,7 +1692,7 @@ </ul> </ul> <p> - Class-level converters can be created programmatically by overriding the {@link org.apache.juneau.rest.RestServlet#createConverters(ObjectMap)} method. + Class-level converters can be created programmatically by overriding the {@link org.apache.juneau.rest.RestConfig#addConverters(Class[])} method. </p> <p> Note that from the example above, you can specify more than one converter. @@ -1812,21 +1812,11 @@ Children can also be defined programmatically by overriding any of the following methods: </p> <ul class='javahierarchy'> - <li class='a'>{@link org.apache.juneau.rest.RestServlet} + <li class='a'>{@link org.apache.juneau.rest.RestConfig} <ul> - <li class='m'>{@link org.apache.juneau.rest.RestServlet#getChildClasses() getChildClasses()} - <br>Programmatic equivalent to {@link org.apache.juneau.rest.annotation.RestResource#children() @RestResource.children()} annotation. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#createChildren() createChildren()} - <br>Creates instances of classes returned by {@link org.apache.juneau.rest.RestServlet#getChildClasses() getChildClasses()}. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#createChildrenMap() createChildrenMap()} - <br>Uses {@link org.apache.juneau.rest.RestServlet#createChildren() createChildren()} and - {@link org.apache.juneau.rest.annotation.RestResource#path() @RestResource.path()} to create a map of child URLs to child servlets. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#addChildResource(String,RestServlet) addChildResource(String,RestServlet)} - <br>Can be used to programmatically add a REST servlet. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#resolveChild(Class) resolveChild(Class)} - <br>An interceptor method that can be used to provide custom resolution of a child resource. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#replaceChild(RestServlet) replaceChild(RestServlet)} - <br>Allows a child to be replaced at runtime without affecting the parent. + <li class='m'>{@link org.apache.juneau.rest.RestConfig#addChildResource(String,Object)} + <li class='m'>{@link org.apache.juneau.rest.RestConfig#addChildResources(Class[])} + <li class='m'>{@link org.apache.juneau.rest.RestConfig#addChildResources(Object[])} </ul> </ul> </div> @@ -1965,18 +1955,18 @@ <ul class='javahierarchy'> <li class='a'>{@link org.apache.juneau.rest.RestServlet} <ul> - <li class='m'>{@link org.apache.juneau.rest.RestServlet#getVarResolver()} + <li class='m'>{@link org.apache.juneau.rest.RestContext#getVarResolver()} <br>Returns the <l>VarResolver</l> associated with a servlet. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#createVarResolver()} + <li class='m'>{@link org.apache.juneau.rest.RestConfig#addVars(Class[])} <br>The method used to create the servlet <l>VarResolver</l>. <br>Subclasses can override this method to provide their own resolver. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#getSessionObjects(RestRequest)} + <li class='m'>{@link org.apache.juneau.rest.RestCallHandler#getSessionObjects(RestRequest)} <br>Defines the session objects for the var resolver. <br>Subclasses can override this method to provide additional session objects. </ul> </ul> <p> - The default {@link org.apache.juneau.rest.RestServlet#createVarResolver()} method provides + The default {@link org.apache.juneau.rest.RestContext#getVarResolver()} method provides support the following string variable types: </p> <table class='styled'> @@ -1998,7 +1988,7 @@ </tr> <tr> <td><ck>$C{key}</ck><br><ck>$C{key,default}</ck></td> - <td>Values from the config file returned by {@link org.apache.juneau.rest.RestServlet#getConfig()}.</td> + <td>Values from the config file returned by {@link org.apache.juneau.rest.RestContext#getConfigFile()}.</td> </tr> </table> <p> @@ -2041,7 +2031,7 @@ } </p> <p> - The default {@link org.apache.juneau.rest.RestServlet#createVarResolver()} method provides + The default {@link org.apache.juneau.rest.RestRequest#getVarResolverSession()} method provides support for all the servlet-level variables, and augments it with the following request-specific variable types: </p> @@ -2235,7 +2225,7 @@ <h6 class='topic'>Notes:</h6> <ul class='spaced-list'> <li>Mappings are cumulative from parent to child. Child resources can override mappings made on parent resources. - <li>The media type on the response is determined by the {@link org.apache.juneau.rest.RestServlet#getMimetypesFileTypeMap()} method. + <li>The media type on the response is determined by the {@link org.apache.juneau.rest.RestContext#getMediaTypeForName(String)} method. </ul> </div> @@ -2244,19 +2234,19 @@ <h3 class='topic' onclick='toggle(this)'>4.16 - Listener Methods</h3> <div class='topic'> <p> - Various convenience listener methods are provided on the {@link org.apache.juneau.rest.RestServlet} class + Various convenience listener methods are provided on the {@link org.apache.juneau.rest.RestCallHandler} class that subclasses can use to intercept requests: </p> <ul class='javahierarchy'> - <li class='a'>{@link org.apache.juneau.rest.RestServlet} + <li class='a'>{@link org.apache.juneau.rest.RestCallHandler} <ul> - <li class='m'>{@link org.apache.juneau.rest.RestServlet#onPreCall(RestRequest) onPreCall(RestRequest)} + <li class='m'>{@link org.apache.juneau.rest.RestCallHandler#onPreCall(RestRequest) onPreCall(RestRequest)} <br>Callback method that gets invoked right before the REST Java method is invoked. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#onPostCall(RestRequest,RestResponse) onPostCall(RestRequest,RestResponse)} + <li class='m'>{@link org.apache.juneau.rest.RestCallHandler#onPostCall(RestRequest,RestResponse) onPostCall(RestRequest,RestResponse)} <br>Callback method that gets invoked right after the REST Java method is invoked, but before the serializer is invoked. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#onSuccess(RestRequest,RestResponse,long) onSuccess(RestRequest,RestResponse,long)} + <li class='m'>{@link org.apache.juneau.rest.RestCallHandler#onSuccess(RestRequest,RestResponse,long) onSuccess(RestRequest,RestResponse,long)} <br>Callback method for listening for successful completion of requests. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#onError(HttpServletRequest,HttpServletResponse,RestException) onError(HttpServletRequest,HttpServletResponse,RestException)} + <li class='m'>{@link org.apache.juneau.rest.RestLogger#onError(HttpServletRequest,HttpServletResponse,RestException) onError(HttpServletRequest,HttpServletResponse,RestException)} <br>Callback method for logging errors during HTTP requests. </ul> </ul> @@ -2349,10 +2339,10 @@ Default headers can also be specified programmatically by overriding the following methods: </p> <ul class='javahierarchy'> - <li class='a'>{@link org.apache.juneau.rest.RestServlet} + <li class='a'>{@link org.apache.juneau.rest.RestConfig} <ul> - <li class='m'>{@link org.apache.juneau.rest.RestServlet#createDefaultRequestHeaders(ObjectMap) createDefaultRequestHeaders()} - <li class='m'>{@link org.apache.juneau.rest.RestServlet#createDefaultResponseHeaders(ObjectMap) createDefaultResponseHeaders()} + <li class='m'>{@link org.apache.juneau.rest.RestConfig#addDefaultRequestHeaders(String[])} + <li class='m'>{@link org.apache.juneau.rest.RestConfig#addDefaultResponseHeaders(String[])} </ul> </ul> </div> @@ -2365,14 +2355,11 @@ The following overridable methods are provided for handling errors on requests: </p> <ul class='javahierarchy'> - <li class='a'>{@link org.apache.juneau.rest.RestServlet} + <li class='a'>{@link org.apache.juneau.rest.RestCallHandler} <ul> - <li class='m'>{@link org.apache.juneau.rest.RestServlet#onError(HttpServletRequest,HttpServletResponse,RestException) onError(HttpServletRequest,HttpServletResponse,RestException)} - <br>Gets called when an error occurs on a request call. - <br>Default implementation logs the error. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#renderError(HttpServletRequest,HttpServletResponse,RestException) renderError(HttpServletRequest,HttpServletResponse,RestException)} + <li class='m'>{@link org.apache.juneau.rest.RestCallHandler#renderError(HttpServletRequest,HttpServletResponse,RestException) renderError(HttpServletRequest,HttpServletResponse,RestException)} <br>Method that produces the error message on the HTTP response. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#handleNotFound(int,RestRequest,RestResponse) handleNotFound(int,RestRequest,RestResponse)} + <li class='m'>{@link org.apache.juneau.rest.RestCallHandler#handleNotFound(int,RestRequest,RestResponse) handleNotFound(int,RestRequest,RestResponse)} <br>Method that gets called when no method/path pattern match the incoming request. </ul> @@ -2381,12 +2368,15 @@ The following convenience methods are provided for logging: </p> <ul class='javahierarchy'> - <li class='a'>{@link org.apache.juneau.rest.RestServlet} + <li class='a'>{@link org.apache.juneau.rest.RestLogger} <ul> - <li class='m'>{@link org.apache.juneau.rest.RestServlet#getLogger() getLogger()} - <li class='m'>{@link org.apache.juneau.rest.RestServlet#log(Level,String,Object[]) log(Level,String,Object[])} - <li class='m'>{@link org.apache.juneau.rest.RestServlet#log(Level,Throwable,String,Object[]) log(Level,Throwable,String,Object[])} - <li class='m'>{@link org.apache.juneau.rest.RestServlet#logObjects(Level,String,Object[]) logObject(Level,String,Object[])} + <li class='m'>{@link org.apache.juneau.rest.RestLogger#getLogger() getLogger()} + <li class='m'>{@link org.apache.juneau.rest.RestLogger#onError(HttpServletRequest,HttpServletResponse,RestException) onError(HttpServletRequest,HttpServletResponse,RestException)} + <br>Gets called when an error occurs on a request call. + <br>Default implementation logs the error. + <li class='m'>{@link org.apache.juneau.rest.RestLogger#log(Level,String,Object[]) log(Level,String,Object[])} + <li class='m'>{@link org.apache.juneau.rest.RestLogger#log(Level,Throwable,String,Object[]) log(Level,Throwable,String,Object[])} + <li class='m'>{@link org.apache.juneau.rest.RestLogger#logObjects(Level,String,Object[]) logObject(Level,String,Object[])} </ul> </ul> <p> @@ -2485,7 +2475,7 @@ It should be noted that the Configuration API is used extensively in the Microservice API in order to externally configure microservices. </p> <p> - Once a config file has been associated with a REST servlet, it can be accessed through the {@link org.apache.juneau.rest.RestServlet#getConfig()} + Once a config file has been associated with a REST servlet, it can be accessed through the {@link org.apache.juneau.rest.RestContext#getConfigFile()} method. </p> <p> @@ -2513,7 +2503,7 @@ <jk>public</jk> MyRestServlet <jk>extends</jk> RestServlet { </p> <p> - It's even possible to reference request-level variables in your config file if you use {@link org.apache.juneau.rest.RestRequest#getConfig()} + It's even possible to reference request-level variables in your config file if you use {@link org.apache.juneau.rest.RestRequest#getConfigFile()} to access the config file: </p> <p class='bcode'> @@ -2588,8 +2578,7 @@ <br>Juneau Configuration API Javadocs. <li class='p'><a href='../microservice/package-summary.html#TOC'><l>org.apache.juneau.microservice</l></a> <br>Juneau Microservice API Javadocs. - <li class='m'>{@link org.apache.juneau.rest.RestServlet#getConfig()} - <li class='m'>{@link org.apache.juneau.rest.RestServlet#getConfigMgr()} + <li class='m'>{@link org.apache.juneau.rest.RestContext#getConfigFile()} </ul> </div> @@ -2813,7 +2802,7 @@ } </p> <p> - To support overloaded methods, the {@link org.apache.juneau.rest.RestServletContext#REST_allowMethodParam} property + To support overloaded methods, the {@link org.apache.juneau.rest.RestContext#REST_allowMethodParam} property must be set on your servlet. </p> <p class='bcode'> @@ -2864,14 +2853,14 @@ <td class='code'>&method=X</td> <td> Overload the HTTP method as a GET parameter (e.g <l>"POST"</l>). - <br>Must be enabled via {@link org.apache.juneau.rest.RestServletContext#REST_allowMethodParam} property. + <br>Must be enabled via {@link org.apache.juneau.rest.RestContext#REST_allowMethodParam} property. </td> </tr> <tr> <td class='code'>&X=headerValue</td> <td> Specify a header value as a GET parameter. - <br>Must be enabled via {@link org.apache.juneau.rest.RestServletContext#REST_allowHeaderParams} property. + <br>Must be enabled via {@link org.apache.juneau.rest.RestContext#REST_allowHeaderParams} property. </td> </tr> <tr> @@ -2879,7 +2868,7 @@ <td> Pass in the HTTP body content on PUT and POST methods as a UON-encoded GET parameter. <br> - <br>Must be enabled via {@link org.apache.juneau.rest.RestServletContext#REST_allowBodyParam} property. + <br>Must be enabled via {@link org.apache.juneau.rest.RestContext#REST_allowBodyParam} property. </td> </tr> </table> @@ -3041,10 +3030,10 @@ </p> <ul class='spaced-list'> <li>Specifying additional handlers through the {@link org.apache.juneau.rest.annotation.RestResource#responseHandlers() @RestResource.responseHandlers()} annotation. - <li>Overriding and extending the {@link org.apache.juneau.rest.RestServlet#createResponseHandlers(ObjectMap)} method. + <li>Overriding and extending the {@link org.apache.juneau.rest.RestConfig#addResponseHandlers(Class[])} method. </ul> <p> - The {@link org.apache.juneau.rest.RestServlet#handleResponse(RestRequest,RestResponse,Object)} method can also be + The {@link org.apache.juneau.rest.RestCallHandler#handleResponse(RestRequest,RestResponse,Object)} method can also be overridden to bypass the response handler API and process the POJO yourself. </p> </div> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java b/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java index 6ba3997..15a96ad 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/RemoteableServlet.java @@ -68,7 +68,7 @@ public abstract class RemoteableServlet extends RestServletDefault { List<Link> l = new LinkedList<Link>(); boolean useAll = ! useOnlyAnnotated(); for (Class<?> c : getServiceMap().keySet()) { - if (useAll || getBeanContext().getClassMeta(c).isRemoteable()) + if (useAll || getContext().getBeanContext().getClassMeta(c).isRemoteable()) l.add(new Link(c.getName(), "{0}/{1}", req.getRequestURI(), c.getName())); //$NON-NLS-1$ } return l; @@ -131,7 +131,7 @@ public abstract class RemoteableServlet extends RestServletDefault { private Map<String,java.lang.reflect.Method> getMethods(String javaInterface) throws Exception { Class<?> c = getInterfaceClass(javaInterface); - ClassMeta<?> cm = getBeanContext().getClassMeta(c); + ClassMeta<?> cm = getContext().getBeanContext().getClassMeta(c); return (useOnlyAnnotated() ? cm.getRemoteableMethods() : cm.getPublicMethods()); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java index 52650e1..f7f6df3 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/DefaultHandler.java @@ -30,9 +30,6 @@ import org.apache.juneau.serializer.*; * <p> * The <code>Content-Type</code> header is set to the mime-type defined on the selected * serializer based on the {@link Produces#contentType() @Produces.contentType} annotation. - * <p> - * This handler is registered by default on {@link RestServlet RestServlets} via the - * default implementation of the {@link RestServlet#createResponseHandlers} method. */ public class DefaultHandler implements ResponseHandler { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java index 1eebcfb..78d3948 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/InputStreamHandler.java @@ -23,9 +23,6 @@ import org.apache.juneau.utils.*; * Simply pipes the contents of the {@link InputStream} to {@link RestResponse#getNegotiatedOutputStream()}. * <p> * Sets the <code>Content-Type</code> response header to whatever was set via {@link RestResponse#setContentType(String)}. - * <p> - * This handler is registered by default on {@link RestServlet RestServlets} via the - * default implementation of the {@link RestServlet#createResponseHandlers} method. */ public final class InputStreamHandler implements ResponseHandler { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java index 6f5b6ef..d34f280 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/ReaderHandler.java @@ -21,9 +21,6 @@ import org.apache.juneau.utils.*; * Response handler for {@link Reader} objects. * <p> * Simply pipes the contents of the {@link Reader} to {@link RestResponse#getNegotiatedWriter()}. - * <p> - * This handler is registered by default on {@link RestServlet RestServlets} via the - * default implementation of the {@link RestServlet#createResponseHandlers} method. */ public final class ReaderHandler implements ResponseHandler { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java index b2054ce..499a834 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/RedirectHandler.java @@ -19,9 +19,6 @@ import org.apache.juneau.rest.*; /** * Response handler for {@link Redirect} objects. - * <p> - * This handler is registered by default on {@link RestServlet RestServlets} via the - * default implementation of the {@link RestServlet#createResponseHandlers} method. */ public final class RedirectHandler implements ResponseHandler { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/response/StreamableHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/StreamableHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/StreamableHandler.java index 041665b..8a2f107 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/StreamableHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/StreamableHandler.java @@ -22,9 +22,6 @@ import org.apache.juneau.rest.*; * Response handler for {@link Writable} and {@link ReaderResource} objects. * <p> * Uses the {@link Writable#writeTo(Writer)} method to send the contents to the {@link RestResponse#getNegotiatedWriter()} writer. - * <p> - * This handler is registered by default on {@link RestServlet RestServlets} via the - * default implementation of the {@link RestServlet#createResponseHandlers} method. */ public final class StreamableHandler implements ResponseHandler { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java b/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java index 7d84368..b453d1f 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/response/WritableHandler.java @@ -22,9 +22,6 @@ import org.apache.juneau.rest.*; * Response handler for {@link Writable} and {@link ReaderResource} objects. * <p> * Uses the {@link Writable#writeTo(Writer)} method to send the contents to the {@link RestResponse#getNegotiatedWriter()} writer. - * <p> - * This handler is registered by default on {@link RestServlet RestServlets} via the - * default implementation of the {@link RestServlet#createResponseHandlers} method. */ public final class WritableHandler implements ResponseHandler { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/07843d64/juneau-rest/src/main/java/org/apache/juneau/rest/vars/ServletInitParamVar.java ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/vars/ServletInitParamVar.java b/juneau-rest/src/main/java/org/apache/juneau/rest/vars/ServletInitParamVar.java index 7f534ce..b141695 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/vars/ServletInitParamVar.java +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/vars/ServletInitParamVar.java @@ -44,6 +44,6 @@ public class ServletInitParamVar extends DefaultingVar { @Override /* Parameter */ public String resolve(VarResolverSession session, String key) { - return session.getSessionObject(RestRequest.class, RequestVar.SESSION_req).getServlet().getServletConfig().getInitParameter(key); + return session.getSessionObject(RestRequest.class, RequestVar.SESSION_req).getContext().getServletInitParameter(key); } }
