1 package net.sourceforge.blogentis.modules.screens;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import net.sourceforge.blogentis.plugins.BlogPluginService;
26 import net.sourceforge.blogentis.xmlrpc.IRPCExtensionPoint;
27
28 import org.apache.commons.io.CopyUtils;
29 import org.apache.turbine.modules.screens.RawScreen;
30 import org.apache.turbine.util.RunData;
31 import org.apache.xmlrpc.XmlRpc;
32 import org.apache.xmlrpc.XmlRpcServer;
33
34 /***
35 * @author abas
36 */
37 public class RPC2
38 extends RawScreen {
39 protected static XmlRpcServer xrs = null;
40
41 private static synchronized void initServer() {
42 if (xrs != null)
43 return;
44 XmlRpc.setEncoding("utf-8");
45 xrs = new XmlRpcServer();
46 IRPCExtensionPoint extensionPoint = (IRPCExtensionPoint)BlogPluginService
47 .locateExtensionPoint(IRPCExtensionPoint.class);
48 if (extensionPoint != null)
49 extensionPoint.setupServer(xrs);
50 }
51
52 protected String getContentType(RunData data) {
53 return "text-xml";
54 }
55
56 protected void doOutput(RunData data)
57 throws Exception {
58 if (xrs == null)
59 initServer();
60
61 byte[] result = xrs.execute(data.getRequest().getInputStream());
62 data.getResponse().setContentType("text/xml");
63 data.getResponse().setContentLength(result.length);
64 CopyUtils.copy(result, data.getResponse().getOutputStream());
65 data.getResponse().getOutputStream().flush();
66 }
67 }