Commits

James Dumay committed b591ab8

XMLRPC-2 - Allow method level binding

Comments (0)

Files changed (2)

src/main/java/com/atlassian/xmlrpc/RPCCallMethodInterceptor.java

     {
         try
         {
-            return client.execute(serviceObject + "." + method.getName(), new Vector(Arrays.asList(args)));
+            return client.execute(serviceObject + "." + getMethodName(method), new Vector(Arrays.asList(args)));
         }
         catch (Exception e)
         {
             throw new RuntimeException("Could not execute RPC method", e);
         }
     }
+    
+    private String getMethodName(Method method)
+    {
+        String methodName = method.getName();
+        ServiceMethod serviceMethod = method.getAnnotation(ServiceMethod.class);
+        if (serviceMethod != null)
+        {
+            methodName = serviceMethod.methodName();
+        }
+        return methodName;
+    }
 }

src/test/java/com/atlassian/xmlrpc/SimpleServiceTest.java

  */
 public class SimpleServiceTest extends TestCase
 {
-    public void testSimpleBinding() throws Exception
+    public void testSimpleBinding()
+        throws Exception
     {
         final int port = 9001;
         WebServer server = new WebServer(port);
         }
     }
     
+    public void testNamedMethodBinding()
+        throws Exception
+    {
+        final int port = 9001;
+        WebServer server = new WebServer(port);
+        PropertyHandlerMapping phm = new PropertyHandlerMapping();
+        phm.addHandler("WeatherReport", com.atlassian.xmlrpc.WetherReportServiceImpl.class);
+        XmlRpcServer xmlRpcServer = server.getXmlRpcServer();
+        xmlRpcServer.setHandlerMapping(phm);
+        
+        XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
+        serverConfig.setEnabledForExtensions(true);
+        serverConfig.setContentLengthOptional(false);
+
+        server.start();
+
+        try
+        {
+            URL url = new URL("http://localhost:" + port);
+            Binder binder = new DefaultBinder();
+            WeatherReportService service = binder.bind(WeatherReportService.class, url);
+            String result = service.getReport();
+            assertEquals("Fine and sunny", result);
+        }
+        finally
+        {
+            server.shutdown();
+        }        
+    }
+    
     public void testThrowsExceptionIfBinderIsClass()
         throws Exception
     {