You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by wi...@apache.org on 2005/09/28 23:26:00 UTC

svn commit: r292312 - /webservices/muse/trunk/src/examples/client/src/java/WsdmExplorer.java

Author: wire
Date: Wed Sep 28 14:25:55 2005
New Revision: 292312

URL: http://svn.apache.org/viewcvs?rev=292312&view=rev
Log:
Added listen command.

Modified:
    webservices/muse/trunk/src/examples/client/src/java/WsdmExplorer.java

Modified: webservices/muse/trunk/src/examples/client/src/java/WsdmExplorer.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/WsdmExplorer.java?rev=292312&r1=292311&r2=292312&view=diff
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/WsdmExplorer.java (original)
+++ webservices/muse/trunk/src/examples/client/src/java/WsdmExplorer.java Wed Sep 28 14:25:55 2005
@@ -12,13 +12,22 @@
  */
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.Observable;
+import java.util.Observer;
 
 import javax.xml.namespace.QName;
 
 import org.apache.ws.addressing.XmlBeansEndpointReference;
 import org.apache.ws.client.muse.client.ManageableResource;
+import org.apache.ws.client.muse.client.NotificationConsumer;
+import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
+import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.ws.client.muse.client.model.Notification;
 import org.apache.ws.client.muse.client.model.SetPropertiesRequest;
+import org.apache.ws.client.muse.client.model.TopicExpression;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
@@ -64,22 +73,28 @@
 	        }
 
 	        // 	ls Command
-		    if (args.length == 2 || args[1].equals("dump")) {
+		    if (args.length == 2 && args[1].equals("dump")) {
 		        WsdmExplorer client;
 					client = new WsdmExplorer(args[0],args);
 		            client.dump();
 		    }
-		    if (args.length == 3 || args[1].equals("get")) {
+		    if (args.length == 3 && args[1].equals("get")) {
 		        WsdmExplorer client;
 					client = new WsdmExplorer(args[0],args);
 		            client.get();
 		    }
-		    if (args.length == 4 || args[1].equals("set")) {
+		    if (args.length == 4 && args[1].equals("set")) {
 		        WsdmExplorer client;
 					client = new WsdmExplorer(args[0],args);
 		            client.set();
 		    }
 
+		    if (args.length == 3 && args[1].equals("listen")) {
+		        WsdmExplorer client;
+					client = new WsdmExplorer(args[0],args);
+		            client.listen();
+		    }
+
 		    System.exit(0);
         } catch (Exception e) {
                 System.err.println(e.getMessage());
@@ -92,7 +107,37 @@
     }
 
  
-    /**
+    private void listen() {
+    	try {
+		// params are 0=epr 1=listen 2=topic 3=Optional Port
+    	String[] parts = this.args[2].split("[}{]");
+    	QName name = new QName(parts[1],parts[2]);
+    	int port=8089;
+    	if(args.length>3)
+    		port=Integer.parseInt(args[3]);
+    	NotificationConsumer consumer = NotificationConsumer.Factory.create(null,port,0);
+    	consumer.addObserver(new Observer(){
+
+			public void update(Observable o, Object arg) {
+				Notification notification = (Notification)arg;
+				System.out.println(notification.toString());
+			}});
+    	consumer.start();
+    	System.out.println("Now listening on "+consumer.getEndpointReference().getAddress()+" to Topic "+name);
+		ManageableResource subscription=m_resource.subscribe(TopicExpression.Factory.create(null,name),consumer.getEndpointReference());
+		System.out.println("Hit any key to destroy your subscription.\n Until then all notifications received will be written here.");
+		System.in.read();		
+		subscription.destroy();
+		consumer.stop();
+    	} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} 
+		
+	}
+
+
+	/**
      * @param propName
      * @param value
      */
@@ -146,10 +191,11 @@
     	QName name = new QName(parts[1],parts[2]);
     	String setValue = this.args[3];
     	
-    	System.out.println("Requested Property "+name);
+    	System.out.println("Setting Property "+name);
     	SetPropertiesRequest spr=SetPropertiesRequest.Factory.create();
     	spr.addUpdateRequest(name,new String[]{setValue});
 		m_resource.setProperties(spr);
+		System.out.println("has been set to "+setValue);
     }
     
     public static void ShowHelpMessage() {