1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.xmlrpc.webserver; |
17 |
|
|
18 |
|
import java.io.IOException; |
19 |
|
import java.io.InputStream; |
20 |
|
import java.io.OutputStream; |
21 |
|
|
22 |
|
import javax.servlet.ServletException; |
23 |
|
import javax.servlet.http.HttpServletRequest; |
24 |
|
import javax.servlet.http.HttpServletResponse; |
25 |
|
|
26 |
|
import org.apache.xmlrpc.XmlRpcException; |
27 |
|
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl; |
28 |
|
import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig; |
29 |
|
import org.apache.xmlrpc.server.XmlRpcHttpServerConfig; |
30 |
|
import org.apache.xmlrpc.server.XmlRpcStreamServer; |
31 |
|
import org.apache.xmlrpc.util.HttpUtil; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
44 |
public class XmlRpcServletServer extends XmlRpcStreamServer { |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
protected static class RequestData extends XmlRpcHttpRequestConfigImpl { |
44 |
70 |
private final HttpServletRequest request; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
70 |
public RequestData(HttpServletRequest pRequest) { |
50 |
70 |
request = pRequest; |
51 |
70 |
} |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
0 |
public HttpServletRequest getRequest() { return request; } |
56 |
|
} |
57 |
|
|
58 |
|
protected RequestData newConfig(HttpServletRequest pRequest) { |
59 |
70 |
return new RequestData(pRequest); |
60 |
|
} |
61 |
|
|
62 |
|
protected RequestData getConfig(HttpServletRequest pRequest) { |
63 |
70 |
RequestData result = newConfig(pRequest); |
64 |
70 |
XmlRpcHttpServerConfig serverConfig = (XmlRpcHttpServerConfig) getConfig(); |
65 |
70 |
result.setBasicEncoding(serverConfig.getBasicEncoding()); |
66 |
70 |
result.setContentLengthOptional(serverConfig.isContentLengthOptional()); |
67 |
70 |
result.setEnabledForExtensions(serverConfig.isEnabledForExtensions()); |
68 |
70 |
result.setGzipCompressing(HttpUtil.isUsingGzipEncoding(pRequest.getHeader("Content-Encoding"))); |
69 |
70 |
result.setGzipRequesting(HttpUtil.isUsingGzipEncoding(pRequest.getHeaders("Accept-Encoding"))); |
70 |
70 |
result.setEncoding(pRequest.getCharacterEncoding()); |
71 |
70 |
HttpUtil.parseAuthorization(result, pRequest.getHeader("Authorization")); |
72 |
70 |
return result; |
73 |
|
} |
74 |
|
|
75 |
|
protected RequestData newRequestData(HttpServletRequest pRequest) { |
76 |
0 |
return new RequestData(pRequest); |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
public void execute(HttpServletRequest pRequest, HttpServletResponse pResponse) |
86 |
|
throws ServletException, IOException { |
87 |
70 |
RequestData config = getConfig(pRequest); |
88 |
|
try { |
89 |
70 |
super.execute(config, pResponse); |
90 |
0 |
} catch (XmlRpcException e) { |
91 |
0 |
throw new ServletException(e); |
92 |
|
} |
93 |
70 |
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
protected boolean isContentLengthRequired(XmlRpcStreamRequestConfig pConfig) { |
98 |
70 |
RequestData data = (RequestData) pConfig; |
99 |
70 |
if (data.isEnabledForExtensions()) { |
100 |
|
|
101 |
70 |
return true; |
102 |
|
} |
103 |
0 |
return !((XmlRpcHttpServerConfig) getConfig()).isContentLengthOptional(); |
104 |
|
} |
105 |
|
|
106 |
|
protected InputStream newInputStream(XmlRpcStreamRequestConfig pConfig, Object pConnection) throws IOException { |
107 |
70 |
return ((RequestData) pConfig).request.getInputStream(); |
108 |
|
} |
109 |
|
|
110 |
|
protected OutputStream newOutputStream(XmlRpcStreamRequestConfig pConfig, Object pConnection) throws IOException { |
111 |
70 |
HttpServletResponse response = ((HttpServletResponse) pConnection); |
112 |
70 |
response.setContentType("text/xml"); |
113 |
70 |
return response.getOutputStream(); |
114 |
|
} |
115 |
|
|
116 |
|
protected OutputStream getOutputStream(XmlRpcStreamRequestConfig pConfig, |
117 |
|
Object pConnection, |
118 |
|
int pSize) throws IOException { |
119 |
70 |
if (pSize != -1) { |
120 |
70 |
((HttpServletResponse) pConnection).setContentLength(pSize); |
121 |
|
} |
122 |
70 |
return super.getOutputStream(pConfig, pConnection, pSize); |
123 |
|
} |
124 |
|
|
125 |
|
protected void closeConnection(Object pConnection) throws IOException { |
126 |
70 |
((HttpServletResponse) pConnection).getOutputStream().close(); |
127 |
70 |
} |
128 |
|
} |