commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r321126 - in /jakarta/commons/sandbox/proxy/trunk: ./ src/java/org/apache/commons/proxy/exception/ src/java/org/apache/commons/proxy/factory/javassist/ src/java/org/apache/commons/proxy/handler/ src/test/org/apache/commons/proxy/handler/
Date Fri, 14 Oct 2005 14:08:25 GMT
Author: jcarman
Date: Fri Oct 14 07:08:17 2005
New Revision: 321126

URL: http://svn.apache.org/viewcvs?rev=321126&view=rev
Log:
Adding support for Apache XML-RPC.

Added:
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/exception/InvocationHandlerException.java
  (with props)
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/XmlRpcInvocationHandler.java
  (with props)
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestXmlRpcInvocationHandler.java
  (with props)
Modified:
    jakarta/commons/sandbox/proxy/trunk/build.xml
    jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml
    jakarta/commons/sandbox/proxy/trunk/project.xml
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java

Modified: jakarta/commons/sandbox/proxy/trunk/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/build.xml?rev=321126&r1=321125&r2=321126&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/build.xml (original)
+++ jakarta/commons/sandbox/proxy/trunk/build.xml Fri Oct 14 07:08:17 2005
@@ -70,6 +70,8 @@
         <runtime-dependency groupId="log4j" version="1.2.9" />
         <runtime-dependency groupId="commons-discovery" version="0.2" />
         <runtime-dependency groupId="javassist" version="3.0"/>
+        <runtime-dependency groupId="xmlrpc" version="2.0" />
+        <runtime-dependency groupId="commons-codec" version="1.3" />
         <build-dependency groupId="junit" version="3.8.1"/>
         <build-dependency groupId="jmock" version="1.0.1" />
     </target>

Modified: jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml?rev=321126&r1=321125&r2=321126&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml (original)
+++ jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml Fri Oct 14 07:08:17 2005
@@ -165,6 +165,24 @@
         <SOURCES />
       </library>
     </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/lib/runtime/xmlrpc/xmlrpc.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/lib/runtime/commons-codec/commons-codec.jar!/"
/>
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
     <orderEntryProperties />
   </component>
 </module>

Modified: jakarta/commons/sandbox/proxy/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/project.xml?rev=321126&r1=321125&r2=321126&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/project.xml (original)
+++ jakarta/commons/sandbox/proxy/trunk/project.xml Fri Oct 14 07:08:17 2005
@@ -259,6 +259,24 @@
                 <comment>The JMock Mock Objects Library</comment>
             </properties>
         </dependency>
+        <dependency>
+            <groupId>xmlrpc</groupId>
+            <artifactId>xmlrpc</artifactId>
+            <version>2.0</version>
+            <url>http://ws.apache.org/xmlrpc/</url>
+            <properties>
+                <comment>Apache XML-RPC</comment>
+            </properties>
+        </dependency>
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.3</version>
+            <url>http://jakarta.apache.org/commons/codec/</url>
+            <properties>
+                <comment>Jakarta Commons Codec</comment>
+            </properties>
+        </dependency>
     </dependencies>
 
     <build>

Added: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/exception/InvocationHandlerException.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/exception/InvocationHandlerException.java?rev=321126&view=auto
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/exception/InvocationHandlerException.java
(added)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/exception/InvocationHandlerException.java
Fri Oct 14 07:08:17 2005
@@ -0,0 +1,43 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.proxy.exception;
+
+/**
+ * @author James Carman
+ * @version 1.0
+ */
+public class InvocationHandlerException extends RuntimeException
+{
+    public InvocationHandlerException()
+    {
+    }
+
+    public InvocationHandlerException( String message )
+    {
+        super( message );
+    }
+
+    public InvocationHandlerException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public InvocationHandlerException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

Propchange: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/exception/InvocationHandlerException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/exception/InvocationHandlerException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java?rev=321126&r1=321125&r2=321126&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistMethodInvocation.java
Fri Oct 14 07:08:17 2005
@@ -112,7 +112,7 @@
         constructor.setBody( "{\n\tsuper($$);\n}" );
         ctClass.addConstructor( constructor );
         final CtMethod proceedMethod = new CtMethod( JavassistUtils.resolve( Object.class
), "proceed",
-                                                     JavassistUtils.resolve( ProxyUtils.EMPTY_ARGUMENT_TYPES
), ctClass );
+                                                     JavassistUtils.resolve( new Class[0]
), ctClass );
         final Class[] argumentTypes = interfaceMethod.getParameterTypes();
         final StringBuffer proceedBody = new StringBuffer( "{\n" );
         if( !Void.TYPE.equals( interfaceMethod.getReturnType() ) )
