File: 06_use_xmlrpc3.diff

package info (click to toggle)
red5 1.0~svn4374-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 11,456 kB
  • sloc: java: 56,478; xml: 13,069; sh: 593; makefile: 33; jsp: 24
file content (91 lines) | stat: -rw-r--r-- 3,586 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Description: src/org/red5/server/net/servlet/StatisticsServlet.java:
 Use Java XmlRpc 3.1 API
 (Debian package libxmlrpc3-server-java).
Author: Damien Raude-Morvan <drazzib@debian.org>
Forwarded: yes
Bug: http://trac.red5.org/ticket/572
Last-Update: 2011-03-04
--- a/src/org/red5/server/net/servlet/StatisticsServlet.java
+++ b/src/org/red5/server/net/servlet/StatisticsServlet.java
@@ -20,13 +20,19 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.URL;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.xmlrpc.XmlRpcServer;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.server.PropertyHandlerMapping;
+import org.apache.xmlrpc.server.RequestProcessorFactoryFactory;
+import org.apache.xmlrpc.server.RequestProcessorFactoryFactory.RequestSpecificProcessorFactoryFactory;
+import org.apache.xmlrpc.webserver.XmlRpcServlet;
 import org.red5.server.api.IContext;
 import org.red5.server.statistics.XmlRpcScopeStatistics;
 import org.springframework.web.context.WebApplicationContext;
@@ -38,12 +44,10 @@
  * @author The Red5 Project (red5@osflash.org)
  * @author Joachim Bauch (jojo@struktur.de)
  */
-public class StatisticsServlet extends HttpServlet {
+public class StatisticsServlet extends XmlRpcServlet {
 
 	private static final long serialVersionUID = 5810139109603229027L;
 
-	private final transient XmlRpcServer server = new XmlRpcServer();
-
 	protected transient WebApplicationContext webAppCtx;
 
 	protected transient IContext webContext;
@@ -51,6 +55,7 @@
 	/** {@inheritDoc} */
 	@Override
 	public void init() throws ServletException {
+		super.init();
 		webAppCtx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
 		if (webAppCtx == null) {
 			webAppCtx = (WebApplicationContext) getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
@@ -60,20 +65,26 @@
 		}
 
 		webContext = (IContext) webAppCtx.getBean("web.context");
+	}
 
-		// Register handlers in XML-RPC server
-		server.addHandler("scopes", new XmlRpcScopeStatistics(webContext.getGlobalScope()));
+	public IContext getContext() {
+		return this.webContext;
 	}
 
-	/** {@inheritDoc} */
-	@Override
-	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		// Process request with XML-RPC server
-		byte[] result = server.execute(request.getInputStream());
-		response.setContentType("text/xml");
-		response.setContentLength(result.length);
-		OutputStream out = response.getOutputStream();
-		out.write(result);
-		out.close();
+	protected PropertyHandlerMapping newPropertyHandlerMapping(URL url) throws IOException, XmlRpcException {
+		PropertyHandlerMapping mapping = new PropertyHandlerMapping();
+
+		mapping.addHandler("scopes", XmlRpcScopeStatistics.class);
+
+		RequestProcessorFactoryFactory factory = new RequestSpecificProcessorFactoryFactory(){
+			protected Object getRequestProcessor(Class pClass, XmlRpcRequest pRequest) throws XmlRpcException {
+				XmlRpcScopeStatistics stats = (XmlRpcScopeStatistics) super.getRequestProcessor(pClass, pRequest);
+				stats.setGlobalScope(StatisticsServlet.this.getContext().getGlobalScope());
+				return stats;
+			}
+		};
+		mapping.setRequestProcessorFactoryFactory(factory);
+		mapping.load(Thread.currentThread().getContextClassLoader(), url);
+		return mapping;
 	}
 }