public class JsonRpcClient
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
JsonRpcClient.RequestListener
Provides access to the jackson
ObjectNode s
that represent the JSON-RPC requests and responses. |
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
logger |
Constructor and Description |
---|
JsonRpcClient()
Creates a client that uses the default
ObjectMapper
to map to and from JSON and Java objects. |
JsonRpcClient(com.fasterxml.jackson.databind.ObjectMapper mapper)
Creates a client that uses the given
ObjectMapper to
map to and from JSON and Java objects. |
Modifier and Type | Method and Description |
---|---|
protected com.fasterxml.jackson.databind.node.ObjectNode |
createRequest(java.lang.String methodName,
java.lang.Object argument) |
com.fasterxml.jackson.databind.node.ObjectNode |
createRequest(java.lang.String methodName,
java.lang.Object argument,
java.lang.String id) |
java.util.Map<java.lang.String,java.lang.Object> |
getAdditionalJsonContent() |
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper()
Returns the
ObjectMapper that the client
is using for JSON marshalling. |
protected void |
handleErrorResponse(com.fasterxml.jackson.databind.node.ObjectNode jsonObject) |
protected boolean |
hasError(com.fasterxml.jackson.databind.node.ObjectNode jsonObject) |
void |
invoke(java.lang.String methodName,
java.lang.Object argument,
java.io.OutputStream output)
Invokes the given method on the remote service passing
the given argument.
|
<T> T |
invokeAndReadResponse(java.lang.String methodName,
java.lang.Object argument,
java.lang.Class<T> clazz,
java.io.OutputStream output,
java.io.InputStream input)
Invokes the given method on the remote service
passing the given arguments, a generated id and reads
a response.
|
<T> T |
invokeAndReadResponse(java.lang.String methodName,
java.lang.Object argument,
java.lang.Class<T> clazz,
java.io.OutputStream output,
java.io.InputStream input,
java.lang.String id)
Invokes the given method on the remote service
passing the given arguments and reads a response.
|
java.lang.Object |
invokeAndReadResponse(java.lang.String methodName,
java.lang.Object argument,
java.lang.reflect.Type returnType,
java.io.OutputStream output,
java.io.InputStream input)
Invokes the given method on the remote service
passing the given arguments, a generated id and reads
a response.
|
void |
invokeNotification(java.lang.String methodName,
java.lang.Object argument,
java.io.OutputStream output)
Invokes the given method on the remote service passing
the given argument without reading or expecting a return
response.
|
<T> T |
readResponse(java.lang.Class<T> clazz,
java.io.InputStream input)
Reads a JSON-PRC response from the server.
|
<T> T |
readResponse(java.lang.Class<T> clazz,
java.io.InputStream input,
java.lang.String id)
Reads a JSON-PRC response from the server.
|
java.lang.Object |
readResponse(java.lang.reflect.Type returnType,
java.io.InputStream input)
Reads a JSON-PRC response from the server.
|
protected java.lang.Object |
readResponse(java.lang.reflect.Type returnType,
com.fasterxml.jackson.databind.JsonNode jsonObject) |
void |
setAdditionalJsonContent(java.util.Map<java.lang.String,java.lang.Object> additionalJsonContent) |
void |
setExceptionResolver(ExceptionResolver exceptionResolver) |
void |
setRequestIDGenerator(RequestIDGenerator requestIDGenerator)
Set the
RequestIDGenerator |
void |
setRequestListener(JsonRpcClient.RequestListener requestListener)
Sets the
JsonRpcClient.RequestListener . |
void |
writeNotification(java.lang.String methodName,
java.lang.Object argument,
java.io.OutputStream output)
Writes a JSON-RPC notification to the given
OutputStream . |
public JsonRpcClient()
ObjectMapper
to map to and from JSON and Java objects.public JsonRpcClient(com.fasterxml.jackson.databind.ObjectMapper mapper)
ObjectMapper
to
map to and from JSON and Java objects.mapper
- the ObjectMapper
public java.util.Map<java.lang.String,java.lang.Object> getAdditionalJsonContent()
public void setAdditionalJsonContent(java.util.Map<java.lang.String,java.lang.Object> additionalJsonContent)
public void setRequestListener(JsonRpcClient.RequestListener requestListener)
JsonRpcClient.RequestListener
.requestListener
- the JsonRpcClient.RequestListener
public void setRequestIDGenerator(RequestIDGenerator requestIDGenerator)
RequestIDGenerator
requestIDGenerator
- the RequestIDGenerator
public <T> T invokeAndReadResponse(java.lang.String methodName, java.lang.Object argument, java.lang.Class<T> clazz, java.io.OutputStream output, java.io.InputStream input) throws java.lang.Throwable
T
- the expected return typemethodName
- the method to invokeargument
- the argument to pass to the methodclazz
- the expected return typeoutput
- the OutputStream
to write toinput
- the InputStream
to read fromjava.lang.Throwable
- on errorwriteRequest(String, Object, OutputStream, String)
public java.lang.Object invokeAndReadResponse(java.lang.String methodName, java.lang.Object argument, java.lang.reflect.Type returnType, java.io.OutputStream output, java.io.InputStream input) throws java.lang.Throwable
methodName
- the method to invokeargument
- the argument to pass to the methodreturnType
- the expected return typeoutput
- the OutputStream
to write toinput
- the InputStream
to read fromjava.lang.Throwable
- on errorwriteRequest(String, Object, OutputStream, String)
protected void handleErrorResponse(com.fasterxml.jackson.databind.node.ObjectNode jsonObject) throws java.lang.Throwable
java.lang.Throwable
protected boolean hasError(com.fasterxml.jackson.databind.node.ObjectNode jsonObject)
public <T> T invokeAndReadResponse(java.lang.String methodName, java.lang.Object argument, java.lang.Class<T> clazz, java.io.OutputStream output, java.io.InputStream input, java.lang.String id) throws java.lang.Throwable
T
- the expected return typemethodName
- the method to invokeargument
- the argument to pass to the methodclazz
- the expected return typeoutput
- the OutputStream
to write toinput
- the InputStream
to read fromid
- id to send with the JSON-RPC requestjava.lang.Throwable
- if there is an error
while reading the responsewriteRequest(String, Object, OutputStream, String)
public void invoke(java.lang.String methodName, java.lang.Object argument, java.io.OutputStream output) throws java.io.IOException
readResponse(Type, InputStream)
must be
subsequently called.methodName
- the method to invokeargument
- the arguments to pass to the methodoutput
- the OutputStream
to write tojava.io.IOException
- on errorwriteRequest(String, Object, OutputStream, String)
public void invokeNotification(java.lang.String methodName, java.lang.Object argument, java.io.OutputStream output) throws java.io.IOException
methodName
- the method to invokeargument
- the argument to pass to the methodoutput
- the OutputStream
to write tojava.io.IOException
- on errorwriteRequest(String, Object, OutputStream, String)
public <T> T readResponse(java.lang.Class<T> clazz, java.io.InputStream input) throws java.lang.Throwable
T
- the expected return typeclazz
- the expected return typeinput
- the InputStream
to read fromjava.lang.Throwable
- on errorpublic java.lang.Object readResponse(java.lang.reflect.Type returnType, java.io.InputStream input) throws java.lang.Throwable
returnType
- the expected return typeinput
- the InputStream
to read fromjava.lang.Throwable
- on errorpublic <T> T readResponse(java.lang.Class<T> clazz, java.io.InputStream input, java.lang.String id) throws java.lang.Throwable
T
- the expected return typeclazz
- the expected return typeinput
- the InputStream
to read fromid
- The id used to compare the response withjava.lang.Throwable
- on errorprotected com.fasterxml.jackson.databind.node.ObjectNode createRequest(java.lang.String methodName, java.lang.Object argument)
public com.fasterxml.jackson.databind.node.ObjectNode createRequest(java.lang.String methodName, java.lang.Object argument, java.lang.String id)
public void writeNotification(java.lang.String methodName, java.lang.Object argument, java.io.OutputStream output) throws java.io.IOException
OutputStream
.methodName
- the method to invokeargument
- the method argumentoutput
- the OutputStream
to write tojava.io.IOException
- on errorwriteRequest(String, Object, OutputStream, String)
protected java.lang.Object readResponse(java.lang.reflect.Type returnType, com.fasterxml.jackson.databind.JsonNode jsonObject) throws java.lang.Throwable
java.lang.Throwable
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
ObjectMapper
that the client
is using for JSON marshalling.ObjectMapper
public void setExceptionResolver(ExceptionResolver exceptionResolver)
exceptionResolver
- the exceptionResolver to set