public final class RPC extends Object
Modifier and Type | Method and Description |
---|---|
static RPCRequest |
decodeRequest(String encodedRequest)
Returns an
RPCRequest that is built by decoding the contents of an
encoded RPC request. |
static RPCRequest |
decodeRequest(String encodedRequest,
Class<?> type)
Returns an
RPCRequest that is built by decoding the contents of an
encoded RPC request and optionally validating that type can handle the
request. |
static RPCRequest |
decodeRequest(String encodedRequest,
Class<?> type,
SerializationPolicyProvider serializationPolicyProvider)
Returns an
RPCRequest that is built by decoding the contents of an
encoded RPC request and optionally validating that type can handle the
request. |
static String |
encodeResponseForFailedRequest(RPCRequest rpcRequest,
Throwable cause)
Returns a string that encodes an exception.
|
static String |
encodeResponseForFailure(Method serviceMethod,
Throwable cause)
Returns a string that encodes an exception.
|
static String |
encodeResponseForFailure(Method serviceMethod,
Throwable cause,
SerializationPolicy serializationPolicy)
Returns a string that encodes an exception.
|
static String |
encodeResponseForFailure(Method serviceMethod,
Throwable cause,
SerializationPolicy serializationPolicy,
int flags) |
static String |
encodeResponseForSuccess(Method serviceMethod,
Object object)
Returns a string that encodes the object.
|
static String |
encodeResponseForSuccess(Method serviceMethod,
Object object,
SerializationPolicy serializationPolicy)
Returns a string that encodes the object.
|
static String |
encodeResponseForSuccess(Method serviceMethod,
Object object,
SerializationPolicy serializationPolicy,
int flags) |
static SerializationPolicy |
getDefaultSerializationPolicy()
Returns a default serialization policy.
|
static String |
invokeAndEncodeResponse(Object target,
Method serviceMethod,
Object[] args)
Returns a string that encodes the result of calling a service method, which
could be the value returned by the method or an exception thrown by it.
|
static String |
invokeAndEncodeResponse(Object target,
Method serviceMethod,
Object[] args,
SerializationPolicy serializationPolicy)
Returns a string that encodes the result of calling a service method, which
could be the value returned by the method or an exception thrown by it.
|
static String |
invokeAndEncodeResponse(Object target,
Method serviceMethod,
Object[] args,
SerializationPolicy serializationPolicy,
int flags) |
public static RPCRequest decodeRequest(String encodedRequest)
RPCRequest
that is built by decoding the contents of an
encoded RPC request.
This method is equivalent to calling decodeRequest(String, Class)
with null
for the type parameter.
encodedRequest
- a string that encodes the RemoteService
interface, the service method to call, and the arguments to for
the service methodRPCRequest
instanceIncompatibleRemoteServiceException
- if any of the following
conditions apply:
ClassLoader
acquired from
Thread.currentThread().getContextClassLoader()
cannot load the service interface or any of the types specified
in the encodedRequestRemoteService
null
and is not
assignable to the requested RemoteService
interface
public static RPCRequest decodeRequest(String encodedRequest, Class<?> type)
RPCRequest
that is built by decoding the contents of an
encoded RPC request and optionally validating that type can handle the
request. If the type parameter is not null
, the implementation
checks that the type is assignable to the RemoteService
interface
requested in the encoded request string.
Invoking this method with null
for the type parameter,
decodeRequest(encodedRequest, null)
, is equivalent to calling
decodeRequest(encodedRequest)
.
encodedRequest
- a string that encodes the RemoteService
interface, the service method, and the arguments to pass to the
service methodtype
- if not null
, the implementation checks that the
type is assignable to the RemoteService
interface encoded
in the encoded request string.RPCRequest
instanceNullPointerException
- if the encodedRequest is null
IllegalArgumentException
- if the encodedRequest is an empty stringIncompatibleRemoteServiceException
- if any of the following
conditions apply:
ClassLoader
acquired from
Thread.currentThread().getContextClassLoader()
cannot load the service interface or any of the types specified
in the encodedRequestRemoteService
null
and is not
assignable to the requested RemoteService
interface
public static RPCRequest decodeRequest(String encodedRequest, Class<?> type, SerializationPolicyProvider serializationPolicyProvider)
RPCRequest
that is built by decoding the contents of an
encoded RPC request and optionally validating that type can handle the
request. If the type parameter is not null
, the implementation
checks that the type is assignable to the RemoteService
interface
requested in the encoded request string.
If the serializationPolicyProvider parameter is not null
, it
is asked for a SerializationPolicy
to use to restrict the set of
types that can be decoded from the request. If this parameter is
null
, then only subtypes of
IsSerializable
or
types which have custom field serializers can be decoded.
Invoking this method with null
for the type parameter,
decodeRequest(encodedRequest, null)
, is equivalent to calling
decodeRequest(encodedRequest)
.
encodedRequest
- a string that encodes the RemoteService
interface, the service method, and the arguments to pass to the
service methodtype
- if not null
, the implementation checks that the
type is assignable to the RemoteService
interface encoded
in the encoded request string.serializationPolicyProvider
- if not null
, the
implementation asks this provider for a
SerializationPolicy
which will be used to restrict the set
of types that can be decoded from this requestRPCRequest
instanceNullPointerException
- if the encodedRequest is null
IllegalArgumentException
- if the encodedRequest is an empty stringIncompatibleRemoteServiceException
- if any of the following
conditions apply:
ClassLoader
acquired from
Thread.currentThread().getContextClassLoader()
cannot load the service interface or any of the types specified
in the encodedRequestRemoteService
null
and is not
assignable to the requested RemoteService
interface
public static String encodeResponseForFailedRequest(RPCRequest rpcRequest, Throwable cause) throws SerializationException
rpcRequest
is null
a default serialization policy and default request
flags will be used. Otherwise these information are taken from
rpcRequest
.
This method should be used if the RPC request could not be decoded or
could not be executed because of an exception thrown, e.g.
IncompatibleRemoteServiceException
, RpcTokenException
rpcRequest
- the RPCRequest that failed to execute, may be nullcause
- the Throwable
that was thrownSerializationException
- if the result cannot be serializedpublic static String encodeResponseForFailure(Method serviceMethod, Throwable cause) throws SerializationException
null
, it is an error if the exception is not in the method's
list of checked exceptions.serviceMethod
- the method that threw the exception, may be
null
cause
- the Throwable
that was thrownNullPointerException
- if the cause is null
SerializationException
- if the result cannot be serializedUnexpectedException
- if the result was an unexpected exception (a
checked exception not declared in the serviceMethod's signature)public static String encodeResponseForFailure(Method serviceMethod, Throwable cause, SerializationPolicy serializationPolicy) throws SerializationException
null
, it is an error if the exception is not in the method's
list of checked exceptions.
If the serializationPolicy parameter is not null
, it is used
to determine what types can be encoded as part of this response. If this
parameter is null
, then only subtypes of
IsSerializable
or
types which have custom field serializers may be encoded.
serviceMethod
- the method that threw the exception, may be
null
cause
- the Throwable
that was thrownserializationPolicy
- determines the serialization policy to be usedNullPointerException
- if the cause or the serializationPolicy
are null
SerializationException
- if the result cannot be serializedUnexpectedException
- if the result was an unexpected exception (a
checked exception not declared in the serviceMethod's signature)public static String encodeResponseForFailure(Method serviceMethod, Throwable cause, SerializationPolicy serializationPolicy, int flags) throws SerializationException
SerializationException
public static String encodeResponseForSuccess(Method serviceMethod, Object object) throws SerializationException
serviceMethod
- the method whose result we are encodingobject
- the instance that we wish to encodeIllegalArgumentException
- if the result is not assignable to the
service method's return typeNullPointerException
- if the service method is null
SerializationException
- if the result cannot be serializedpublic static String encodeResponseForSuccess(Method serviceMethod, Object object, SerializationPolicy serializationPolicy) throws SerializationException
If the serializationPolicy parameter is not null
, it is used
to determine what types can be encoded as part of this response. If this
parameter is null
, then only subtypes of
IsSerializable
or
types which have custom field serializers may be encoded.
serviceMethod
- the method whose result we are encodingobject
- the instance that we wish to encodeserializationPolicy
- determines the serialization policy to be usedIllegalArgumentException
- if the result is not assignable to the
service method's return typeNullPointerException
- if the serviceMethod or the
serializationPolicy are null
SerializationException
- if the result cannot be serializedpublic static String encodeResponseForSuccess(Method serviceMethod, Object object, SerializationPolicy serializationPolicy, int flags) throws SerializationException
SerializationException
public static SerializationPolicy getDefaultSerializationPolicy()
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args) throws SerializationException
This method does no security checking; security checking must be done on the method prior to this invocation.
target
- instance on which to invoke the serviceMethodserviceMethod
- the method to invokeargs
- arguments used for the method invocationSecurityException
- if the method cannot be accessed or if the number
or type of actual and formal arguments differSerializationException
- if an object could not be serialized by the
streamUnexpectedException
- if the serviceMethod throws a checked exception
that is not declared in its signaturepublic static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, SerializationPolicy serializationPolicy) throws SerializationException
If the serializationPolicy parameter is not null
, it is used
to determine what types can be encoded as part of this response. If this
parameter is null
, then only subtypes of
IsSerializable
or
types which have custom field serializers may be encoded.
This method does no security checking; security checking must be done on the method prior to this invocation.
target
- instance on which to invoke the serviceMethodserviceMethod
- the method to invokeargs
- arguments used for the method invocationserializationPolicy
- determines the serialization policy to be usedNullPointerException
- if the serviceMethod or the
serializationPolicy are null
SecurityException
- if the method cannot be accessed or if the number
or type of actual and formal arguments differSerializationException
- if an object could not be serialized by the
streamUnexpectedException
- if the serviceMethod throws a checked exception
that is not declared in its signaturepublic static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args, SerializationPolicy serializationPolicy, int flags) throws SerializationException
SerializationException
Copyright © 2018. All rights reserved.