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/23 18:27:14 UTC
svn commit: r291166 - in
/webservices/muse/trunk/src/examples/client/src/java: Sample.java
Sample2.java
Author: wire
Date: Fri Sep 23 09:27:10 2005
New Revision: 291166
URL: http://svn.apache.org/viewcvs?rev=291166&view=rev
Log: (empty)
Added:
webservices/muse/trunk/src/examples/client/src/java/Sample.java
webservices/muse/trunk/src/examples/client/src/java/Sample2.java
Added: webservices/muse/trunk/src/examples/client/src/java/Sample.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/Sample.java?rev=291166&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/Sample.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/Sample.java Fri Sep 23 09:27:10 2005
@@ -0,0 +1,36 @@
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.client.muse.client.ManageableResource;
+import org.apache.ws.client.muse.client.model.SetPropertiesRequest;
+
+public class Sample {
+ QName NAME = new QName( "http://ws.apache.org/service/testresource", "Name", "tns");
+ URL eprURL;
+
+ public Sample() {
+ super();
+ try {
+ eprURL=new URL("http://localhost:8080/muse/epr/demo-epr.xml");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+ public String getNameOfResource() throws Exception{
+ URL eprURL=new URL("http://localhost:8080/muse/epr/demo-epr.xml");
+ ManageableResource managedResource = ManageableResource.Factory.create(null, eprURL);
+ String propValue=managedResource.getPropertyAsString(NAME);
+ return propValue;
+ }
+
+ public void setNameOfResource() throws Exception{
+ ManageableResource managedResource = ManageableResource.Factory.create(null, eprURL);
+ SetPropertiesRequest spr=SetPropertiesRequest.Factory.create();
+ spr.addUpdateRequest(NAME,new String[]{"New Name"});
+ managedResource.setProperties(spr);
+ }
+
+
+}
Added: webservices/muse/trunk/src/examples/client/src/java/Sample2.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/java/Sample2.java?rev=291166&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/java/Sample2.java (added)
+++ webservices/muse/trunk/src/examples/client/src/java/Sample2.java Fri Sep 23 09:27:10 2005
@@ -0,0 +1,136 @@
+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.EndpointReference;
+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.ChangeNotification;
+import org.apache.ws.client.muse.client.model.Notification;
+import org.apache.ws.client.muse.client.model.Situation;
+import org.apache.ws.client.muse.client.model.TopicExpression;
+import org.apache.xmlbeans.XmlException;
+
+public class Sample2 implements Observer {
+
+ private static final int LISTENER_TIMEOUT = 30000;
+
+ private static final int LISTERNER_PORT = 8888;
+
+ private NotificationConsumer listner;
+
+ private URL eprURL;
+
+ private ManageableResource subscription;
+
+ public Sample2() {
+ super();
+ try {
+ eprURL = new URL("http://localhost:8080/muse/epr/demo-epr.xml");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * This operation causes an HTTP listener to be created port 8888.
+ * NotificationConsumer implements the observer pattern. Anyone who wants to
+ * receive the notification must add themselves as an obverver.
+ *
+ * @throws IOException
+ */
+ public void createNotificationListener() throws IOException {
+ this.listner = NotificationConsumer.Factory.create(null,
+ LISTERNER_PORT, LISTENER_TIMEOUT);
+ this.listner.addObserver(this);
+ this.listner.start();
+ }
+
+ /**
+ * This operation causes notification to be sent back to us whenever the
+ * TestMetric value is changed.
+ *
+ * @throws MalformedURLException
+ * @throws XmlException
+ * @throws IOException
+ * @throws URISyntaxException
+ * @throws UnexpectedServerResponseException
+ * @throws FaultException
+ */
+ public void subscribe() throws MalformedURLException, XmlException,
+ IOException, URISyntaxException, UnexpectedServerResponseException,
+ FaultException {
+ ManageableResource resource = ManageableResource.Factory.create(null,
+ eprURL);
+ QName topicName = new QName(
+ "http://docs.oasis-open.org/wsdm/2004/12/muws/wsdm-muws-part2-events.xml",
+ "TestMetricMonitorChannel");
+ TopicExpression topic = TopicExpression.Factory.create(null, topicName);
+ this.subscription = resource.subscribe(topic, listner
+ .getEndpointReference());
+ }
+
+ /**
+ * It is not always clear to the developer that the Subscribe operation
+ * returns a Subscription amanged resource. Destroying this resource
+ * terminates the subscription.
+ *
+ * @throws URISyntaxException
+ * @throws IOException
+ * @throws XmlException
+ * @throws UnexpectedServerResponseException
+ * @throws FaultException
+ */
+ public void unsubscribe() throws URISyntaxException, IOException,
+ XmlException, UnexpectedServerResponseException, FaultException {
+ this.subscription.destroy();
+ }
+
+ /**
+ * When you want to stop the listener, you should first unregister yourself
+ * as an observer. Stopping the lisnter will cauase it to shut down. It may
+ * be restarted again by calling start.
+ *
+ */
+ public void destroyNotificationListener() {
+ this.listner.deleteObserver(this);
+ this.listner.stop();
+ }
+
+ /**
+ * Notification's Arrive here.
+ */
+ public void update(Observable notificationListnerObservable,
+ Object notificationObject) {
+ NotificationConsumer notificationListener = (NotificationConsumer) notificationListnerObservable;
+
+ // What Consumer sent this message?
+ EndpointReference listenerEpr = null;
+ try {
+ listenerEpr = notificationListener.getEndpointReference();
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+
+ // What is the content of the Change Notification?
+ Notification notification = (Notification) notificationObject;
+ ChangeNotification changeNotification = notification
+ .getChangeNotification();
+
+ // What is the situation?
+ Situation situation = notification.getSituation();
+
+ // What is the raw text of the notification?
+ String text = notification.getNotificationMessage().toString();
+ }
+
+}