public class JSONRPC2CallingConvention extends JSONRPCCallingConvention
Manageable.State
Modifier and Type | Field and Description |
---|---|
protected static String |
JSON_REQUEST_CONTENT_TYPE
The jsonrequest content type.
|
protected static String |
JSON_RPC_CONTENT_TYPE
The json-rpc content type.
|
protected static String |
RESPONSE_CONTENT_TYPE
The json content type.
|
BOOTSTRAPPED, BOOTSTRAPPING, DEINITIALIZING, INITIALIZING, UNUSABLE, USABLE
Constructor and Description |
---|
JSONRPC2CallingConvention(API api)
Creates a new
JSONRPCCallingConvention instance. |
Modifier and Type | Method and Description |
---|---|
protected void |
convertResultImpl(FunctionResult xinsResult,
HttpServletResponse httpResponse,
Map<String,Object> backpack)
Converts a XINS result to an HTTP response (implementation method).
|
protected API |
getAPI()
Determines the current API.
|
protected String[] |
getSupportedMethods(HttpServletRequest request)
Determines which HTTP methods are supported for function invocations,
for the specified request.
|
protected boolean |
matches(HttpServletRequest httpRequest)
Checks if the specified request can possibly be handled by this calling
convention as a function invocation.
|
protected FunctionRequest |
parseGetRequest(HttpServletRequest httpRequest)
Parses the JSON-RPC HTTP GET request according to the specs.
|
protected FunctionRequest |
parsePostRequest(HttpServletRequest httpRequest)
Parses the JSON-RPC HTTP POST request according to the specs.
|
protected Element |
parseXMLRequest(HttpServletRequest httpRequest)
Parses XML from the specified HTTP request and checks that the content
type is correct.
|
protected Element |
parseXMLRequest(HttpServletRequest httpRequest,
boolean checkType)
Parses XML from the specified HTTP request and optionally checks that
the content type is correct.
|
convertRequestImpl, getErrorDescription, getSupportedMethods
assertUsable, bootstrap, bootstrapImpl, deinit, deinitImpl, getState, init, initImpl, isBootstrapped, isUsable
protected static final String RESPONSE_CONTENT_TYPE
protected static final String JSON_RPC_CONTENT_TYPE
protected static final String JSON_REQUEST_CONTENT_TYPE
public JSONRPC2CallingConvention(API api) throws IllegalArgumentException
JSONRPCCallingConvention
instance.api
- the API, needed for the JSON-RPC messages, cannot be null
.IllegalArgumentException
- if api == null
.protected boolean matches(HttpServletRequest httpRequest) throws Exception
Implementations of this method should be optimized for performance, as this method may be called for each incoming request. Also, this method should not have any side-effects except possibly some caching in case there is a match.
If this method throws any exception, the exception is logged as an
ignorable exception and false
is assumed.
This method should only be called by the XINS/Java Server Framework.
matches
in class JSONRPCCallingConvention
httpRequest
- the HTTP request to investigate, never null
.true
if this calling convention is possibly
able to handle this request, or false
if it is
definitely not able to handle this request.Exception
- if analysis of the request causes an exception; in this case
false
will be assumed by the framework.protected FunctionRequest parseGetRequest(HttpServletRequest httpRequest) throws InvalidRequestException, FunctionNotSpecifiedException
JSONRPCCallingConvention
parseGetRequest
in class JSONRPCCallingConvention
httpRequest
- the HTTP request.null
.InvalidRequestException
- if the request is considerd to be invalid.FunctionNotSpecifiedException
- if the request does not indicate the name of the function to execute.protected FunctionRequest parsePostRequest(HttpServletRequest httpRequest) throws InvalidRequestException, FunctionNotSpecifiedException
JSONRPCCallingConvention
parsePostRequest
in class JSONRPCCallingConvention
httpRequest
- the HTTP request.null
.InvalidRequestException
- if the request is considerd to be invalid.FunctionNotSpecifiedException
- if the request does not indicate the name of the function to execute.protected void convertResultImpl(FunctionResult xinsResult, HttpServletResponse httpResponse, Map<String,Object> backpack) throws IOException
null
.convertResultImpl
in class JSONRPCCallingConvention
xinsResult
- the XINS result object that should be converted to an HTTP response,
will not be null
.httpResponse
- the HTTP response object to configure.backpack
- the backpack.IOException
- if the invocation of any of the methods in either
httpResponse
or httpRequest
caused an I/O
error.protected final API getAPI()
API
, never null
.protected String[] getSupportedMethods(HttpServletRequest request)
Each String
in the returned array must be one
supported method.
The returned array may be null
. If it is not, then the
returned array must only contain valid HTTP method names, so they may
not contain whitespace, for example. HTTP method names must be in uppercase.
There must be at least one HTTP method supported for function invocations.
Note that OPTIONS must not be returned by this method, as it is not an HTTP method that can ever be used to invoke a XINS function.
The set of supported methods must be a subset of the set returned by
getSupportedMethods()
.
The default implementation of this method returns the set returned by
getSupportedMethods()
.
request
- the request to determine the supported methods for.String
array, can be null
.protected Element parseXMLRequest(HttpServletRequest httpRequest) throws IllegalArgumentException, InvalidRequestException
This method uses a cache to optimize performance if either of the
parseXMLRequest
methods is called multiple times for the
same request.
Calling this method is equivalent with calling
parseXMLRequest(HttpServletRequest,boolean)
with the
checkType
argument set to true
.
httpRequest
- the HTTP request, cannot be null
.null
.IllegalArgumentException
- if httpRequest == null
.InvalidRequestException
- if the HTTP request cannot be read or cannot be parsed correctly.protected Element parseXMLRequest(HttpServletRequest httpRequest, boolean checkType) throws IllegalArgumentException, InvalidRequestException
Since XINS 1.4.0, this method uses a cache to optimize performance if
either of the parseXMLRequest
methods is called multiple
times for the same request.
httpRequest
- the HTTP request, cannot be null
.checkType
- flag indicating whether this method should check that the content
type of the request is text/xml.null
.IllegalArgumentException
- if httpRequest == null
.InvalidRequestException
- if the HTTP request cannot be read or cannot be parsed correctly.See http://www.xins.org/.