You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2011/01/10 22:50:35 UTC

svn commit: r1057387 - in /tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src: main/java/sample/api/ main/java/sample/impl/ test/java/sample/

Author: jsdelfino
Date: Mon Jan 10 21:50:34 2011
New Revision: 1057387

URL: http://svn.apache.org/viewvc?rev=1057387&view=rev
Log:
Add support for both RPC and Doc-wrapped modes to the component implementation example. Test an RPC reference configured with a Doc-Wrapped binding contract.

Modified:
    tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java
    tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java
    tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java
    tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/ClientTest.java
    tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/WelloTest.java

Modified: tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java?rev=1057387&r1=1057386&r2=1057387&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java (original)
+++ tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/api/WSDLReference.java Mon Jan 10 21:50:34 2011
@@ -23,8 +23,7 @@ import org.w3c.dom.Element;
 
 public interface WSDLReference {
 
-    Element call(String op, Element e);
-    public Element callBare(String op, Element... e);
-    void callAsync(String op, Element e);
+    Element doccall(String op, Element e);
+    public Object rpccall(String op, Object... args);
     
 }

Modified: tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java?rev=1057387&r1=1057386&r2=1057387&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java (original)
+++ tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java Mon Jan 10 21:50:34 2011
@@ -39,12 +39,22 @@ import org.w3c.dom.Element;
 class SampleWSDLInvoker extends InterceptorAsyncImpl {
     final String name;
     final Object instance;
-    final Method method;
+    final Method doccall;
+    final Method rpccall;
+
+    static Method method(final Class<?> clazz, final String name, final Class<?>... types) {
+        try {
+            return clazz.getMethod("doccall", String.class, Element.class);
+        } catch (Exception e) {
+            return null;
+        }
+    }
 
     SampleWSDLInvoker(final WSDLOperation op, final Class<?> clazz, final Object instance) throws SecurityException, NoSuchMethodException {
         this.name = op.getName();
         this.instance = instance;
-        this.method = clazz.getMethod("call", String.class, Element.class);
+        this.doccall = method(clazz, "doccall", String.class, Element.class);
+        this.rpccall = method(clazz, "rpccall", String.class, Object[].class);
     }
 
     public Invoker getNext() {
@@ -56,31 +66,18 @@ class SampleWSDLInvoker extends Intercep
         return processRequest(msg);
     }
     
-    public void invokeAsyncRequest(Message msg) {
-    	// Retrieve the async callback information
-    	AsyncResponseInvoker respInvoker = (AsyncResponseInvoker)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
-    	if( respInvoker == null ) throw new ServiceRuntimeException("Async Implementation invoked with no response invoker");
-    	
-        Message responseMsg = processRequest(msg);
-        
-        // in this sample programming model we make the async
-        // response from the implementation provider. The 
-        // component implementation itself doesn't get a chance to 
-        // do async responses. 
-        
-        // At this point we could serialize the AsyncResponseInvoker and pick it up again 
-        // later to send the async response
-        
-        //((RuntimeEndpoint)msg.getTo()).invokeAsyncResponse(responseMsg);
-        respInvoker.invokeAsyncResponse(responseMsg);
-    } // end method invokeAsyncRequest
-    
     public Message processRequest(Message msg) {
         try {
-            //AsyncHeader asyncHeader = (String) message.getHeaders().get("ASYNC-HEADER");
             // Invoke the generic call method
-            Object response = method.invoke(instance, name, ((Object[])msg.getBody())[0]);
-            msg.setBody(response);
+            if (doccall != null) {
+                // Document style (args wrapped in a single wrapper element)
+                final Object response = doccall.invoke(instance, name, ((Object[])msg.getBody())[0]);
+                msg.setBody(response);
+            } else {
+                // RPC style (args are passed as an array)
+                final Object response = rpccall.invoke(instance, name, (Object[])msg.getBody());
+                msg.setBody(response);
+            }
         } catch(Exception e) {
             e.printStackTrace();
             msg.setFaultBody(e.getCause());

Modified: tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java?rev=1057387&r1=1057386&r2=1057387&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java (original)
+++ tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java Mon Jan 10 21:50:34 2011
@@ -58,7 +58,7 @@ class SampleWSDLProxy implements WSDLRef
     }
 
     @Override
-    public Element call(String op, Element e) {
+    public Element doccall(String op, Element e) {
         try {
             // Invoke the named operation on the endpoint reference
             return (Element)repr.invoke(ops.get(op), new Object[] {e});
@@ -68,37 +68,13 @@ class SampleWSDLProxy implements WSDLRef
     }
     
     @Override
-    public Element callBare(String op, Element... e) {
+    public Object rpccall(String op, Object... args) {
         try {
             // Invoke the named operation on the endpoint reference
-            return (Element)repr.invoke(ops.get(op), e);
+            return repr.invoke(ops.get(op), args);
         } catch(InvocationTargetException ex) {
             throw new RuntimeException(ex);
         }
     }    
     
-    @Override
-    public void callAsync(String op, Element e) {
-        // Asynchronously invoke the named operation on the endpoint reference
-        Message message = mf.createMessage();
-        message.setBody(new Object[]{e});
-        
-        // Generate MESSAGE_ID here. 
-        // String messageID = "myuniqueid";
-        String messageID = UUID.randomUUID().toString();
-        message.getHeaders().put(Constants.MESSAGE_ID, messageID);
-        
-        // save the message id ready for when we process the response        
-        asyncMessageMap.put(messageID, op);
-        
-        // We could add implementation specific headers here if required
-        //message.getHeaders().put(Constants.???, ???);
-        
-        try {
-            repr.invokeAsync(ops.get(op), message);
-        } catch (Throwable ex) {
-            ex.printStackTrace();
-        }
-        
-    }    
 }

Modified: tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/ClientTest.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/ClientTest.java?rev=1057387&r1=1057386&r2=1057387&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/ClientTest.java (original)
+++ tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/ClientTest.java Mon Jan 10 21:50:34 2011
@@ -58,7 +58,7 @@ public class ClientTest {
         out.println("ClientTest.wello(" + s + ")");
         final Element hreq = xdom("http://sample/hello", "hello", elem("name", text(s)));
         
-        final Element hres = wello.call("hello", hreq);
+        final Element hres = wello.doccall("hello", hreq);
         
         return xreduce(print, "", xfilter(select("result"), elems(hres))); 
     }

Modified: tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/WelloTest.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/WelloTest.java?rev=1057387&r1=1057386&r2=1057387&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/WelloTest.java (original)
+++ tuscany/sandbox/sebastien/java/wrapped/samples/extending-tuscany/implementation-sample/src/test/java/sample/WelloTest.java Mon Jan 10 21:50:34 2011
@@ -43,17 +43,31 @@ import sample.api.WSDLReference;
 @WSDL("http://sample/hello#Hello")
 public class WelloTest {
 
-    @WSDL("http://sample/upper#Upper")
+    // Uncomment and comment the next line to switch back from RPC to Doc mode
+    //WSDL("http://sample/upper#Upper")
+    @WSDL("http://sample/upperrpc#Upper")
     WSDLReference upper;
 
-    public Element call(String op, Element e) {
+    // Uncomment and comment rpccall to switch back from RPC to Doc mode
+    /*
+    public Element doccall(String op, Element e) {
         out.println("WelloTest." + op + "(" + xml(e) + ")");
         final String name = xreduce(print, "", xfilter(select("name"), elems(e)));
 
         final Element ureq = xdom("http://sample/upper", "upper", elem("s", text("Hello " + name)));
-        final Element ures = upper.call("upper", ureq);
+        final Element ures = upper.doccall("upper", ureq);
         
         final String s = xreduce(print, "", xfilter(select("result"), elems(ures)));
         return xdom("http://sample/hello", "helloResponse", elem("result", text(s)));
     }
+    */
+
+    public Element doccall(String op, Element e) {
+        out.println("WelloTest." + op + "(" + xml(e) + ")");
+        final String name = xreduce(print, "", xfilter(select("name"), elems(e)));
+
+        final String s = (String)upper.rpccall("upper", "Hello " + name);
+        
+        return xdom("http://sample/hello", "helloResponse", elem("result", text(s)));
+    }
 }