KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > connector > soap > XMLRPCServlet


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ioc.connector.soap;
8
9 import java.io.OutputStream JavaDoc;
10 import java.io.IOException JavaDoc;
11 import javax.servlet.http.HttpServletRequest JavaDoc;
12 import javax.servlet.http.HttpServletResponse JavaDoc;
13 import javax.servlet.http.HttpServlet JavaDoc;
14 import javax.servlet.ServletException JavaDoc;
15
16 import org.apache.xmlrpc.XmlRpcServer;
17
18 /**
19  * 将调用转发给 JRMPContainerService,完成真正的调用
20  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
21  */

22
23 public class XMLRPCServlet extends HttpServlet JavaDoc {
24     private static XmlRpcServer xmlrpc;
25
26     public void init() throws ServletException JavaDoc {
27         xmlrpc = new XmlRpcServer();
28         try {
29             xmlrpc.addHandler("$default", new JRMPXmlRpcHandler());
30         }
31         catch(Exception JavaDoc e) {
32             throw new ServletException JavaDoc(e);
33         }
34     }
35
36     protected void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws ServletException JavaDoc, IOException JavaDoc {
37         res.setContentType("text/plain");
38         OutputStream JavaDoc out = res.getOutputStream();
39         out.write("xml rpc proxy servlet\n".getBytes());
40         out.close();
41     }
42
43     protected void doPost(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws ServletException JavaDoc, IOException JavaDoc {
44         byte[] result = xmlrpc.execute(req.getInputStream());
45         res.setContentType("text/xml");
46         res.setContentLength(result.length);
47         OutputStream JavaDoc output = res.getOutputStream();
48         output.write(result);
49         output.flush();
50         output.close();
51     }
52
53     public static void main(String JavaDoc[] args) {
54
55     }
56 }
Popular Tags