public class JsonRpcServer extends StringRpcServer
Class, representing an interface, and an
implementation of that interface, JsonRpcServer will reflect on the
class to construct the ServiceDescription, and will route
incoming requests for methods on the interface to the
implementation object while the mainloop() is running.RpcServer,
JsonRpcClient| Modifier and Type | Field and Description |
|---|---|
java.lang.Class<?> |
interfaceClass
The interface this server implements.
|
java.lang.Object |
interfaceInstance
The instance backing this server.
|
ServiceDescription |
serviceDescription
Holds the JSON-RPC service description for this client.
|
STRING_ENCODING| Constructor and Description |
|---|
JsonRpcServer(Channel channel,
java.lang.Class<?> interfaceClass,
java.lang.Object interfaceInstance)
Construct a server that talks to the outside world using the
given channel, and constructs a fresh temporary
queue.
|
JsonRpcServer(Channel channel,
java.lang.String queueName,
java.lang.Class<?> interfaceClass,
java.lang.Object interfaceInstance)
Construct a server that talks to the outside world using the
given channel and queue name.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
doCall(java.lang.String requestBody)
Runs a single JSON-RPC request.
|
static java.lang.String |
errorResponse(java.lang.Object id,
int code,
java.lang.String message,
java.lang.Object errorArg)
Construct and encode a JSON-RPC error response for the request
ID given, using the code, message, and possible
(JSON-encodable) argument passed in.
|
ServiceDescription |
getServiceDescription()
Public API - gets the service description record that this
service built from interfaceClass at construction time.
|
java.lang.String |
handleStringCall(java.lang.String requestBody,
AMQP.BasicProperties replyProperties)
Override our superclass' method, dispatching to doCall.
|
java.lang.reflect.Method |
matchingMethod(java.lang.String methodName,
java.lang.Object[] params)
Retrieves the best matching method for the given method name and parameters.
|
static java.lang.String |
response(java.lang.Object id,
java.lang.String label,
java.lang.Object value)
Private API - used by errorResponse and resultResponse.
|
static java.lang.String |
resultResponse(java.lang.Object id,
java.lang.Object result)
Construct and encode a JSON-RPC success response for the
request ID given, using the result value passed in.
|
handleCall, handleCast, handleStringCall, handleStringCastclose, getChannel, getQueueName, handleCall, handleCall, handleCast, handleCast, mainloop, processRequest, setupConsumer, terminateMainlooppublic ServiceDescription serviceDescription
public java.lang.Class<?> interfaceClass
public java.lang.Object interfaceInstance
public JsonRpcServer(Channel channel, java.lang.Class<?> interfaceClass, java.lang.Object interfaceInstance) throws java.io.IOException
channel - AMQP channel to useinterfaceClass - Java interface that this server is exposing to the worldinterfaceInstance - Java instance (of interfaceClass) that is being exposedjava.io.IOException - if something goes wrong during an AMQP operationpublic JsonRpcServer(Channel channel, java.lang.String queueName, java.lang.Class<?> interfaceClass, java.lang.Object interfaceInstance) throws java.io.IOException
channel - AMQP channel to usequeueName - AMQP queue name to listen for requests oninterfaceClass - Java interface that this server is exposing to the worldinterfaceInstance - Java instance (of interfaceClass) that is being exposedjava.io.IOException - if something goes wrong during an AMQP operationpublic java.lang.String handleStringCall(java.lang.String requestBody,
AMQP.BasicProperties replyProperties)
handleStringCall in class StringRpcServerpublic java.lang.String doCall(java.lang.String requestBody)
requestBody - the JSON-RPC request string (a JSON encoded value)public java.lang.reflect.Method matchingMethod(java.lang.String methodName,
java.lang.Object[] params)
public static java.lang.String errorResponse(java.lang.Object id,
int code,
java.lang.String message,
java.lang.Object errorArg)
public static java.lang.String resultResponse(java.lang.Object id,
java.lang.Object result)
public static java.lang.String response(java.lang.Object id,
java.lang.String label,
java.lang.Object value)
public ServiceDescription getServiceDescription()