Java 如何打印在Apache XML-RPC中发送或接收的XML
我正在运行一个简单的客户机/服务器XML-RPC应用程序,以便更好地理解ApacheXMLRPC库 但我希望能够打印或调试客户端发送的XML输出和服务器接收的XML输出。我怎样才能找到这些数据Java 如何打印在Apache XML-RPC中发送或接收的XML,java,xml,xml-rpc,xmlrpcclient,Java,Xml,Xml Rpc,Xmlrpcclient,我正在运行一个简单的客户机/服务器XML-RPC应用程序,以便更好地理解ApacheXMLRPC库 但我希望能够打印或调试客户端发送的XML输出和服务器接收的XML输出。我怎样才能找到这些数据 //StartServer.java public class StartServer { public static void main(String args[]) throws Exception { Server server = new Server(); } } //Se
//StartServer.java
public class StartServer {
public static void main(String args[]) throws Exception {
Server server = new Server();
}
}
//Server.java
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;
public class Server {
private static final int port = 3000;
public Server() throws Exception {
WebServer webServer = new WebServer(port);
XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
PropertyHandlerMapping phm = new PropertyHandlerMapping();
phm.addHandler("reply", ReplyClass.class);
xmlRpcServer.setHandlerMapping(phm);
XmlRpcServerConfigImpl serverConfig =
(XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
serverConfig.setEnabledForExtensions(true);
serverConfig.setContentLengthOptional(false);
webServer.start();
}
}
//ReplyClass.java
public class ReplyClass {
public int reply(Object params[]){
for(int i = 0; i< params.length; i++){
System.out.println( "Params :"+params[i].toString());
}
return 0;
}
public int foo(int x){
System.out.println("foo : "+ x);
return 1;
}
}
//XMLRPCtest
import java.net.URL;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcLocalTransportFactory;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
public class XMLRPCtest {
private XmlRpcClient client;
public XMLRPCtest() {
try {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://localhost:3000"));
config.setEnabledForExtensions(true);
client = new XmlRpcClient();
client.setConfig(config);
} catch (Exception exception) {
exception.printStackTrace();
}
}
public Object execute(String command, Object[] params) {
try {
Object reply = client.execute(command, params);
return reply;
} catch (XmlRpcException e) {
e.printStackTrace();
return null;
}
}
public static void main(String args[]) {
try {
XMLRPCtest client = new XMLRPCtest();
int data[] = {};
Object[] params = new Object[]{1};
Integer result = (Integer) client.execute("reply.foo", params);
System.out.println("Result: " + result);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
//StartServer.java
公共类StartServer{
公共静态void main(字符串args[])引发异常{
服务器=新服务器();
}
}
//Server.java
导入org.apache.xmlrpc.server.PropertyHandlerMapping;
导入org.apache.xmlrpc.server.XmlRpcServer;
导入org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
导入org.apache.xmlrpc.webserver.webserver;
公共类服务器{
专用静态最终int端口=3000;
公共服务器()引发异常{
WebServer WebServer=新的WebServer(端口);
XmlRpcServer XmlRpcServer=webServer.getXmlRpcServer();
PropertyHandlerMapping phm=新的PropertyHandlerMapping();
addHandler(“reply”,ReplyClass.class);
setHandlerMapping(phm);
XmlRpcServerConfigImpl服务器配置=
(XmlRpcServerConfigImpl)xmlRpcServer.getConfig();
serverConfig.setEnabledForExtensions(true);
serverConfig.setContentLengthoOptional(false);
start();
}
}
//ReplyClass.java
公共类回复类{
public int reply(对象参数[]){
对于(int i=0;i
有一些系统属性用于设置日志级别…:)请参阅,有一些系统属性用于设置日志级别…:)看见