public class JsonRpcClient extends RpcClient implements InvocationHandler
JsonRpcClient class.
JSON-RPC services are self-describing - each service is able
to list its supported procedures, and each procedure
describes its parameters and types. An instance of
JsonRpcClient retrieves its service description using the
standard system.describe procedure when it is
constructed, and uses the information to coerce parameter
types appropriately. A JSON service description is parsed
into instances of ServiceDescription. Client
code can access the service description by reading the
serviceDescription field of
JsonRpcClient instances.
JsonRpcClient delegates JSON parsing and generating to
a JsonRpcMapper.
By default only a safe set of return types is accepted from the remote
service description (primitives, String, Map, List,
and common boxed types). Services that return custom types must pass an
explicit allowlist via the constructors that accept allowedReturnTypes.
call(String, Object[]),
JsonRpcMapper,
JacksonJsonRpcMapperRpcClient.ResponseDEFAULT_REPLY_HANDLER, NO_TIMEOUT| Constructor and Description |
|---|
JsonRpcClient(Channel channel,
String exchange,
String routingKey) |
JsonRpcClient(Channel channel,
String exchange,
String routingKey,
int timeout)
Construct a new JsonRpcClient using the safe default return-type allowlist.
|
JsonRpcClient(Channel channel,
String exchange,
String routingKey,
int timeout,
JsonRpcMapper mapper)
Construct a new JsonRpcClient using the safe default return-type allowlist.
|
JsonRpcClient(Channel channel,
String exchange,
String routingKey,
int timeout,
JsonRpcMapper mapper,
Set<Class<?>> allowedReturnTypes)
Construct a new JsonRpcClient with an explicit allowlist of permitted return types.
|
JsonRpcClient(RpcClientParams rpcClientParams,
JsonRpcMapper mapper)
Construct a new
JsonRpcClient that only accepts return types from the built-in
safe set (primitives, String, Map, List, common boxed types). |
JsonRpcClient(RpcClientParams rpcClientParams,
JsonRpcMapper mapper,
Set<Class<?>> allowedReturnTypes)
Construct a new
JsonRpcClient with an explicit allowlist of permitted return types. |
| Modifier and Type | Method and Description |
|---|---|
Object |
call(String[] args)
Deprecated.
This method will be removed in the next major version
|
Object |
call(String method,
Object[] params)
Public API - builds, encodes and sends a JSON-RPC request, and
waits for the response.
|
static Object |
coerce(String val,
String type)
Deprecated.
This method will be removed in the next major version
|
<T> T |
createProxy(Class<T> klass)
Public API - gets a dynamic proxy for a particular interface class.
|
ServiceDescription |
getServiceDescription()
Public API - gets the service description record that this
service loaded from the server itself at construction time.
|
Object |
invoke(Object proxy,
Method method,
Object[] args)
Public API - implements InvocationHandler.invoke.
|
close, doCall, doCall, getChannel, getConsumer, getContinuationMap, getCorrelationId, getExchange, getRoutingKey, incrementingCorrelationIdSupplier, incrementingCorrelationIdSupplier, mapCall, mapCall, primitiveCall, primitiveCall, primitiveCall, publish, responseCall, responseCall, setupConsumer, stringCallpublic JsonRpcClient(RpcClientParams rpcClientParams, JsonRpcMapper mapper) throws IOException, JsonRpcException, TimeoutException
JsonRpcClient that only accepts return types from the built-in
safe set (primitives, String, Map, List, common boxed types).
Services that declare custom return types will cause construction to fail with an
IllegalStateException. Use
JsonRpcClient(RpcClientParams, JsonRpcMapper, Set) to allow additional types.
IllegalStateException - if the service description contains a return type not in
the allowlistIOExceptionJsonRpcExceptionTimeoutExceptionpublic JsonRpcClient(RpcClientParams rpcClientParams, JsonRpcMapper mapper, Set<Class<?>> allowedReturnTypes) throws IOException, JsonRpcException, TimeoutException
JsonRpcClient with an explicit allowlist of permitted return types.
The provided types are merged with the built-in safe set, so common types (String,
Map, primitives, etc.) do not need to be listed explicitly.
allowedReturnTypes - additional return types to accept from the remote service
description, on top of the built-in safe setIllegalStateException - if the service description contains a return type not in
the allowlistIOExceptionJsonRpcExceptionTimeoutExceptionpublic JsonRpcClient(Channel channel, String exchange, String routingKey, int timeout, JsonRpcMapper mapper) throws IOException, JsonRpcException, TimeoutException
TimeoutException - if a response is not received within the timeout specified, if anyIllegalStateException - if the service description contains a return type not in
the allowlistIOExceptionJsonRpcExceptionpublic JsonRpcClient(Channel channel, String exchange, String routingKey, int timeout, JsonRpcMapper mapper, Set<Class<?>> allowedReturnTypes) throws IOException, JsonRpcException, TimeoutException
allowedReturnTypes - additional return types to accept from the remote service
description, on top of the built-in safe setTimeoutException - if a response is not received within the timeout specified, if anyIllegalStateException - if the service description contains a return type not in
the allowlistIOExceptionJsonRpcExceptionpublic JsonRpcClient(Channel channel, String exchange, String routingKey, int timeout) throws IOException, JsonRpcException, TimeoutException
TimeoutException - if a response is not received within the timeout specified, if anyIOExceptionJsonRpcExceptionpublic JsonRpcClient(Channel channel, String exchange, String routingKey) throws IOException, JsonRpcException, TimeoutException
@Deprecated public static Object coerce(String val, String type) throws NumberFormatException
call(String[]) to ad-hoc convert
strings into the required data types for a call.
This method is deprecated because it uses homegrown JSON utilities
that don't deal correctly with complex types. The JacksonJsonRpcMapper
has been introduced to handle primitive and complex types, as well
as primitive wrappers correctly.NumberFormatExceptionpublic Object call(String method, Object[] params) throws IOException, JsonRpcException, TimeoutException
JsonRpcException - if the reply object contained an exceptionTimeoutException - if a response is not received within the timeout specified, if anyIOExceptionpublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable
invoke in interface InvocationHandlerThrowablepublic <T> T createProxy(Class<T> klass) throws IllegalArgumentException
IllegalArgumentException@Deprecated public Object call(String[] args) throws NumberFormatException, IOException, JsonRpcException, TimeoutException
call(String, Object[]), but takes the
method name from the first entry in args, and the
parameters from subsequent entries. All parameter values are
passed through coerce() to attempt to make them the types the
server is expecting.
This method is deprecated because it uses homegrown JSON utilities
that don't deal correctly with complex types. The JacksonJsonRpcMapper
has been introduced to handle primitive and complex types, as well
as primitive wrappers correctly.JsonRpcException - if the reply object contained an exceptionNumberFormatException - if a coercion failedTimeoutException - if a response is not received within the timeout specified, if anyIOExceptioncoerce(java.lang.String, java.lang.String)public ServiceDescription getServiceDescription()
Copyright © 2026 Broadcom Inc. and its subsidiaries.. All rights reserved.