Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../../img/srcFileCovDistChart0.png 48% of files have more coverage
21   124   5   5,25
0   51   0,24   4
4     1,25  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  XmlRpcController       Line # 54 21 0% 5 25 0% 0.0
 
No Tests
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.web.controller;
33   
34    import net.sourceforge.pebble.webservice.BloggerAPIHandler;
35    import net.sourceforge.pebble.webservice.MetaWeblogAPIHandler;
36    import net.sourceforge.pebble.webservice.PebbleAPIHandler;
37    import net.sourceforge.pebble.webservice.SearchAPIHandler;
38    import org.apache.xmlrpc.XmlRpcServer;
39    import org.springframework.context.ApplicationContext;
40    import org.springframework.web.context.support.WebApplicationContextUtils;
41   
42    import javax.servlet.ServletException;
43    import javax.servlet.http.HttpServlet;
44    import javax.servlet.http.HttpServletRequest;
45    import javax.servlet.http.HttpServletResponse;
46    import java.io.IOException;
47    import java.io.OutputStream;
48   
49    /**
50    * Single entry point for all XML-RPC requests (e.g. Blogger API).
51    *
52    * @author Simon Brown
53    */
 
54    public class XmlRpcController extends HttpServlet {
55   
56    /**
57    * Initialises this instance.
58    */
 
59  0 toggle public void init() {
60    }
61   
62    /**
63    * Processes the request - this is delegated to from doGet and doPost.
64    *
65    * @param request the HttpServletRequest instance
66    * @param response the HttpServletResponse instance
67    */
 
68  0 toggle protected void processRequest(HttpServletRequest request,
69    HttpServletResponse response)
70    throws ServletException, IOException {
71   
72  0 try {
73  0 XmlRpcServer xmlrpc = new XmlRpcServer();
74  0 ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
75   
76  0 BloggerAPIHandler bloggerApi = (BloggerAPIHandler)ctx.getBean("bloggerApiHandler");
77  0 xmlrpc.addHandler("blogger", bloggerApi);
78   
79  0 MetaWeblogAPIHandler metaweblogApi = (MetaWeblogAPIHandler)ctx.getBean("metaweblogApiHandler");
80  0 xmlrpc.addHandler("metaWeblog", metaweblogApi);
81   
82  0 PebbleAPIHandler pebbleApi = (PebbleAPIHandler)ctx.getBean("pebbleApiHandler");
83  0 xmlrpc.addHandler("pebble", pebbleApi);
84   
85  0 SearchAPIHandler searchApi = (SearchAPIHandler)ctx.getBean("searchApiHandler");
86  0 xmlrpc.addHandler("search", searchApi);
87   
88  0 byte[] result = xmlrpc.execute(request.getInputStream());
89  0 response.setContentType("text/xml; charset=UTF-8");
90  0 response.setContentLength(result.length);
91  0 OutputStream out = response.getOutputStream();
92  0 out.write(result);
93  0 out.flush();
94    } catch (Exception e) {
95  0 e.printStackTrace();
96  0 throw new ServletException(e);
97    }
98    }
99   
100    /**
101    * A default implementation of doGet that delegates to the processRequest method.
102    *
103    * @param req the HttpServletRequest instance
104    * @param res the HttpServletResponse instance
105    */
 
106  0 toggle protected void doGet(HttpServletRequest req, HttpServletResponse res)
107    throws ServletException, IOException {
108   
109  0 processRequest(req, res);
110    }
111   
112    /**
113    * A default implementation of doPost that delegates to the processRequest method.
114    *
115    * @param req the HttpServletRequest instance
116    * @param res the HttpServletResponse instance
117    */
 
118  0 toggle protected void doPost(HttpServletRequest req, HttpServletResponse res)
119    throws ServletException, IOException {
120   
121  0 processRequest(req, res);
122    }
123   
124    }