public class JsonRpcBasicServer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
CODE_OK |
static java.lang.String |
DATA |
static java.lang.String |
ERROR |
static java.lang.String |
ERROR_CODE |
static java.lang.String |
ERROR_MESSAGE |
static java.lang.String |
EXCEPTION_TYPE_NAME |
protected HttpStatusCodeProvider |
httpStatusCodeProvider |
static java.lang.String |
ID |
static java.lang.String |
JSONRPC |
static java.lang.String |
JSONRPC_CONTENT_TYPE |
static java.lang.String |
METHOD |
static java.lang.String |
NAME |
static java.lang.String |
NULL |
static java.lang.String |
PARAMS |
static java.lang.String |
RESULT |
static java.lang.String |
VERSION |
static java.lang.String |
WEB_PARAM_ANNOTATION_CLASS_LOADER |
Constructor and Description |
---|
JsonRpcBasicServer(java.lang.Object handler)
Creates the server with a default
ObjectMapper delegating
all calls to the given handler . |
JsonRpcBasicServer(java.lang.Object handler,
java.lang.Class<?> remoteInterface)
Creates the server with a default
ObjectMapper delegating
all calls to the given handler Object but only
methods available on the remoteInterface . |
JsonRpcBasicServer(com.fasterxml.jackson.databind.ObjectMapper mapper,
java.lang.Object handler)
Creates the server with the given
ObjectMapper delegating
all calls to the given handler . |
JsonRpcBasicServer(com.fasterxml.jackson.databind.ObjectMapper mapper,
java.lang.Object handler,
java.lang.Class<?> remoteInterface)
Creates the server with the given
ObjectMapper delegating
all calls to the given handler Object but only
methods available on the remoteInterface . |
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
getHandler(java.lang.String serviceName)
Get the handler (object) that should be invoked to execute the specified
RPC method.
|
protected java.lang.Class<?>[] |
getHandlerInterfaces(java.lang.String serviceName)
Returns the handler's class or interfaces.
|
protected java.lang.String |
getMethodName(java.lang.String methodName)
Get the method name from the methodNode.
|
RequestInterceptor |
getRequestInterceptor() |
protected java.lang.String |
getServiceName(java.lang.String methodName)
Get the service name from the methodNode.
|
protected ErrorResolver.JsonError |
handleJsonNodeRequest(com.fasterxml.jackson.databind.JsonNode node,
java.io.OutputStream output)
Handles the given
JsonNode and writes the responses to the given OutputStream . |
int |
handleRequest(java.io.InputStream input,
java.io.OutputStream output)
Handles a single request from the given
InputStream ,
that is to say that a single JsonNode is read from
the stream and treated as a JSON-RPC request. |
void |
setAllowExtraParams(boolean allowExtraParams)
Sets whether or not the server should allow superfluous
parameters to method calls.
|
void |
setAllowLessParams(boolean allowLessParams)
Sets whether or not the server should allow less parameters
than required to method calls (passing null for missing params).
|
void |
setBackwardsCompatible(boolean backwardsCompatible)
Sets whether or not the server should be backwards
compatible to JSON-RPC 1.0.
|
void |
setConvertedParameterTransformer(ConvertedParameterTransformer convertedParameterTransformer)
Sets the
ConvertedParameterTransformer instance that can be
used to mutate the deserialized arguments passed to the service method during invocation. |
void |
setErrorResolver(ErrorResolver errorResolver)
Sets the
ErrorResolver used for resolving errors. |
void |
setHttpStatusCodeProvider(HttpStatusCodeProvider httpStatusCodeProvider)
Sets the
HttpStatusCodeProvider instance to use for HTTP error results. |
void |
setInvocationListener(InvocationListener invocationListener)
Sets the
InvocationListener instance that can be
used to provide feedback for capturing method-invocation
statistics. |
void |
setRequestInterceptor(RequestInterceptor requestInterceptor) |
void |
setRethrowExceptions(boolean rethrowExceptions)
Sets whether or not the server should re-throw exceptions.
|
void |
setShouldLogInvocationErrors(boolean shouldLogInvocationErrors)
If true, then when errors arise in the invocation of JSON-RPC services, the error will be
logged together with the underlying stack trace.
|
public static final java.lang.String JSONRPC_CONTENT_TYPE
public static final java.lang.String PARAMS
public static final java.lang.String METHOD
public static final java.lang.String JSONRPC
public static final java.lang.String ID
public static final java.lang.String ERROR
public static final java.lang.String ERROR_MESSAGE
public static final java.lang.String ERROR_CODE
public static final java.lang.String DATA
public static final java.lang.String RESULT
public static final java.lang.String EXCEPTION_TYPE_NAME
public static final java.lang.String VERSION
public static final int CODE_OK
public static final java.lang.String WEB_PARAM_ANNOTATION_CLASS_LOADER
public static final java.lang.String NAME
public static final java.lang.String NULL
protected HttpStatusCodeProvider httpStatusCodeProvider
public JsonRpcBasicServer(com.fasterxml.jackson.databind.ObjectMapper mapper, java.lang.Object handler)
ObjectMapper
delegating
all calls to the given handler
.mapper
- the ObjectMapper
handler
- the handler
public JsonRpcBasicServer(com.fasterxml.jackson.databind.ObjectMapper mapper, java.lang.Object handler, java.lang.Class<?> remoteInterface)
ObjectMapper
delegating
all calls to the given handler
Object
but only
methods available on the remoteInterface
.mapper
- the ObjectMapper
handler
- the handler
remoteInterface
- the interfacepublic JsonRpcBasicServer(java.lang.Object handler, java.lang.Class<?> remoteInterface)
ObjectMapper
delegating
all calls to the given handler
Object
but only
methods available on the remoteInterface
.handler
- the handler
remoteInterface
- the interfacepublic JsonRpcBasicServer(java.lang.Object handler)
ObjectMapper
delegating
all calls to the given handler
.handler
- the handler
public RequestInterceptor getRequestInterceptor()
public void setRequestInterceptor(RequestInterceptor requestInterceptor)
public int handleRequest(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOException
InputStream
,
that is to say that a single JsonNode
is read from
the stream and treated as a JSON-RPC request. All responses
are written to the given OutputStream
.input
- the InputStream
output
- the OutputStream
0
if nonejava.io.IOException
- on errorprotected java.lang.Class<?>[] getHandlerInterfaces(java.lang.String serviceName)
serviceName
- the optional name of a serviceprotected ErrorResolver.JsonError handleJsonNodeRequest(com.fasterxml.jackson.databind.JsonNode node, java.io.OutputStream output) throws java.io.IOException
JsonNode
and writes the responses to the given OutputStream
.node
- the JsonNode
output
- the OutputStream
0
if nonejava.io.IOException
- on errorprotected java.lang.String getServiceName(java.lang.String methodName)
null
. Subclasses may parse the methodNode for service name.methodName
- the JsonNode for the methodnull
protected java.lang.String getMethodName(java.lang.String methodName)
methodName
- the JsonNode for the methodprotected java.lang.Object getHandler(java.lang.String serviceName)
serviceName
- an optional service namepublic void setBackwardsCompatible(boolean backwardsCompatible)
backwardsCompatible
- the backwardsCompatible to setpublic void setRethrowExceptions(boolean rethrowExceptions)
rethrowExceptions
- true or falsepublic void setAllowExtraParams(boolean allowExtraParams)
allowExtraParams
- true or falsepublic void setAllowLessParams(boolean allowLessParams)
allowLessParams
- the allowLessParams to setpublic void setErrorResolver(ErrorResolver errorResolver)
ErrorResolver
used for resolving errors.
Multiple ErrorResolver
s can be used at once by
using the MultipleErrorResolver
.errorResolver
- the errorResolver to setMultipleErrorResolver
public void setInvocationListener(InvocationListener invocationListener)
InvocationListener
instance that can be
used to provide feedback for capturing method-invocation
statistics.invocationListener
- is the listener to setpublic void setHttpStatusCodeProvider(HttpStatusCodeProvider httpStatusCodeProvider)
HttpStatusCodeProvider
instance to use for HTTP error results.httpStatusCodeProvider
- the status code provider to use for translating JSON-RPC error codes into
HTTP status messages.public void setConvertedParameterTransformer(ConvertedParameterTransformer convertedParameterTransformer)
ConvertedParameterTransformer
instance that can be
used to mutate the deserialized arguments passed to the service method during invocation.convertedParameterTransformer
- the transformer to setpublic void setShouldLogInvocationErrors(boolean shouldLogInvocationErrors)
InvocationListener
.