ws-pubscribe-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lisc...@apache.org
Subject svn commit: r158385 - in incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub: ./ Publisher.java Subscriber.java Subscription.java SubscriptionHome.java
Date Mon, 21 Mar 2005 00:34:45 GMT
Author: lischke
Date: Sun Mar 20 16:34:44 2005
New Revision: 158385

URL: http://svn.apache.org/viewcvs?view=rev&rev=158385
Log:
added client impl for pubsub API

Added:
    incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/
    incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Publisher.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscriber.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscription.java
    incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/SubscriptionHome.java

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Publisher.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Publisher.java?view=auto&rev=158385
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Publisher.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Publisher.java Sun Mar
20 16:34:44 2005
@@ -0,0 +1,41 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+
+
+package org.apache.ws.notification.pubsub;
+
+import javax.xml.soap.SOAPMessage;
+import org.apache.ws.pubsub.emitter.EmitterTask;
+
+/**
+ *
+ * @author  Stefan Lischke
+ */
+public class Publisher implements org.apache.ws.pubsub.Publisher{
+       
+    private String m_url;
+    public Publisher(String url){
+        m_url=url;
+    } 
+    
+    public void publish(Object msg, org.apache.ws.notification.topics.Topic t) {
+    }
+    
+    private void publish(SOAPMessage soapMsg) throws Exception{
+        EmitterTask et = EmitterTask.createEmitterTask(soapMsg, new java.net.URL(m_url));
+        et.run();
+    }    
+}

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscriber.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscriber.java?view=auto&rev=158385
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscriber.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscriber.java Sun
Mar 20 16:34:44 2005
@@ -0,0 +1,170 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+
+package org.apache.ws.notification.pubsub;
+
+//import org.xmlsoap.schemas.ws.x2003.x03.addressing.EEndpointReference;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.addressing.EndpointReference;
+
+import org.apache.ws.util.XmlBeanUtils;
+
+import org.apache.axis.configuration.FileProvider;
+
+import org.apache.ws.pubsub.NotificationProducer;
+import org.apache.ws.pubsub.NotificationConsumer;
+import org.apache.ws.pubsub.SubscriptionEndConsumer;
+import org.apache.ws.pubsub.XPathFilter;
+import org.apache.ws.pubsub.TopicFilter;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+
+
+
+import org.apache.ws.XmlObjectWrapper;
+import org.apache.axis.AxisProperties;
+import org.apache.axis.configuration.EngineConfigurationFactoryDefault;
+import java.util.Calendar;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.ws.util.jndi.XmlBeanJndiUtils;
+
+import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
+
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeResponseDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+
+import org.apache.ws.pubsub.wsaSOAPConnection;
+
+import org.apache.xmlbeans.XmlCursor;
+/**
+ *
+ * @author  Stefan Lischke
+ */
+public class Subscriber implements NotificationProducer{
+
+    private static final Log LOG = LogFactory.getLog( Subscriber.class.getName() );
+    
+    private EndpointReference epr;
+    private SubscriptionHome sH;
+    
+    /** Creates a new instance of Subscriber */
+    public Subscriber(String url,String configfile){
+        //Axis stuff to enable Addressing HandlerChain
+        AxisProperties.setProperty(EngineConfigurationFactoryDefault.OPTION_CLIENT_CONFIG_FILE,"/org/apache/ws/eventing/client-config.wsdd");
   
+        try{
+            //read jndi-config.xml
+            init(configfile);
+            
+            //create EPR TODO clean
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType e = org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType.Factory.newInstance();
+            org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI auri = org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI.Factory.newInstance();

+            auri.setStringValue(url);
+            e.setAddress(auri);    
+            //wrapper 
+            this.epr= new XmlBeansEndpointReference(e); 
+
+            //getlocal SubscriptionHome from jndi-config
+            Context initialContext = new InitialContext(  );
+            sH = (SubscriptionHome) initialContext.lookup( SubscriptionHome.HOME_LOCATION
);
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }      
+    }
+    
+    public Object getCurrentMessage(org.apache.ws.pubsub.Filter[] filters) {
+        return null;
+    }
+    
+    public org.apache.ws.addressing.EndpointReference getEPR() {
+        return this.epr;
+    }
+    
+    public org.apache.ws.pubsub.Subscription subscribe(NotificationConsumer notificationConsumer,
SubscriptionEndConsumer subscriptionEndConsumer, TopicFilter tf, XPathFilter xf, Calendar
initialTerminationTime, boolean UseNotify) {
+       SubscribeDocument sdom = SubscribeDocument.Factory.newInstance();         
+        SubscribeDocument.Subscribe s = sdom.addNewSubscribe(); 
+        //subscription ends are send to:
+        //TODO
+        
+        //notifications are send to:
+        s.setConsumerReference((org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType)((XmlObjectWrapper)notificationConsumer.getEPR()).getXmlObject());
+              
+        //TODO check Calendar serializing
+        s.setInitialTerminationTime(initialTerminationTime);
+        
+        //TODO multiple filters
+        if(tf!=null){
+            TopicExpressionType te = s.addNewTopicExpression();
+            XmlCursor xc = te.newCursor();
+            xc.toNextToken();
+	    xc.insertNamespace( "tns",tf.getNameSpace());
+            te.newCursor().setTextValue((String)tf.getExpression());
+            te.setDialect(tf.getURI().toString());
+        }
+        
+        //create Subscription
+        //add to local SubscriptionHome        
+        org.apache.ws.notification.pubsub.Subscription ls = this.sH.create();         
+        SubscribeResponseDocument.SubscribeResponse sresres=null;
+        try{
+            //now call 
+            wsaSOAPConnection sconn = wsaSOAPConnection.newInstance();
+            MessageFactory mf = MessageFactory.newInstance();
+            SOAPMessage soapm = mf.createMessage();
+            //put XMLbean into SOAPBody
+            soapm.getSOAPBody().addDocument((org.w3c.dom.Document) sdom.newDomNode());
+            SOAPMessage subscribeResponse = sconn.call(soapm, epr.getAddress().toString());
+            java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
+            subscribeResponse.writeTo(os);
+            EnvelopeDocument sres = EnvelopeDocument.Factory.parse(new java.io.ByteArrayInputStream(os.toByteArray()));
+
+            //extract SubscribeResponse from SOAPBody
+            /*SubscribeResponseDocument sresdom = SubscribeResponseDocument.Factory.newInstance();
+            sresres= sresdom.addNewSubscribeResponse();
+            sresres.set(sres.getEnvelope().getBody());
+             */
+            //TODO handle faults
+            SubscribeResponseDocument sresdom = SubscribeResponseDocument.Factory.parse(sres.getEnvelope().getBody().xmlText());
+            sresres= sresdom.getSubscribeResponse();
+        }catch(Exception e){
+            e.printStackTrace();
+        }    
+
+        //set SubscritpionManager
+        ls.setSubscriptionManager(sresres);
+        ls.setNotificationConsumer(notificationConsumer);
+        return ls;
+    }
+   /**
+    * runs resource discovery.
+    *
+    */
+   public void init(String configfile)
+         throws Exception
+   {
+         LOG.info(this.getClass().getName()+" : initialize with "+configfile);
+//         XmlBeanJndiUtils.initializeFromInputStream(new java.io.FileInputStream(configfile));
+         XmlBeanJndiUtils.initializeFromInputStream(Thread.currentThread().getContextClassLoader().getResourceAsStream(configfile/*XmlBeanJndiUtils.JNDI_CONFIG_FILENAME*/));
+   }    
+}

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscription.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscription.java?view=auto&rev=158385
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscription.java (added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/Subscription.java Sun
Mar 20 16:34:44 2005
@@ -0,0 +1,57 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+
+package org.apache.ws.notification.pubsub;
+import org.apache.ws.notification.base.impl.AbstractSubscription;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeResponseDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeResponseDocument.SubscribeResponse;
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.ws.util.uuid.UuidGenerator;
+import org.apache.ws.util.uuid.UuidGeneratorFactory;
+import java.util.Calendar;
+/**
+ *
+ * @author  Stefan Lischke
+ */
+public class Subscription extends AbstractSubscription{
+    private EndpointReferenceType sMan; 
+    private static final Log LOG = LogFactory.getLog( Subscriber.class.getName() );
+    
+    private static final UuidGenerator UUID_GEN = UuidGeneratorFactory.createUUIdGenerator();
+
+    
+    /** Creates a new instance of Subscription */
+    public Subscription() {
+        m_id = UUID_GEN.generateUuid();
+        m_creationTime= Calendar.getInstance();        
+    }
+
+    public void setSubscriptionManager(SubscribeResponseDocument.SubscribeResponse sresdom)
{
+        sMan = sresdom.getSubscriptionReference();
+        super.setEpr(new XmlBeansEndpointReference(sMan));
+    }
+ 
+    public void init() {
+    }
+    public void setResourcePropertySet(org.apache.ws.resource.properties.ResourcePropertySet
propSet){
+        
+    }
+}

Added: incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/SubscriptionHome.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/SubscriptionHome.java?view=auto&rev=158385
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/SubscriptionHome.java
(added)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/pubsub/SubscriptionHome.java
Sun Mar 20 16:34:44 2005
@@ -0,0 +1,53 @@
+/*=============================================================================*
+ *  Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+
+
+package org.apache.ws.notification.pubsub;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.SubscribeResponseDocument;
+
+import org.apache.ws.resource.JndiConstants;
+import org.apache.ws.resource.impl.SimpleTypeResourceKey;
+
+import javax.xml.namespace.QName;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+/**
+ *
+ * @author  Stefan Lischke
+ */
+public class SubscriptionHome extends org.apache.ws.resource.impl.AbstractResourceHome {
+    private static final String SERVICE_NAME = "NotificationPort";
+    public static final String HOME_LOCATION = JndiConstants.CONTEXT_NAME_SERVICES + "/"
+ SERVICE_NAME + "/" + JndiConstants.ATOMIC_NAME_HOME;
+
+    private static final Log LOG = LogFactory.getLog( SubscriptionHome.class.getName() );
+    
+    public Subscription create(){
+        Subscription s = new Subscription();
+        String id = (String) s.getID();
+
+        SimpleTypeResourceKey resourceKey = new SimpleTypeResourceKey( QName.valueOf( getResourceKeyName()),
id);
+        add(resourceKey,s);
+        return s;
+    }
+    
+    public org.apache.ws.resource.Resource getInstance(org.apache.ws.resource.ResourceContext
resourceContext) throws org.apache.ws.resource.ResourceException, org.apache.ws.resource.ResourceContextException,
org.apache.ws.resource.ResourceUnknownException {
+        LOG.info("getInstance SubscriptionHome");
+        return find( resourceContext.getResourceKey() );
+    }   
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: hermes-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: hermes-dev-help@ws.apache.org


Mime
View raw message