Skip to main content

Java Method Parameters

Java methods can contain any of the following parameters in any order:

Parameters based on class types:Request objects:AsyncContext CookieList DispatcherType HttpPartParserSession HttpPartSerializerSession HttpServletRequest InputStream InputStreamParser Locale Messages Parser Principal Reader ReaderParser RequestAttributes RequestContent RequestFormParams RequestHeaders RequestPathParams RequestQueryParams ResourceBundle RestRequest ServletInputStream Swagger TimeZone UriContext UriResolver VarResolverSessionResponse objects:HttpServletResponse OutputStream RestResponse ServletOutputStream WriterSession objects:HttpSession RestSession UrlPath UrlPathMatch BeanStore RestOpSessionParsed request header values:Accept AcceptCharset AcceptEncoding AcceptLanguage AcceptRanges Authorization CacheControl ClientVersion Connection ContentDisposition ContentEncoding ContentLength ContentType Date Debug Expect Forwarded From Host IfMatch IfModifiedSince IfNoneMatch IfRange IfUnmodifiedSince MaxForwards NoTrace Origin Pragma ProxyAuthorization Range Referer TE Thrown Upgrade UserAgent WarningContext values:BeanContext CallLogger Config DebugEnablement EncoderSet FileFinder JsonSchemaGenerator Logger MethodExecStore ParserSet RestChildren RestContext RestContextStats RestOpContext RestOperations SerializerSet StaticFiles ThrownStoreAnnotated parameters:Attr Content Path FormData HasFormData Query HasQuery Header StatusCode Method Request Response

In Spring Boot environments, any available Spring Beans can also be passed in as parameters.

Example
@RestGet("/example1/{a1}/{a2}/{a3}/*")
public String doGetExample1(
RestRequest req,
RestResponse res,
@Method String method,
@Path("a1") String a1,
@Path("a2") int a2,
@Path("a3") UUID a3,
@Query("p1") int p1,
@Query("p2") String p2,
@Query("p3") UUID p3,
@HasQuery("p3") boolean hasP3,
@Path("/*") String remainder,
@Header("Accept-Language") String lang,
@Header("Accept") String accept,
@Header("DNT") int doNotTrack,
RequestAttributes attributes,
ResourceBundle nls
) {
// Do something with all of those
}

Additional parameter types can be defined via the annotation Rest.restOpArgs() or by calling restOpArgs().

Example
@Rest(
restOpArgs={ MyOpArg.class } // Option #1 - Via annotation
)
public class MyResource extends BasicRestObject {

// Option #2 - Programmatically
@RestInit
public void init(RestContext.Builder builder) {
builder.restOpArgs(MyOpArg.class);
}
}