r1198 - in xwiki-clients/p2pxwiki: lib src/main/java src/main/java/com/xpn/p2pxwiki/communication src/main/java/com/xpn/p2pxwiki/communication/rpc3 src/main/java/com/xpn/p2pxwiki/utils src/main/java/org src/main/java/org/apache src/main/java/org/apache/xmlrpc src/main/java/org/apache/xmlrpc/webserver
Sergiu Dumitriu
sdumitriu at users.forge.objectweb.org
Wed Aug 23 20:00:23 CEST 2006
Author: sdumitriu
Date: 2006-08-23 20:00:21 +0200 (Wed, 23 Aug 2006)
New Revision: 1198
Added:
xwiki-clients/p2pxwiki/lib/ws-commons-java5-1.0.1.jar
xwiki-clients/p2pxwiki/lib/ws-commons-util-1.0.1.jar
xwiki-clients/p2pxwiki/lib/xmlrpc-client-3.0rc1.jar
xwiki-clients/p2pxwiki/lib/xmlrpc-common-3.0rc1.jar
xwiki-clients/p2pxwiki/lib/xmlrpc-server-3.0rc1.jar
xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/
xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcConnectionFactory.java
xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerManager.java
xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerMapping.java
xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerStub.java
xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcNetwork.java
xwiki-clients/p2pxwiki/src/main/java/org/
xwiki-clients/p2pxwiki/src/main/java/org/apache/
xwiki-clients/p2pxwiki/src/main/java/org/apache/xmlrpc/
xwiki-clients/p2pxwiki/src/main/java/org/apache/xmlrpc/webserver/
xwiki-clients/p2pxwiki/src/main/java/org/apache/xmlrpc/webserver/XmlRpcServlet.properties
Modified:
xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/ConnectionFactory.java
xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/utils/P2PUtil.java
Log:
Added support for xmlrpc3 to XWikiP2P. Warning: it breaks about everything else.
Added: xwiki-clients/p2pxwiki/lib/ws-commons-java5-1.0.1.jar
===================================================================
(Binary files differ)
Property changes on: xwiki-clients/p2pxwiki/lib/ws-commons-java5-1.0.1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: xwiki-clients/p2pxwiki/lib/ws-commons-util-1.0.1.jar
===================================================================
(Binary files differ)
Property changes on: xwiki-clients/p2pxwiki/lib/ws-commons-util-1.0.1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: xwiki-clients/p2pxwiki/lib/xmlrpc-client-3.0rc1.jar
===================================================================
(Binary files differ)
Property changes on: xwiki-clients/p2pxwiki/lib/xmlrpc-client-3.0rc1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: xwiki-clients/p2pxwiki/lib/xmlrpc-common-3.0rc1.jar
===================================================================
(Binary files differ)
Property changes on: xwiki-clients/p2pxwiki/lib/xmlrpc-common-3.0rc1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: xwiki-clients/p2pxwiki/lib/xmlrpc-server-3.0rc1.jar
===================================================================
(Binary files differ)
Property changes on: xwiki-clients/p2pxwiki/lib/xmlrpc-server-3.0rc1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/ConnectionFactory.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/ConnectionFactory.java 2006-08-23 09:32:19 UTC (rev 1197)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/ConnectionFactory.java 2006-08-23 18:00:21 UTC (rev 1198)
@@ -2,6 +2,7 @@
import com.xpn.p2pxwiki.P2PXWikiException;
+// TODO Q: No close connection?
public interface ConnectionFactory {
HandlerStub getConnection(String peer) throws P2PXWikiException;
}
Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcConnectionFactory.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcConnectionFactory.java 2006-08-23 09:32:19 UTC (rev 1197)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcConnectionFactory.java 2006-08-23 18:00:21 UTC (rev 1198)
@@ -0,0 +1,61 @@
+package com.xpn.p2pxwiki.communication.rpc3;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+
+import com.xpn.p2pxwiki.P2PXWikiException;
+import com.xpn.p2pxwiki.communication.ConnectionFactory;
+import com.xpn.p2pxwiki.communication.ConnectorPlugin;
+import com.xpn.p2pxwiki.communication.HandlerStub;
+import com.xpn.p2pxwiki.utils.P2PUtil;
+
+public class RpcConnectionFactory implements ConnectionFactory {
+ private static Log log = LogFactory.getFactory().getInstance(RpcConnectionFactory.class);
+
+ protected static RpcConnectionFactory instance = null;
+
+ private XmlRpcClientConfigImpl config;
+ private String transportType;
+
+ public RpcConnectionFactory() throws P2PXWikiException {
+ config = new XmlRpcClientConfigImpl();
+ // TODO get properties and add them to the config
+ transportType = XmlRpcCommonsTransportFactory.class.getName();
+ // TODO make transport type customizable
+ }
+
+ public HandlerStub getConnection(String peer) throws P2PXWikiException {
+ try {
+ log.debug("getting xmlrpc connection");
+
+ // TODO make this dependency between connection factory and network explicit (in the general case!)
+ URL url = new URL(ConnectorPlugin.getNetwork().getCanonicalRemoteName(peer));
+ config.setServerURL(url);
+
+ XmlRpcClient client = new XmlRpcClient();
+ XmlRpcTransportFactory transport = (XmlRpcTransportFactory)
+ P2PUtil.getInstance(transportType, new Object[] {client}, new Class[] {XmlRpcClient.class});
+
+ client.setTransportFactory(transport);
+ client.setConfig(config);
+ return new RpcHandlerStub(peer, client);
+ } catch (MalformedURLException e) {
+ throw new P2PXWikiException(0, e);
+ }
+ }
+
+ public static RpcConnectionFactory getInstance() throws P2PXWikiException {
+ log.debug("getInstance");
+ if (instance == null) {
+ instance = new RpcConnectionFactory();
+ }
+ return instance;
+ }
+}
Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerManager.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerManager.java 2006-08-23 09:32:19 UTC (rev 1197)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerManager.java 2006-08-23 18:00:21 UTC (rev 1198)
@@ -0,0 +1,60 @@
+package com.xpn.p2pxwiki.communication.rpc3;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xmlrpc.server.XmlRpcServer;
+import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
+import org.apache.xmlrpc.webserver.WebServer;
+
+import com.xpn.p2pxwiki.P2PXWikiException;
+import com.xpn.p2pxwiki.communication.ConnectorPlugin;
+import com.xpn.p2pxwiki.communication.Handler;
+import com.xpn.p2pxwiki.communication.HandlerManager;
+
+public class RpcHandlerManager implements HandlerManager {
+ private static Log log = LogFactory.getFactory().getInstance(RpcHandlerManager.class);
+// private XmlRpcServlet servlet;
+ private RpcHandlerMapping handlerMapping = new RpcHandlerMapping(); // TODO could allow this to be loaded from a file at startup (PropertyHandlerMapping)
+
+ protected static RpcHandlerManager instance = null;
+
+ protected RpcHandlerManager() throws P2PXWikiException {
+ log.debug("constructor");
+ try {
+ // TODO this is only one (stupid) way to do it - could be useful in tests
+ WebServer webServer = new WebServer(ConnectorPlugin.getServerPort()); // TODO make dependency to network explicit (obtain the port from the network object)
+ XmlRpcServer server = webServer.getXmlRpcServer();
+ server.setHandlerMapping(handlerMapping);
+ XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) server.getConfig();
+ serverConfig.setEnabledForExtensions(true);
+ webServer.start();
+
+// // TODO Find out why this does not work.
+// ServletWebServer webServer = new ServletWebServer(new XmlRpcServlet(), ConnectorPlugin.getServerPort()); // TODO make dependency to network explicit (obtain the port from the network object)
+// XmlRpcServer server = webServer.getXmlRpcServer();
+// server.setHandlerMapping(handlerMapping);
+// webServer.start();
+// } catch (ServletException e) {
+// throw new P2PXWikiException(0, e);
+ } catch (IOException e) {
+ throw new P2PXWikiException(0, e);
+ }
+ }
+
+ public boolean addHandler(Handler handler) throws P2PXWikiException {
+ return handlerMapping.addHandler(handler.getName(), handler);
+ }
+
+ public boolean removeHandler(Handler handler) throws P2PXWikiException {
+ return handlerMapping.removeHandler(handler.getName());
+ }
+
+ public static RpcHandlerManager getInstance() throws P2PXWikiException {
+ if(instance == null){
+ instance = new RpcHandlerManager();
+ }
+ return instance;
+ }
+}
Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerMapping.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerMapping.java 2006-08-23 09:32:19 UTC (rev 1197)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerMapping.java 2006-08-23 18:00:21 UTC (rev 1198)
@@ -0,0 +1,80 @@
+package com.xpn.p2pxwiki.communication.rpc3;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcHandler;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import org.apache.xmlrpc.server.XmlRpcNoSuchHandlerException;
+
+public class RpcHandlerMapping implements XmlRpcHandlerMapping {
+ private Map map = new HashMap();
+
+ class RpcHandler implements XmlRpcHandler {
+ private Object handler;
+
+ public RpcHandler(Object handler) {
+ this.handler = handler;
+ }
+
+ // This is just a simple initial implementation - first match returned
+ public Object execute(XmlRpcRequest request) throws XmlRpcException {
+ Class c = handler.getClass();
+ Method[] methods = c.getMethods();
+ Method method = null;
+ String methodName = request.getMethodName().substring(request.getMethodName().indexOf(".")+1);
+ for (int i = 0; method == null && i<methods.length; i++) {
+ if (methods[i].getName().equals(methodName) &&
+ methods[i].getParameterTypes().length
+ == request.getParameterCount()) {
+ boolean found = true;
+ for (int j = 0; !found && j<request.getParameterCount(); j++) {
+ if (!methods[i].getParameterTypes()[j].isInstance(request.getParameter(j))) {
+ found = false;
+ }
+ }
+ if (found) {
+ method = methods[i];
+ }
+ }
+ }
+ if (method != null) {
+ Object[] args = new Object[request.getParameterCount()];
+ for (int i = 0; i<request.getParameterCount(); i++) {
+ args[i] = request.getParameter(i);
+ }
+ try {
+ return method.invoke(handler, args);
+ } catch (Exception ex) {
+ throw new XmlRpcException("invocation error", ex);
+ }
+ } else {
+ throw new XmlRpcException("method not found");
+ }
+ }
+ }
+
+ public XmlRpcHandler getHandler(String handlerNameDotMethod)
+ throws XmlRpcNoSuchHandlerException, XmlRpcException {
+ String handlerName = handlerNameDotMethod.substring(0, handlerNameDotMethod.indexOf("."));
+ Object handler = map.get(handlerName);
+ if (handler != null) {
+ return new RpcHandler(handler);
+ } else {
+ throw new XmlRpcNoSuchHandlerException(handlerName);
+ }
+ }
+
+ public boolean addHandler(String handlerName, Object handler) {
+ map.put(handlerName, handler);
+ return true;
+ }
+
+ public boolean removeHandler(String handlerName) {
+ return map.remove(handlerName) != null;
+ }
+}
+
Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerStub.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerStub.java 2006-08-23 09:32:19 UTC (rev 1197)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcHandlerStub.java 2006-08-23 18:00:21 UTC (rev 1198)
@@ -0,0 +1,34 @@
+package com.xpn.p2pxwiki.communication.rpc3;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.client.XmlRpcClient;
+
+import com.xpn.p2pxwiki.P2PXWikiException;
+import com.xpn.p2pxwiki.communication.HandlerStub;
+
+public class RpcHandlerStub implements HandlerStub {
+
+ private String peer;
+ private XmlRpcClient client;
+
+ public RpcHandlerStub(String peer, XmlRpcClient client) {
+ this.peer = peer;
+ this.client = client;
+ }
+
+ public Object execute(String function, Object[] params) throws P2PXWikiException {
+ try {
+ return client.execute(function, params);
+ } catch (XmlRpcException e) {
+ throw new P2PXWikiException(P2PXWikiException.REMOTE_CALL, e);
+ }
+ }
+
+ public String getPeerName() {
+ return peer;
+ }
+
+ public void close() throws P2PXWikiException {
+ // nothing to do here
+ }
+}
Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcNetwork.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcNetwork.java 2006-08-23 09:32:19 UTC (rev 1197)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc3/RpcNetwork.java 2006-08-23 18:00:21 UTC (rev 1198)
@@ -0,0 +1,47 @@
+package com.xpn.p2pxwiki.communication.rpc3;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+//TODO remove this import from ANYWHERE! statics will have to go away!
+import com.xpn.p2pxwiki.communication.ConnectorPlugin;
+
+import com.xpn.p2pxwiki.communication.Network;
+
+public class RpcNetwork implements Network {
+ private static Log log = LogFactory.getFactory().getInstance(RpcNetwork.class);
+ protected static RpcNetwork instance = null;
+
+ protected RpcNetwork(){
+ log.debug("constructor");
+ }
+
+ // TODO This will be written differently
+ public String getCanonicalLocalName() {
+ // TODO network should store the local server port
+ // TODO network should store the local peer name / address too
+ try{
+ return "http://" + InetAddress.getLocalHost().getCanonicalHostName() + ":" + ConnectorPlugin.getServerPort();
+ }
+ catch(UnknownHostException ex){
+ return "http://" + ConnectorPlugin.getPeerName() + ".xwiki.com:" + ConnectorPlugin.getServerPort();
+ }
+ }
+
+ // FIXME This will be written differently
+ public String getCanonicalRemoteName(String peer) {
+ // TODO network should store the server port
+ // TODO this assumes all peers are using the same port ... crap
+ return "http://" + peer + ":" + ConnectorPlugin.getServerPort();
+ }
+
+ public static RpcNetwork getInstance(){
+ if(instance == null){
+ instance = new RpcNetwork();
+ }
+ return instance;
+ }
+}
Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/utils/P2PUtil.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/utils/P2PUtil.java 2006-08-23 09:32:19 UTC (rev 1197)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/utils/P2PUtil.java 2006-08-23 18:00:21 UTC (rev 1198)
@@ -6,8 +6,12 @@
public class P2PUtil {
public static Object getInstance(String className) throws P2PXWikiException {
+ return getInstance(className, (Object[])null, (Class[])null);
+ }
+
+ public static Object getInstance(String className, Object[] params, Class[] paramTypes) throws P2PXWikiException {
try{
- return Class.forName(className).getConstructor((Class[])null).newInstance((Object[])null);
+ return Class.forName(className).getConstructor(paramTypes).newInstance(params);
} catch(ClassNotFoundException ex){
throw new P2PXWikiException(P2PXWikiException.INSTANCE, ex);
} catch(NoSuchMethodException ex){
Added: xwiki-clients/p2pxwiki/src/main/java/org/apache/xmlrpc/webserver/XmlRpcServlet.properties
===================================================================
More information about the Xwiki-notifications
mailing list