`
frank127
  • 浏览: 10535 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论
阅读更多
package org.apache.xmlrpc.demo.webserver;

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 JavaServer {
	private static final int port = 8080;

	public static void main(String[] args) throws Exception {
		System.out.println("Attempting to start XML-RPC Server...");
		WebServer webServer = new WebServer(port);

		XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();

		PropertyHandlerMapping phm = new PropertyHandlerMapping();
		/*
		 * Load handler definitions from a property file. The property file
		 * might look like: Calculator=org.apache.xmlrpc.demo.Calculator
		 * org.apache
		 * .xmlrpc.demo.proxy.Adder=org.apache.xmlrpc.demo.proxy.AdderImpl
		 */
		phm.load(Thread.currentThread().getContextClassLoader(),
				"MyHandlers.properties");

		/*
		 * You may also provide the handler classes directly, like this:
		 * phm.addHandler("Calculator",
		 * org.apache.xmlrpc.demo.Calculator.class);
		 * phm.addHandler(org.apache.xmlrpc.demo.proxy.Adder.class.getName(),
		 * org.apache.xmlrpc.demo.proxy.AdderImpl.class);
		 */
		xmlRpcServer.setHandlerMapping(phm);

		XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer
				.getConfig();
		serverConfig.setEnabledForExtensions(true);
		serverConfig.setContentLengthOptional(false);

		webServer.start();
	}
}



package org.apache.xmlrpc.demo.client;

import java.net.URL;

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
import org.apache.xmlrpc.client.util.ClientFactory;

import com.foo.Adder;

public class JavaClient {
	public static void main(String[] args) throws Exception {
		// create configuration
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setServerURL(new URL("http://127.0.0.1:8080/xmlrpc"));
		config.setEnabledForExtensions(true);
		config.setConnectionTimeout(60 * 1000);
		config.setReplyTimeout(60 * 1000);

		XmlRpcClient client = new XmlRpcClient();

		// use Commons HttpClient as transport
		client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));
		// set configuration
		client.setConfig(config);

		// make the a regular call
		Object[] params = new Object[] { new Integer(2), new Integer(3) };
		Integer result = (Integer) client.execute("Calculator.add", params);
		System.out.println("2 + 3 = " + result);

		// make a call using dynamic proxy
		ClientFactory factory = new ClientFactory(client);
		Adder adder = (Adder) factory.newInstance(Adder.class);
		int sum = adder.add(2, 4);
		System.out.println("2 + 4 = " + sum);
	}
}



MyHandlers.properties

Calculator=org.apache.xmlrpc.demo.Calculator
com.foo.Adder=com.foo.AdderImpl
分享到:
评论
2 楼 fxbird 2011-04-21  
不要误导人啦,在web容器里不能用WebServer这个类。
1 楼 ahomeeye 2011-04-20  
大哥,下面的那个类没有提供呀。总得说明一下吧,初学者不懂的。
import com.foo.Adder;

相关推荐

    xml-rpc学习心得

    xml-rpc 学习心得是我自己的学习心得体会。

    3.0 XML-RPC 官方示例+源码+官网地址资料.rar

    3.0 XML-RPC

    Apache xml-rpc入门

    Apache xml-rpc入门详细的描述xmlrpc的开发过程,并带有例子。

    XML-RPC客户端程序

    XML-RPC客户端测试程序 向XMLRPC服务器发送一个XML-RPC请求,以文本文件读取xml文件; 记录返回的数据到文件中; windows命令行程序,使用前请配置*.pln文件 askcyg@hotmail.com

    php xml-rpc 协议 非常有用哦

    XML-RPC的全称是XML Remote Procedure Call,即XML远程方法调用。  它是一套允许运行在不同操作系统、不同环境的程序实现基于Internet过程调用的规范和一系列的实现。

    xml-rpc.net.2.4.0.zip

    Version 2.4.0 has been released: xml-rpc.net.2.4.0.zip New feature and fixed issues: New StructParams property on XmlRpcMethodAttribute which provides supports for APIs which use a struct to ...

    LabVIEW XML-RPC

    LabVIEW 版 XML_RPC,有7.1,8.0,8.5三个版本。

    XML-RPC.rar_HTTP协议_XML-R_XML-RPC _xml rpc

    简单介绍了XML-RPC这种通过HTTP协议进行RPC通信的规范。 以Apache XML-RPC 3.0为基础,对XML-RPC的基本原理及Apache XML-RPC 3.0的主要特性进行了讨论和分析

    使用 XML-RPC 为 C++ 应用程序启用 Web 服务

    简单对象访问协议(Simple Object Access Protocol,SOAP)、代表性状态传输(Representational State Transfer,REST)以及 XML 远程过程调用协议(XML Remote Procedure Call,XML-RPC)等 Web 服务协议可帮助将...

    XML-RPC.rar_python xml rpc_python写xml_xml rpc_xml-rpc python

    我自己动手写的XML-RPC,最近自己写了写关于大规模分布式只是学习的实验,其中用到了python里面的清凉级

    apache XML-RPC 实现

    commons-logging-1.1.jar ws-commons-util-1.0.2.jar xmlrpc-client-3.1.3.jar xmlrpc-common-3.1.3.jar xmlrpc-server-3.1.3.jar

    xml-rpc协议资料

    xml-rpc 是一套规范及其一系列的实现,允许运行在不同操作系统、不同环境的程序基于internet进行远程过程调用。  这种远程过程调用使用http作为传输协议,xml作为传送信息的编码格式。Xml-Rpc的定义尽可能的保持了...

    xml-rpc.net.3.0

    xml-rpc.net.3.0.0.270-snapshot,用于c#访问解析XML-RPC

    Java RPC通信机制之XML-RPC

    Java RPC通信机制之XML-RPC

    解决Delphi XML-RPC 中文乱码

    此资源不要下载,请下载最新的 最近要用XML-RPC机制实现...下载Delphi XML-RPC 后发现中文字符串会出现乱码,跟踪代码后发现XML-RPC默认的 字符编码是UTF-8,而且QT也都是用UTF-8编程,故把传输字符串改为UTF-8就行了,

    Delphi XML-RPC 中文乱码解决方法

    最近要用XML-RPC机制实现delphi程序与Qt程序之间的通信,从开源网站http://sourceforge.net/projects/delphixml-rpc/下载Delphi XML-RPC 后发现中文字符串会出现乱码,跟踪代码后发现XML-RPC默认的字符编码是UTF-8,...

    解决Delphi XML-RPC 中文乱码、结构/数组等没有解析I4项BUG

    最近要用XML-RPC机制实现delphi程序与Qt程序之间的通信,从...下载Delphi XML-RPC 后发现中文字符串会出现乱码,跟踪代码后发现XML-RPC默认的 字符编码是UTF-8,而且QT也都是用UTF-8编程,故把传输字符串改为UTF-8就行了。

    apache XML-RPC

    apache XML-RPC,开发所需5个jarapache XML-RPC,开发所需5个jar

    Apache的XML-RPC简化你的WebService应用

    NULL 博文链接:https://x7700.iteye.com/blog/1186416

Global site tag (gtag.js) - Google Analytics