@@ -124,14 +124,14 @@
             proceedBody.append( "\t" );
         }
         proceedBody.append( "( (" );
-        proceedBody.append( interfaceMethod.getDeclaringClass().getName() );
+        proceedBody.append( JavassistUtils.getJavaClassName( interfaceMethod.getDeclaringClass()
) );
         proceedBody.append( " )target )." );
         proceedBody.append( interfaceMethod.getName() );
         proceedBody.append( "(" );
         for( int i = 0; i < argumentTypes.length; ++i )
         {
             proceedBody.append( "(" );
-            proceedBody.append( argumentTypes[i].getName() );
+            proceedBody.append( JavassistUtils.getJavaClassName( argumentTypes[i] ) );
             proceedBody.append( ")arguments[" );
             proceedBody.append( i );
             proceedBody.append( "]" );

Added: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/XmlRpcInvocationHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/XmlRpcInvocationHandler.java?rev=321126&view=auto
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/XmlRpcInvocationHandler.java
(added)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/XmlRpcInvocationHandler.java
Fri Oct 14 07:08:17 2005
@@ -0,0 +1,63 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.proxy.handler;
+
+import org.apache.xmlrpc.XmlRpcHandler;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.commons.proxy.exception.InvocationHandlerException;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.Vector;
+
+/**
+ * @author James Carman
+ * @version 1.0
+ */
+public class XmlRpcInvocationHandler implements InvocationHandler
+{
+    private final XmlRpcHandler handler;
+    private final String handlerName;
+
+    public XmlRpcInvocationHandler( XmlRpcHandler handler, String handlerName )
+    {
+        this.handler = handler;
+        this.handlerName = handlerName;
+    }
+
+    public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
+    {
+        final Object returnValue = handler.execute( handlerName + "." + method.getName(),
toArgumentVector( args ) );
+        if( returnValue instanceof XmlRpcException )
+        {
+            throw new InvocationHandlerException( "Unable to execute XML-RPC call.", ( XmlRpcException
)returnValue );
+
+        }
+        return returnValue;
+    }
+
+    private Vector toArgumentVector( Object[] args )
+    {
+        final Vector v = new Vector();
+        for( int i = 0; i < args.length; i++ )
+        {
+            Object arg = args[i];
+            v.addElement( arg );
+        }
+        return v;
+    }
+}

Propchange: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/XmlRpcInvocationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/handler/XmlRpcInvocationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestXmlRpcInvocationHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestXmlRpcInvocationHandler.java?rev=321126&view=auto
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestXmlRpcInvocationHandler.java
(added)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestXmlRpcInvocationHandler.java
Fri Oct 14 07:08:17 2005
@@ -0,0 +1,72 @@
+/* $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.proxy.handler;
+
+import junit.framework.TestCase;
+import org.apache.commons.proxy.factory.cglib.CglibProxyFactory;
+import org.apache.commons.proxy.util.Echo;
+import org.apache.commons.proxy.util.EchoImpl;
+import org.apache.commons.proxy.exception.InvocationHandlerException;
+import org.apache.xmlrpc.WebServer;
+import org.apache.xmlrpc.XmlRpcClient;
+
+/**
+ * @author James Carman
+ */
+public class TestXmlRpcInvocationHandler extends TestCase
+{
+    private WebServer server;
+    private XmlRpcClient client;
+
+    protected void setUp() throws Exception
+    {
+        server = new WebServer( 9999 );
+        server.addHandler( "echo", new EchoImpl() );
+        server.start();
+        client = new XmlRpcClient( "http://localhost:9999/RPC2" );
+    }
+
+    protected void tearDown() throws Exception
+    {
+        server.shutdown();
+    }
+
+    public void testInvalidHandlerName()
+    {
+        final XmlRpcInvocationHandler handler = new XmlRpcInvocationHandler( client, "invalid"
);
+        final Echo echo = ( Echo ) new CglibProxyFactory()
+                .createInvocationHandlerProxy( handler, new Class[]{ Echo.class } );
+        try
+        {
+            echo.echoBack( "Hello" );
+            fail();
+        }
+        catch( InvocationHandlerException e )
+        {
+            
+        }
+    }
+
+    public void testValidInvocation() throws Exception
+    {
+        final XmlRpcInvocationHandler handler = new XmlRpcInvocationHandler( client, "echo"
);
+        final Echo echo = ( Echo ) new CglibProxyFactory()
+                .createInvocationHandlerProxy( handler, new Class[]{ Echo.class } );
+        assertEquals( "Hello", echo.echoBack( "Hello" ) );
+
+    }
+}
\ No newline at end of file

Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestXmlRpcInvocationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/handler/TestXmlRpcInvocationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message