1 16 17 18 package org.apache.xmlrpc; 19 20 import java.io.IOException ; 21 import java.io.OutputStream ; 22 23 import javax.servlet.ServletConfig ; 24 import javax.servlet.ServletException ; 25 import javax.servlet.http.HttpServlet ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 29 38 public class XmlRpcProxyServlet extends HttpServlet 39 { 40 private XmlRpcServer xmlrpc; 41 42 47 public void init(ServletConfig config) throws ServletException 48 { 49 if ("true".equalsIgnoreCase(config.getInitParameter("debug"))) 50 { 51 XmlRpc.setDebug(true); 52 } 53 String url = config.getInitParameter("url"); 54 xmlrpc = new XmlRpcServer(); 55 try 56 { 57 xmlrpc.addHandler("$default", new XmlRpcClientLite(url)); 58 } 59 catch (Exception x) 60 { 61 throw new ServletException ("Invalid URL: " + url + " (" 62 + x.toString () + ")"); 63 } 64 } 65 66 73 public void doPost(HttpServletRequest req, HttpServletResponse res) 74 throws ServletException , IOException 75 { 76 byte[] result = xmlrpc.execute(req.getInputStream ()); 77 res.setContentType("text/xml"); 78 res.setContentLength(result.length); 79 OutputStream output = res.getOutputStream(); 80 output.write(result); 81 output.flush(); 82 } 83 } 84 | Popular Tags |