Я впервые пишу здесь, и я не смог найти ответ на свой вопрос во время поиска, поэтому давайте посмотрим, смогу ли я правильно объяснить себя.
Я использую XML-RPC как часть большого проекта, но я представлю упрощенный код, в котором получаю тот же результат.
Соединение работает отлично, если я не выкидываю исключения. Моя проблема состоит в том, чтобы выдать исключение с сервера на клиент. Я получаю исключение XmlRpcException на стороне клиента, но его причина всегда null . Похоже, исключение потеряно при передаче. Есть идеи почему?
Мой сервер:
public class JavaServer {
public Integer sum(int x, int y) throws Exception {
throw new MineException("ABABBABA");
}
public static void main (String [] args) {
try {
System.out.println("Attempting to start XML-RPC Server...");
WebServer server = new WebServer(80);
XmlRpcServer xmlRpcServer = server.getXmlRpcServer();
PropertyHandlerMapping phm = new PropertyHandlerMapping();
phm.addHandler("test", JavaServer.class);
xmlRpcServer.setHandlerMapping(phm);
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
serverConfig.setEnabledForExceptions(true);
server.start();
System.out.println("Started successfully.");
System.out.println("Accepting requests. (Halt program to stop.)");
} catch (Exception exception) {
System.err.println("JavaServer: " + exception);
}}}
Мой клиент:
public static void main(String[] args) {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try {
config.setServerURL(new URL("http://localhost:80"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Object[] params = new Object[] { new Integer(38), new Integer(3), };
Integer result = (Integer) client.execute("test.sum", params);
System.out.println("Results " + result);
} catch (XmlRpcException exception) {
Throwable cause = exception.getCause();
if(cause != null) {
if(cause instanceof MineException) {
System.out.println(((MineException)cause).getMessage());
}
else { System.out.println("Cause not instance of Exception"); }
}
else { System.out.println("Cause was null"); }
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}