View Javadoc

1   package net.sourceforge.blogentis.modules.screens;
2   
3   //-----------------------------------------------------------------------
4   //Blogentis - a blog publishing platform.
5   //Copyright (C) 2004 Tassos Bassoukos <abassouk@gmail.com>
6   //
7   //This library is free software; you can redistribute it and/or
8   //modify it under the terms of the GNU Lesser General Public
9   //License as published by the Free Software Foundation; either
10  //version 2.1 of the License, or (at your option) any later version.
11  //
12  //This library is distributed in the hope that it will be useful,
13  //but WITHOUT ANY WARRANTY; without even the implied warranty of
14  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  //Lesser General Public License for more details.
16  //
17  //You should have received a copy of the GNU Lesser General Public
18  //License along with this library; if not, write to the Free Software
19  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  //-----------------------------------------------------------------------
21  //
22  //$Id: RPC2.java,v 1.1 2004/10/22 17:34:10 tassos Exp $
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  }