try {
SimplePayloadDecoder decoder;
try {
decoder = new SimplePayloadDecoder(clientOracle, encodedRequest);
} catch (ClassNotFoundException e) {
throw new IncompatibleRemoteServiceException(
"Client does not have a type sent by the server", e);
}
CommandServerSerializationStreamReader streamReader = new CommandServerSerializationStreamReader();
if (decoder.getThrownValue() != null) {
streamReader.prepareToRead(Collections.singletonList(decoder.getThrownValue()));
try {
throw new RemoteException((Throwable) streamReader.readObject());
} catch (ClassCastException e) {
throw new SerializationException(
"The remote end threw something other than a Throwable", e);
} catch (SerializationException e) {
throw new IncompatibleRemoteServiceException(
"The remote end threw an exception which could not be deserialized",
e);
}
} else {
streamReader.prepareToRead(decoder.getValues());
}
// Read the name of the RemoteService interface
String serviceIntfName = streamReader.readString();
if (type != null) {
if (!implementsInterface(type, serviceIntfName)) {
// The service does not implement the requested interface
throw new IncompatibleRemoteServiceException(
"Blocked attempt to access interface '" + serviceIntfName
+ "', which is not implemented by '" + printTypeName(type)
+ "'; this is either misconfiguration or a hack attempt");
}
}
Class<?> serviceIntf;
try {
serviceIntf = getClassFromSerializedName(null, serviceIntfName,
classLoader);
if (!RemoteService.class.isAssignableFrom(serviceIntf)) {
// The requested interface is not a RpcService interface
throw new IncompatibleRemoteServiceException(
"Blocked attempt to access interface '"
+ printTypeName(serviceIntf)
+ "', which doesn't extend RpcService; "
+ "this is either misconfiguration or a hack attempt");
}
} catch (ClassNotFoundException e) {
throw new IncompatibleRemoteServiceException(
"Could not locate requested interface '" + serviceIntfName
+ "' in default classloader", e);
}
String serviceMethodName = streamReader.readString();
int paramCount = streamReader.readInt();
Class<?>[] parameterTypes = new Class[paramCount];
for (int i = 0; i < parameterTypes.length; i++) {
String paramClassName = streamReader.readString();
try {
parameterTypes[i] = getClassFromSerializedName(clientOracle,
paramClassName, classLoader);
} catch (ClassNotFoundException e) {
throw new IncompatibleRemoteServiceException("Parameter " + i
+ " of is of an unknown type '" + paramClassName + "'", e);
}
}
try {
Method method = serviceIntf.getMethod(serviceMethodName, parameterTypes);
Object[] parameterValues = new Object[parameterTypes.length];
for (int i = 0; i < parameterValues.length; i++) {
Object o = CommandSerializationUtil.getAccessor(parameterTypes[i]).readNext(
streamReader);
parameterValues[i] = o;
}
return new RPCRequest(method, parameterValues, null, 0);
} catch (NoSuchMethodException e) {
throw new IncompatibleRemoteServiceException(
formatMethodNotFoundErrorMessage(serviceIntf, serviceMethodName,
parameterTypes));
}
} catch (SerializationException ex) {
throw new IncompatibleRemoteServiceException(ex.getMessage(), ex);
}
}