Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
XmlRpcServlet |
|
| 2.6;2,6 |
1 | /* |
|
2 | * Copyright 1999,2005 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.xmlrpc.webserver; |
|
17 | ||
18 | import java.io.IOException; |
|
19 | import java.net.URL; |
|
20 | ||
21 | import javax.servlet.ServletConfig; |
|
22 | import javax.servlet.ServletException; |
|
23 | import javax.servlet.http.HttpServlet; |
|
24 | import javax.servlet.http.HttpServletRequest; |
|
25 | import javax.servlet.http.HttpServletResponse; |
|
26 | ||
27 | import org.apache.xmlrpc.XmlRpcException; |
|
28 | import org.apache.xmlrpc.server.PropertyHandlerMapping; |
|
29 | import org.apache.xmlrpc.server.XmlRpcHandlerMapping; |
|
30 | import org.apache.xmlrpc.server.XmlRpcServer; |
|
31 | ||
32 | ||
33 | /** A default servlet implementation The typical use would |
|
34 | * be to derive a subclass, which is overwriting at least the |
|
35 | * method {@link #newXmlRpcHandlerMapping()}. |
|
36 | */ |
|
37 | 44 | public class XmlRpcServlet extends HttpServlet { |
38 | private static final long serialVersionUID = 2348768267234L; |
|
39 | private XmlRpcServletServer server; |
|
40 | ||
41 | /** Returns the servlets instance of {@link XmlRpcServletServer}. |
|
42 | * @return The configurable instance of {@link XmlRpcServletServer}. |
|
43 | */ |
|
44 | public XmlRpcServletServer getXmlRpcServletServer() { |
|
45 | 44 | return server; |
46 | } |
|
47 | ||
48 | public void init(ServletConfig pConfig) throws ServletException { |
|
49 | 44 | super.init(pConfig); |
50 | try { |
|
51 | 44 | server = newXmlRpcServer(pConfig); |
52 | 44 | server.setHandlerMapping(newXmlRpcHandlerMapping()); |
53 | 0 | } catch (XmlRpcException e) { |
54 | try { |
|
55 | 0 | log("Failed to create XmlRpcServer: " + e.getMessage(), e); |
56 | 0 | } catch (Throwable ignore) { |
57 | } |
|
58 | 0 | throw new ServletException(e); |
59 | } |
|
60 | 44 | } |
61 | ||
62 | /** Creates a new instance of {@link XmlRpcServer}, |
|
63 | * which is being used to process the requests. The default implementation |
|
64 | * will simply invoke <code>new {@link XmlRpcServer}. |
|
65 | */ |
|
66 | protected XmlRpcServletServer newXmlRpcServer(ServletConfig pConfig) |
|
67 | throws XmlRpcException { |
|
68 | 44 | return new XmlRpcServletServer(); |
69 | } |
|
70 | ||
71 | /** Creates a new handler mapping. The default implementation loads |
|
72 | * a property file from the resource |
|
73 | * <code>org/apache/xmlrpc/webserver/XmlRpcServlet.properties</code> |
|
74 | */ |
|
75 | protected XmlRpcHandlerMapping newXmlRpcHandlerMapping() throws XmlRpcException { |
|
76 | 44 | URL url = XmlRpcServlet.class.getResource("XmlRpcServlet.properties"); |
77 | 44 | if (url == null) { |
78 | 0 | throw new XmlRpcException("Failed to locate resource XmlRpcServlet.properties"); |
79 | } |
|
80 | try { |
|
81 | 44 | return new PropertyHandlerMapping(getClass().getClassLoader(), url); |
82 | 0 | } catch (IOException e) { |
83 | 0 | throw new XmlRpcException("Failed to load resource " + url + ": " + e.getMessage(), e); |
84 | } |
|
85 | } |
|
86 | ||
87 | /** Creates a new instance of {@link org.apache.xmlrpc.webserver.RequestData} |
|
88 | * for the request. |
|
89 | */ |
|
90 | public void doPost(HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, ServletException { |
|
91 | 70 | server.execute(pRequest, pResponse); |
92 | 70 | } |
93 | } |