public class BasicRestCallHandler extends Object implements RestCallHandler
RestCallHandler
.
Subclasses can override these methods to tailor how HTTP REST calls are handled.
Subclasses MUST implement a public constructor that takes in a RestContext
object.
RestCallHandler.Null
Constructor and Description |
---|
BasicRestCallHandler(RestContext context)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
RestRequest |
createRequest(javax.servlet.http.HttpServletRequest req)
Creates a
RestRequest object based on the specified incoming HttpServletRequest object. |
RestResponse |
createResponse(RestRequest req,
javax.servlet.http.HttpServletResponse res)
Creates a
RestResponse object based on the specified incoming HttpServletResponse object
and the request returned by createRequest(HttpServletRequest) . |
Map<String,Object> |
getSessionObjects(RestRequest req)
Returns the session objects for the specified request.
|
void |
handleError(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
RestException e)
Deprecated.
|
void |
handleError(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
Throwable e)
Method for handling response errors.
|
void |
handleNotFound(int rc,
RestRequest req,
RestResponse res)
Handle the case where a matching method was not found.
|
void |
handleResponse(RestRequest req,
RestResponse res)
The main method for serializing POJOs passed in through the
RestResponse.setOutput(Object) method or
returned by the Java method. |
void |
handleResponse(RestRequest req,
RestResponse res,
Object output)
Deprecated.
|
void |
renderError(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
RestException e)
Deprecated.
|
void |
service(javax.servlet.http.HttpServletRequest r1,
javax.servlet.http.HttpServletResponse r2)
The main service method.
|
public BasicRestCallHandler(RestContext context)
context
- The resource context.public RestRequest createRequest(javax.servlet.http.HttpServletRequest req) throws javax.servlet.ServletException
RestRequest
object based on the specified incoming HttpServletRequest
object.
Subclasses may choose to override this method to provide a specialized request object.
createRequest
in interface RestCallHandler
req
- The request object from the service(HttpServletRequest, HttpServletResponse)
method.javax.servlet.ServletException
- If any errors occur trying to interpret the request.public RestResponse createResponse(RestRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException
RestResponse
object based on the specified incoming HttpServletResponse
object
and the request returned by createRequest(HttpServletRequest)
.
Subclasses may choose to override this method to provide a specialized response object.
createResponse
in interface RestCallHandler
req
- The request object returned by createRequest(HttpServletRequest)
.res
- The response object from the service(HttpServletRequest, HttpServletResponse)
method.javax.servlet.ServletException
- If any errors occur trying to interpret the request or response.public void service(javax.servlet.http.HttpServletRequest r1, javax.servlet.http.HttpServletResponse r2) throws javax.servlet.ServletException, IOException
Subclasses can optionally override this method if they want to tailor the behavior of requests.
service
in interface RestCallHandler
r1
- The incoming HTTP servlet request object.r2
- The incoming HTTP servlet response object.javax.servlet.ServletException
IOException
public void handleResponse(RestRequest req, RestResponse res) throws IOException, RestException, NotImplemented
RestResponse.setOutput(Object)
method or
returned by the Java method.
Subclasses may override this method if they wish to modify the way the output is rendered or support other output formats.
The default implementation simply iterates through the response handlers on this resource
looking for the first one whose ResponseHandler.handle(RestRequest, RestResponse)
method returns
handleResponse
in interface RestCallHandler
req
- The HTTP request.res
- The HTTP response.IOException
RestException
NotImplemented
public void handleNotFound(int rc, RestRequest req, RestResponse res) throws NotFound, PreconditionFailed, MethodNotAllowed, javax.servlet.ServletException
Subclasses can override this method to provide a 2nd-chance for specifying a response. The default implementation will simply throw an exception with an appropriate message.
handleNotFound
in interface RestCallHandler
rc
- The HTTP response code.req
- The HTTP request.res
- The HTTP response.NotFound
PreconditionFailed
MethodNotAllowed
javax.servlet.ServletException
public void handleError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, Throwable e) throws IOException
Subclasses can override this method to provide their own custom error response handling.
handleError
in interface RestCallHandler
req
- The servlet request.res
- The servlet response.e
- The exception that occurred.IOException
- Can be thrown if a problem occurred trying to write to the output stream.public Map<String,Object> getSessionObjects(RestRequest req)
The default implementation simply returns a single map containing {'req':req}
.
getSessionObjects
in interface RestCallHandler
req
- The REST request.@Deprecated public void handleError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, RestException e) throws IOException
handleError(HttpServletRequest, HttpServletResponse, Throwable)
IOException
@Deprecated public void handleResponse(RestRequest req, RestResponse res, Object output) throws IOException, RestException
handleResponse(RestRequest, RestResponse)
IOException
RestException
@Deprecated public void renderError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, RestException e) throws IOException
handleError(HttpServletRequest, HttpServletResponse, Throwable)
IOException
Copyright © 2018 Apache. All rights reserved.