You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by bi...@apache.org on 2020/04/14 20:02:28 UTC

[axis-axis2-java-core] 16/38: Merged r1231465 to the 1.5 branch.

This is an automated email from the ASF dual-hosted git repository.

billblough pushed a commit to branch 1_5
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit c480fe37b6908a9b93205f0b8331b92749634bbb
Author: Sagara Gunathunga <sa...@apache.org>
AuthorDate: Sat Jan 14 09:07:40 2012 +0000

    Merged r1231465 to the 1.5 branch.
---
 .../userguide/clients/EchoNonBlockingClient.java   | 65 ++++++++++++++--------
 .../clients/EchoNonBlockingDualClient.java         | 63 +++++++++++++--------
 2 files changed, 82 insertions(+), 46 deletions(-)

diff --git a/modules/samples/userguide/src/userguide/clients/EchoNonBlockingClient.java b/modules/samples/userguide/src/userguide/clients/EchoNonBlockingClient.java
index cae78e6..ba47eeb 100644
--- a/modules/samples/userguide/src/userguide/clients/EchoNonBlockingClient.java
+++ b/modules/samples/userguide/src/userguide/clients/EchoNonBlockingClient.java
@@ -25,16 +25,15 @@ import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.client.async.AsyncResult;
-import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.client.async.AxisCallback;
 
 /**
  * Sample for asynchronous single channel non-blocking service invocation.
- * Message Exchage Pattern IN-OUT
+ * Message Exchange Pattern IN-OUT
  */
 public class EchoNonBlockingClient {
     private static EndpointReference targetEPR = new EndpointReference("http://127.0.0.1:8080/axis2/services/MyService");
-
+ 
     public static void main(String[] args) {
         ServiceClient sender = null;
         try {
@@ -43,38 +42,58 @@ public class EchoNonBlockingClient {
             options.setTo(targetEPR);
             options.setAction("urn:echo");
 
-            //Callback to handle the response
-            Callback callback = new Callback() {
-                public void onComplete(AsyncResult result) {
-                    System.out.println(result.getResponseEnvelope());
-                }
-
-                public void onError(Exception e) {
-                    e.printStackTrace();
-                }
-            };
-
+            TestCallback axisCallback = new TestCallback("CallBack1") ;
+            
             //Non-Blocking Invocation
             sender = new ServiceClient();
             sender.setOptions(options);
-            sender.sendReceiveNonBlocking(payload, callback);
-
-            //Wait till the callback receives the response.
-            while (!callback.isComplete()) {
-                Thread.sleep(1000);
+            sender.sendReceiveNonBlocking(payload, axisCallback);
+            
+            while ( ! axisCallback.isComplete( ) ) {
+                Thread.sleep(100);
             }
 
-        } catch (AxisFault axisFault) {
-            axisFault.printStackTrace();
         } catch (Exception ex) {
             ex.printStackTrace();
         } finally {
             try {
                 sender.cleanup();
             } catch (AxisFault axisFault) {
-                //
+                axisFault.printStackTrace();
             }
         }
 
     }
+    
+    static class TestCallback implements AxisCallback {
+
+        private String name = null;
+        private boolean complete = false;
+        
+        public TestCallback (String name) {
+                this.name = name;
+        }
+
+        public void onError (Exception e) {
+                e.printStackTrace();
+        }
+
+        public void onComplete() {
+        	System.out.println( "Message transmission complete") ;
+            complete = true;
+        }
+        
+        public boolean isComplete() {
+            return complete;
+        }
+        
+        public void onMessage(org.apache.axis2.context.MessageContext arg0) {
+           System.out.println( "Call Back " + name + " got Result: " + arg0.getEnvelope() ) ;
+        }
+
+        public void onFault(org.apache.axis2.context.MessageContext arg0) {
+        	System.out.println( "Call Back " + name + " got Fault: " + arg0.getEnvelope() ) ;
+        }
+    }
+  
 }
diff --git a/modules/samples/userguide/src/userguide/clients/EchoNonBlockingDualClient.java b/modules/samples/userguide/src/userguide/clients/EchoNonBlockingDualClient.java
index 7f5a5ad..b13a331 100644
--- a/modules/samples/userguide/src/userguide/clients/EchoNonBlockingDualClient.java
+++ b/modules/samples/userguide/src/userguide/clients/EchoNonBlockingDualClient.java
@@ -23,13 +23,11 @@ package userguide.clients;
 import org.apache.axiom.om.OMElement;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.client.async.AsyncResult;
-import org.apache.axis2.client.async.Callback;
-
-import javax.xml.namespace.QName;
+import org.apache.axis2.client.async.AxisCallback;
 
 /**
  * Sample for asynchronous dual channel non-blocking service invocation.
@@ -51,40 +49,59 @@ public class EchoNonBlockingDualClient {
             options.setUseSeparateListener(true);
             options.setAction("urn:echo");  // this is the action mapping we put within the service.xml
 
-            //Callback to handle the response
-            Callback callback = new Callback() {
-                public void onComplete(AsyncResult result) {
-                    System.out.println(result.getResponseEnvelope());
-                }
-
-                public void onError(Exception e) {
-                    e.printStackTrace();
-                }
-            };
-
+            TestCallback axisCallback = new TestCallback("CallBack1") ;
+                        
             //Non-Blocking Invocation
             sender = new ServiceClient();
             sender.engageModule(Constants.MODULE_ADDRESSING);
             sender.setOptions(options);
-            sender.sendReceiveNonBlocking(payload, callback);
+            sender.sendReceiveNonBlocking(payload, axisCallback);
 
             //Wait till the callback receives the response.
-            while (!callback.isComplete()) {
-                Thread.sleep(1000);
+            while ( ! axisCallback.isComplete( ) ) {
+                Thread.sleep(100);
             }
-            //Need to close the Client Side Listener.
-
-        } catch (AxisFault axisFault) {
-            axisFault.printStackTrace();
+            
         } catch (Exception ex) {
             ex.printStackTrace();
         } finally {
             try {
                 sender.cleanup();
             } catch (AxisFault axisFault) {
-                //have to ignore this
+                axisFault.printStackTrace();
             }
+        	
+        }
+    }
+    
+    static class TestCallback implements AxisCallback {
+
+        private String name = null;
+        private boolean complete = false;
+        
+        public TestCallback (String name) {
+                this.name = name;
         }
 
+        public void onError (Exception e) {
+                e.printStackTrace();
+        }
+
+        public void onComplete() {
+        	System.out.println( "Message transmission complete") ;
+            complete = true;
+        }
+        
+        public boolean isComplete() {
+            return complete;
+        }
+        
+        public void onMessage(org.apache.axis2.context.MessageContext arg0) {
+           System.out.println( "Call Back " + name + " got Result: " + arg0.getEnvelope() ) ;
+        }
+
+        public void onFault(org.apache.axis2.context.MessageContext arg0) {
+        	System.out.println( "Call Back " + name + " got Fault: " + arg0.getEnvelope() ) ;
+        }
     }
 }