if (clientOracle == null) {
throw new NullPointerException("clientOracle");
}
CommandSink sink;
try {
sink = clientOracle.createCommandSink(stream);
} catch (IOException e) {
throw new SerializationException("Unable to initialize output", e);
}
try {
Object result = serviceMethod.invoke(target, args);
try {
streamResponse(clientOracle, result, sink, false);
} catch (SerializationException e) {
streamResponse(clientOracle, e, sink, true);
}
} catch (IllegalAccessException e) {
SecurityException securityException = new SecurityException(
formatIllegalAccessErrorMessage(target, serviceMethod));
securityException.initCause(e);
throw securityException;
} catch (IllegalArgumentException e) {
SecurityException securityException = new SecurityException(
formatIllegalArgumentErrorMessage(target, serviceMethod, args));
securityException.initCause(e);
throw securityException;
} catch (InvocationTargetException e) {
// Try to encode the caught exception
Throwable cause = e.getCause();
// Don't allow random RuntimeExceptions to be thrown back to the client
if (!RPCServletUtils.isExpectedException(serviceMethod, cause)) {
throw new UnexpectedException("Service method '"
+ getSourceRepresentation(serviceMethod)
+ "' threw an unexpected exception: " + cause.toString(), cause);
}
streamResponse(clientOracle, cause, sink, true);
}
sink.finish();
}