You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by pa...@apache.org on 2011/09/15 00:56:20 UTC

svn commit: r1170887 [2/3] - in /incubator/airavata/trunk/modules/ws-messenger/client: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/airavata/ src/main/java/org/apache/airavata/wsmg/ src/main/jav...

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/WsntMsgBrokerClient.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/WsntMsgBrokerClient.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/WsntMsgBrokerClient.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/WsntMsgBrokerClient.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,189 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.wsmg.client;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.wsmg.client.commons.NotificationProducer;
+import org.apache.airavata.wsmg.client.protocol.WSNTProtocolClient;
+import org.apache.airavata.wsmg.client.util.ClientUtil;
+import org.apache.airavata.wsmg.commons.CommonRoutines;
+import org.apache.airavata.wsmg.commons.WsmgCommonConstants;
+import org.apache.airavata.wsmg.commons.WsmgNameSpaceConstants;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+
+public class WsntMsgBrokerClient extends CommonMsgBrokerClient implements MessageBrokerClient {
+
+    protected long timeoutInMilliSeconds = WsmgCommonConstants.DEFAULT_CLIENT_SOCKET_TIME_OUT_MILLIES;
+
+    protected NotificationProducer notifProducer = new NotificationProducer();
+    protected ConsumerServerHandler consumerServerHandler = new ConsumerServerHandler();
+
+    private EndpointReference brokerEndpointRef = null;
+
+    public static EndpointReference createEndpointReference(String brokerURL, String topic) {
+        // TODO : implement
+        return null;
+    }
+
+    public void init(String brokerLocation) {
+        brokerEndpointRef = new EndpointReference(ClientUtil.formatURLString(brokerLocation));
+
+    }
+
+    public void publish(String topic, String plainText) throws MsgBrokerClientException {
+
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+
+        OMElement wrappedMsg = factory.createOMElement(WsmgCommonConstants.WSMG_PLAIN_TEXT_WRAPPER,
+                WsmgNameSpaceConstants.WSMG_NS);
+
+        wrappedMsg.setText(plainText);
+        publish(topic, wrappedMsg);
+
+    }
+
+    public void publish(String topic, OMElement message) throws MsgBrokerClientException {
+
+        String producerURl = ClientUtil.formatURLString(ClientUtil.getHostIP());
+        EndpointReference producerReference = new EndpointReference(producerURl);
+
+        try {
+
+            OMElement messageToNotify = WSNTProtocolClient.encodeNotification(topic, message, producerReference);
+
+            notifProducer.deliverMessage(messageToNotify, "wsnt", brokerEndpointRef, getTimeoutInMilliSeconds());
+        } catch (AxisFault e) {
+            throw new MsgBrokerClientException("unable to publish msg", e);
+        }
+
+    }
+
+    public String subscribe(String eventSinkLocation, String topicExpression, String xpathExpression)
+            throws MsgBrokerClientException {
+
+        return subscribe(new EndpointReference(eventSinkLocation), topicExpression, xpathExpression);
+    }
+
+    public String subscribe(EndpointReference eventSinkLocation, String topicExpression, String xpathExpression)
+            throws MsgBrokerClientException {
+        return subscribe(eventSinkLocation, topicExpression, xpathExpression,
+                WsmgCommonConstants.DEFAULT_SUBSCRIPTION_EXPIRATION_TIME);
+    }
+
+    public String subscribe(EndpointReference eventSinkLocation, String topicExpression, String xpathExpression,
+            long expireTime) throws MsgBrokerClientException {
+
+        String subscriptionId = null;
+
+        try {
+
+            OMElement message = WSNTProtocolClient.createSubscriptionMsg(eventSinkLocation, topicExpression,
+                    xpathExpression);
+
+            ServiceClient client = createServiceClient(message);
+
+            OMElement responseMessage = client.sendReceive(message);
+            client.cleanupTransport();
+
+            OMElement sr = responseMessage.getFirstChildWithName(new QName(WsmgNameSpaceConstants.WSNT_NS
+                    .getNamespaceURI(), "SubscriptionReference"));
+
+            if (sr == null) {
+                throw new MsgBrokerClientException("unable to subscribe, invalid response returned by broker");
+            }
+
+            subscriptionId = WSNTProtocolClient.decodeSubscriptionResponse(sr);
+
+        } catch (AxisFault f) {
+            throw new MsgBrokerClientException("unable to send the subscription msg", f);
+        }
+
+        return subscriptionId;
+
+    }
+
+    private ServiceClient createServiceClient(OMElement message) throws AxisFault {
+
+        String soapAction = message.getNamespace().getNamespaceURI() + "/" + message.getLocalName();
+
+        Options opts = CommonRoutines.getOptions(soapAction, getTimeoutInMilliSeconds(), brokerEndpointRef);
+
+        ServiceClient client = new ServiceClient();
+        CommonRoutines.setHeaders(soapAction, brokerEndpointRef.getAddress(), client);
+
+        client.setOptions(opts);
+
+        return client;
+    }
+
+    public boolean unSubscribe(String subscriptionId) throws MsgBrokerClientException {
+
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        OMElement message = WSNTProtocolClient.createUnsubscribeMsg();
+        OMElement identifierEl = factory.createOMElement("Identifier", message.getNamespace());
+
+        identifierEl.setText(subscriptionId);
+        String soapAction = message.getNamespace().getNamespaceURI() + "/" + message.getLocalName();
+
+        Options opts = CommonRoutines.getOptions(soapAction, getTimeoutInMilliSeconds(), brokerEndpointRef);
+
+        try {
+            ServiceClient client = new ServiceClient();
+            client.setOptions(opts);
+            CommonRoutines.setHeaders(soapAction, brokerEndpointRef.getAddress(), client, identifierEl);
+
+            client.sendReceive(message);
+            client.cleanupTransport();
+
+        } catch (AxisFault e) {
+            throw new MsgBrokerClientException("unable to send subscribe msg", e);
+        }
+
+        return true;
+    }
+
+    public long getTimeoutInMilliSeconds() {
+        return timeoutInMilliSeconds;
+    }
+
+    public void setTimeoutInMilliSeconds(long timeout) {
+        timeoutInMilliSeconds = timeout;
+    }
+
+    public String[] startConsumerService(int port, ConsumerNotificationHandler handler) throws MsgBrokerClientException {
+
+        consumerServerHandler.createConsumerServer(port, handler);
+        return consumerServerHandler.getConsumerServiceEndpointReference();
+
+    }
+
+    public void shutdownConsumerService() {
+        consumerServerHandler.shutdownConsumerService();
+    }
+}

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/WsrfResourceStub.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/WsrfResourceStub.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/WsrfResourceStub.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/WsrfResourceStub.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,378 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.wsmg.client;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.wsmg.client.util.DcDate;
+import org.apache.airavata.wsmg.commons.WsmgCommonConstants;
+import org.apache.airavata.wsmg.commons.WsmgNameSpaceConstants;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code
+ * Templates
+ */
+public class WsrfResourceStub {
+    private final static Logger logger = LoggerFactory.getLogger(WsrfResourceStub.class);
+    private final static OMFactory factory = OMAbstractFactory.getOMFactory();
+    private final static SOAPFactory soapfactory = OMAbstractFactory.getSOAP11Factory();
+    protected Options opts;
+
+    private EndpointReference resourceEndpointReference;
+
+    private long timeoutInMilliSeconds;
+
+    protected WsrfResourceStub(EndpointReference resourceEpr, long timeout) {
+        this.resourceEndpointReference = resourceEpr;
+        logger.info("resourceEprInWsrfResourceStub Constructor" + resourceEpr.toString());
+
+        timeoutInMilliSeconds = timeout;
+
+        opts = new Options();
+        opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
+        opts.setTo(resourceEpr);
+        opts.setTimeOutInMilliSeconds(timeout);
+
+    }
+
+    public EndpointReference getResourceEpr() {
+        return resourceEndpointReference;
+    }
+
+    public long getTimeoutInMilliSeconds() {
+        return timeoutInMilliSeconds;
+    }
+
+    public void setTimeoutInMilliSeconds(long timeout) {
+        timeoutInMilliSeconds = timeout;
+    }
+
+    public void destroy() throws AxisFault {
+        String uuid = UUIDGenerator.getUUID();
+        opts.setMessageId(uuid);
+        OMElement message = factory.createOMElement("Destroy", WsmgNameSpaceConstants.WSRL_NS);
+        opts.setAction(message.getNamespace().getNamespaceURI() + "/" + message.getLocalName());
+        opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+
+        ServiceClient client = new ServiceClient();
+
+        if (client.getAxisConfiguration().getModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING) != null) {
+
+            client.engageModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+        } else {
+            SOAPHeaderBlock msgId = soapfactory.createSOAPHeaderBlock("MessageID", WsmgNameSpaceConstants.WSA_NS);
+            msgId.setText(uuid);
+
+            SOAPHeaderBlock to = soapfactory.createSOAPHeaderBlock("To", WsmgNameSpaceConstants.WSA_NS);
+            to.setText(this.resourceEndpointReference.getAddress());
+
+            SOAPHeaderBlock action = soapfactory.createSOAPHeaderBlock("Action", WsmgNameSpaceConstants.WSA_NS);
+            action.setText(message.getNamespace().getNamespaceURI() + "/" + message.getLocalName());
+
+            client.addHeader(action);
+            client.addHeader(msgId);
+            client.addHeader(to);
+        }
+        client.setOptions(opts);
+
+        client.sendRobust(message);
+    }
+
+    public void setTerminationTime(Calendar cal) throws AxisFault {
+        String uuid = UUIDGenerator.getUUID();
+        opts.setMessageId(uuid);
+        OMElement message = factory.createOMElement("SetTerminationTime", WsmgNameSpaceConstants.WSRL_NS);
+        opts.setAction(message.getNamespace().getNamespaceURI() + "/" + message.getLocalName());
+
+        opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+
+        OMElement child = factory.createOMElement("RequestedTerminationTime", message.getNamespace(), message);
+
+        if (cal == null) {
+            OMNamespace XSI_NS = factory.createOMNamespace("http://www.w3.org/2001/XMLSchema", "xsd");
+            child.addAttribute("nill", "true", XSI_NS);
+            // (XmlConstants.XSI_NS, "nil", "true");
+        } else {
+
+            DcDate dcDate = new DcDate(cal);
+            child.setText(dcDate.toString());
+        }
+
+        ServiceClient client = new ServiceClient();
+
+        if (client.getAxisConfiguration().getModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING) != null) {
+            client.engageModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+        } else {
+            SOAPHeaderBlock msgId = soapfactory.createSOAPHeaderBlock("MessageID", WsmgNameSpaceConstants.WSA_NS);
+            msgId.setText(uuid);
+
+            SOAPHeaderBlock to = soapfactory.createSOAPHeaderBlock("To", WsmgNameSpaceConstants.WSA_NS);
+            to.setText(this.resourceEndpointReference.getAddress());
+
+            SOAPHeaderBlock action = soapfactory.createSOAPHeaderBlock("Action", WsmgNameSpaceConstants.WSA_NS);
+            action.setText(message.getNamespace().getNamespaceURI() + "/" + message.getLocalName());
+
+            client.addHeader(action);
+            client.addHeader(msgId);
+            client.addHeader(to);
+        }
+        client.setOptions(opts);
+        client.sendRobust(message);
+
+    }
+
+    public List<OMElement> getResourceProperty(QName qn) throws AxisFault { // List<XmlElement>
+
+        OMElement messageEl = factory.createOMElement("GetResourceProperty", WsmgNameSpaceConstants.WSRP_NS);
+        String uuid = UUIDGenerator.getUUID();
+
+        opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+        opts.setMessageId(uuid);
+        opts.setAction(messageEl.getNamespace().getNamespaceURI() + "/" + messageEl.getLocalName());
+
+        QName textQName = new QName(qn.getNamespaceURI(), qn.getLocalPart(), qn.getPrefix());
+
+        factory.createOMText(messageEl, textQName);
+
+        if (qn.getPrefix() != null) {
+            OMNamespace ns = factory.createOMNamespace(qn.getNamespaceURI(), qn.getPrefix());
+            messageEl.declareNamespace(ns);
+        }
+
+        ServiceClient client = new ServiceClient();
+
+        if (client.getAxisConfiguration().getModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING) != null) {
+
+            client.engageModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+        } else {
+
+            SOAPHeaderBlock msgId = soapfactory.createSOAPHeaderBlock("MessageID", WsmgNameSpaceConstants.WSA_NS);
+            msgId.setText(uuid);
+
+            SOAPHeaderBlock to = soapfactory.createSOAPHeaderBlock("To", WsmgNameSpaceConstants.WSA_NS);
+            to.setText(this.resourceEndpointReference.getAddress());
+
+            SOAPHeaderBlock action = soapfactory.createSOAPHeaderBlock("Action", WsmgNameSpaceConstants.WSA_NS);
+            action.setText(messageEl.getNamespace().getNamespaceURI() + "/" + messageEl.getLocalName());
+
+            client.addHeader(action);
+            client.addHeader(msgId);
+            client.addHeader(to);
+        }
+        client.setOptions(opts);
+        OMElement responseMessage = client.sendReceive(messageEl);
+        client.cleanupTransport();
+
+        List<OMElement> list = elementsAsList(responseMessage);
+        return list;
+    }
+
+    public List<OMElement> getMultipleResourceProperties(QName[] qnamez) throws AxisFault { // TODO
+
+        OMElement messageEl = factory.createOMElement("GetMultipleResourceProperties", WsmgNameSpaceConstants.WSRP_NS);
+        String uuid = UUIDGenerator.getUUID();
+        opts.setMessageId(uuid);
+        opts.setAction(messageEl.getNamespace().getNamespaceURI() + "/" + messageEl.getLocalName());
+        opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+
+        // message.addChild(new QNameElText(message, WidgetService.WIDGET_NS,
+        // "TerminationTime"));
+        // message.declareNamespace(WidgetService.WIDGET_NS);
+        // wsrp:ResourceProperty
+
+        for (QName qn : qnamez) {
+
+            OMNamespace ns = factory.createOMNamespace(qn.getNamespaceURI(), qn.getPrefix());
+
+            OMElement child = factory.createOMElement("ResourceProperty", WsmgNameSpaceConstants.WSRP_NS);
+
+            QName textQName = new QName(qn.getNamespaceURI(), qn.getLocalPart(), qn.getPrefix());
+
+            factory.createOMText(child, textQName);
+
+            if (qn.getPrefix() != null) {
+                messageEl.declareNamespace(ns);
+            }
+
+        }
+
+        ServiceClient client = new ServiceClient();
+
+        if (client.getAxisConfiguration().getModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING) != null) {
+
+            client.engageModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+        } else {
+            SOAPHeaderBlock msgId = soapfactory.createSOAPHeaderBlock("MessageID", WsmgNameSpaceConstants.WSA_NS);
+            msgId.setText(uuid);
+
+            SOAPHeaderBlock to = soapfactory.createSOAPHeaderBlock("To", WsmgNameSpaceConstants.WSA_NS);
+            to.setText(this.resourceEndpointReference.getAddress());
+
+            SOAPHeaderBlock action = soapfactory.createSOAPHeaderBlock("Action", WsmgNameSpaceConstants.WSA_NS);
+            action.setText(messageEl.getNamespace().getNamespaceURI() + "/" + messageEl.getLocalName());
+
+            client.addHeader(action);
+            client.addHeader(msgId);
+            client.addHeader(to);
+        }
+        client.setOptions(opts);
+        OMElement responseMessage = client.sendReceive(messageEl);
+        client.cleanupTransport();
+
+        List<OMElement> list = elementsAsList(responseMessage);
+        return list;
+    }
+
+    public List<OMNode> queryResourcePropertiesByXpath(String query) throws AxisFault {
+        if (query == null) {
+            throw new IllegalArgumentException();
+        }
+        String uuid = UUIDGenerator.getUUID();
+        opts.setMessageId(uuid);
+        opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+        OMElement messageEl = factory.createOMElement("QueryResourceProperties", WsmgNameSpaceConstants.WSRP_NS);
+
+        opts.setAction(messageEl.getNamespace().getNamespaceURI() + "/" + messageEl.getLocalName());
+
+        OMElement queryExpressionEl = factory.createOMElement("QueryExpression", WsmgNameSpaceConstants.WSRP_NS);
+
+        queryExpressionEl.addAttribute("dialect", WsmgCommonConstants.XPATH_DIALECT, null);
+
+        queryExpressionEl.setText(query);
+
+        ServiceClient client = new ServiceClient();
+
+        if (client.getAxisConfiguration().getModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING) != null) {
+            client.engageModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+        } else {
+
+            SOAPHeaderBlock msgId = soapfactory.createSOAPHeaderBlock("MessageID", WsmgNameSpaceConstants.WSA_NS);
+            msgId.setText(uuid);
+
+            SOAPHeaderBlock to = soapfactory.createSOAPHeaderBlock("To", WsmgNameSpaceConstants.WSA_NS);
+            to.setText(this.resourceEndpointReference.getAddress());
+
+            SOAPHeaderBlock action = soapfactory.createSOAPHeaderBlock("Action", WsmgNameSpaceConstants.WSA_NS);
+            action.setText(messageEl.getNamespace().getNamespaceURI() + "/" + messageEl.getLocalName());
+
+            client.addHeader(action);
+            client.addHeader(msgId);
+            client.addHeader(to);
+        }
+        client.setOptions(opts);
+        OMElement responseMessage = client.sendReceive(messageEl);
+        client.cleanupTransport();
+        List<OMNode> list = childrenAsList(responseMessage);
+        return list;
+    }
+
+    public void setResourceProperties(OMElement[] requests) throws AxisFault {
+        if (requests.length == 0) {
+            throw new IllegalArgumentException("at least one request is required");
+        }
+
+        OMElement messageEl = factory.createOMElement("SetResourceProperties", WsmgNameSpaceConstants.WSRP_NS);
+
+        String uuid = UUIDGenerator.getUUID();
+        opts.setMessageId(uuid);
+        opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+        opts.setAction(messageEl.getNamespace().getNamespaceURI() + "/" + messageEl.getLocalName());
+
+        for (int i = 0; i < requests.length; i++) {
+            messageEl.addChild(requests[i]);
+        }
+        // message.addChild(new QNameElText(message, WidgetService.WIDGET_NS,
+        // "TerminationTime"));
+        // message.declareNamespace(WidgetService.WIDGET_NS);
+        // wsrp:ResourceProperty
+        // message.declareNamespace(WidgetService.WSRL_NS);
+
+        ServiceClient client = new ServiceClient();
+
+        if (client.getAxisConfiguration().getModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING) != null) {
+
+            client.engageModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+        } else {
+            SOAPHeaderBlock msgId = soapfactory.createSOAPHeaderBlock("MessageID", WsmgNameSpaceConstants.WSA_NS);
+            msgId.setText(uuid);
+
+            SOAPHeaderBlock to = soapfactory.createSOAPHeaderBlock("To", WsmgNameSpaceConstants.WSA_NS);
+            to.setText(this.resourceEndpointReference.getAddress());
+
+            SOAPHeaderBlock action = soapfactory.createSOAPHeaderBlock("Action", WsmgNameSpaceConstants.WSA_NS);
+            action.setText(messageEl.getNamespace().getNamespaceURI() + "/" + messageEl.getLocalName());
+
+            client.addHeader(action);
+            client.addHeader(msgId);
+            client.addHeader(to);
+        }
+        client.setOptions(opts);
+        client.sendRobust(messageEl);
+
+    }
+
+    private List<OMElement> elementsAsList(OMElement responseMessage) {
+        List<OMElement> list = new ArrayList<OMElement>();
+
+        for (Iterator it = responseMessage.getChildElements(); it.hasNext();) {
+            OMElement current = (OMElement) it.next();
+            list.add(current);
+        }
+
+        return list;
+    }
+
+    private List<OMNode> childrenAsList(OMElement responseMessage) {
+        List<OMNode> list = new ArrayList<OMNode>();
+
+        for (Iterator it = responseMessage.getChildren(); it.hasNext();) {
+            OMNode child = (OMNode) it.next();
+            list.add(child);
+        }
+        return list;
+    }
+
+    public static void verbose(String msg) {
+        System.err.println(msg);
+
+    }
+}

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/commons/NotificationProducer.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/commons/NotificationProducer.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/commons/NotificationProducer.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/commons/NotificationProducer.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,119 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.wsmg.client.commons;
+
+import org.apache.airavata.wsmg.commons.WsmgCommonConstants;
+import org.apache.airavata.wsmg.commons.WsmgNameSpaceConstants;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+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.airavata.wsmg.WsmgConstants;
+
+//import org.apache.airavata.wsmg.WsmgConstants;
+
+public class NotificationProducer {
+
+    private final OMFactory factory = OMAbstractFactory.getOMFactory();
+    private final SOAPFactory soapfactory = OMAbstractFactory.getSOAP11Factory();
+
+    public NotificationProducer() {
+
+    }
+
+    public synchronized OMElement deliverMessage(OMElement notificationMessage, String type,
+            EndpointReference brokerLocationEPR, long timeout) throws AxisFault {
+
+        ServiceClient client = createServiceClient(type, notificationMessage, brokerLocationEPR, timeout, null);
+
+        OMElement ret = client.sendReceive(notificationMessage);
+        client.cleanupTransport();
+        return ret;
+
+    }
+
+    public synchronized OMElement deliverMessage(OMElement notificationMessage, String type,
+            EndpointReference brokerLocationEPR, long timeout, OMElement topicExpressionEl) throws AxisFault {
+
+        ServiceClient client = createServiceClient(type, notificationMessage, brokerLocationEPR, timeout,
+                topicExpressionEl);
+
+        OMElement ret = client.sendReceive(notificationMessage);
+        client.cleanupTransport();
+        return ret;
+
+    }
+
+    private ServiceClient createServiceClient(String type, OMElement notificationMessage,
+            EndpointReference brokerLocationEPR, long timeout, OMElement topicExpressionEl) throws AxisFault {
+
+        ServiceClient client = new ServiceClient();
+
+        if (client.getAxisConfiguration().getModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING) != null) {
+            brokerLocationEPR.addReferenceParameter(topicExpressionEl);
+            client.engageModule(WsmgCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+        } else {
+            SOAPHeaderBlock msgId = soapfactory.createSOAPHeaderBlock("MessageID", WsmgNameSpaceConstants.WSA_NS);
+            msgId.setText(UUIDGenerator.getUUID());
+
+            SOAPHeaderBlock to = soapfactory.createSOAPHeaderBlock("To", WsmgNameSpaceConstants.WSA_NS);
+            to.setText(brokerLocationEPR.getAddress());
+
+            SOAPHeaderBlock action = soapfactory.createSOAPHeaderBlock("Action", WsmgNameSpaceConstants.WSA_NS);
+            action.setText("wsnt".equals(type) ? WsmgNameSpaceConstants.WSNT_NS.getNamespaceURI() + "/Notify"
+                    : WsmgCommonConstants.WSMG_PUBLISH_SOAP_ACTION);
+            if (topicExpressionEl != null) {
+                try {
+                    client.addHeader(org.apache.axiom.om.util.ElementHelper.toSOAPHeaderBlock(topicExpressionEl,
+                            soapfactory));
+                } catch (Exception e) {
+                    throw AxisFault.makeFault(e);
+                }
+            }
+            client.addHeader(action);
+            client.addHeader(msgId);
+            client.addHeader(to);
+
+        }
+
+        Options opts = new Options();
+
+        opts.setAction("wsnt".equals(type) ? WsmgNameSpaceConstants.WSNT_NS.getNamespaceURI() + "/Notify"
+                : WsmgCommonConstants.WSMG_PUBLISH_SOAP_ACTION);
+
+        opts.setTo(brokerLocationEPR);
+        opts.setTimeOutInMilliSeconds(timeout);
+
+        client.setOptions(opts);
+
+        return client;
+
+    }
+
+}

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/msgbox/MessagePuller.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/msgbox/MessagePuller.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/msgbox/MessagePuller.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/msgbox/MessagePuller.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,124 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.wsmg.client.msgbox;
+
+import java.util.Iterator;
+
+import org.apache.airavata.wsmg.client.NotificationHandler;
+import org.apache.airavata.wsmg.msgbox.client.MsgBoxClient;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.addressing.EndpointReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MessagePuller {
+
+    private final static Logger logger = LoggerFactory.getLogger(MessagePuller.class);
+
+    MsgBoxClient msgBoxUser = null;
+
+    EndpointReference msgBoxId = null;
+
+    NotificationHandler handler = null;
+
+    long backoff = 1000;
+
+    long unavailableInterval = 300000;
+
+    long timeout = 1000L;
+
+    boolean stopPulling = false;
+
+    public MessagePuller() {
+    }
+
+    public MessagePuller(MsgBoxClient msgBoxUser, EndpointReference msgBoxAddr, NotificationHandler handler,
+            long backoff, long timeout) {
+        this.msgBoxUser = msgBoxUser;
+        this.msgBoxId = msgBoxAddr;
+        this.handler = handler;
+        this.backoff = backoff;
+        this.timeout = timeout;
+    }
+
+    public MessagePuller(MsgBoxClient msgBoxUser, EndpointReference msgBoxId, NotificationHandler handler) {
+        this(msgBoxUser, msgBoxId, handler, 1000, 500);
+    }
+
+    public void startPulling() {
+        Puller puller = new Puller();
+        new Thread(puller).start();
+    }
+
+    public void stopPulling() {
+        stopPulling = true;
+    }
+
+    protected class Puller implements Runnable {
+
+        public void run() {
+
+            long backofftime = backoff;
+            while (!stopPulling) {
+                Iterator<OMElement> messages = null;
+                try {
+
+                    messages = msgBoxUser.takeMessagesFromMsgBox(msgBoxId, timeout);
+
+                    try {
+                        if (messages == null || (!messages.hasNext())) {
+                            // sleep only when nothing was found
+                            Thread.sleep(backoff);
+                        }
+                    } catch (InterruptedException ex) {
+                        logger.error("the message puller thread was interruped", ex);
+                    }
+
+                    if (messages != null && messages.hasNext()) {
+                        backofftime = backoff;
+                        while (messages.hasNext()) {
+                            String notification = messages.next().toStringWithConsume();
+                            try {
+                                handler.handleNotification(notification);
+                            } catch (Throwable e) {
+                                logger.info("Error occured in the user callback for message" + notification
+                                        + e.toString());
+                            }
+
+                        }
+                    }
+                } catch (Exception e) {
+                    logger.error("exception on MessagePuller", e);
+                    try {
+                        backofftime = backofftime * 2;
+                        Thread.sleep(Math.min(backofftime, unavailableInterval));
+                        backofftime = Math.min(backofftime, unavailableInterval);
+                    } catch (InterruptedException e1) {
+                        logger.error("message puller was interruped while sleeping", e1);
+                    }
+                }
+            }
+            return;
+        }
+    }
+
+}

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/msgbox/MsgboxHandler.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/msgbox/MsgboxHandler.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/msgbox/MsgboxHandler.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/msgbox/MsgboxHandler.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,121 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.wsmg.client.msgbox;
+
+import java.rmi.RemoteException;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.wsmg.client.MsgBrokerClientException;
+import org.apache.airavata.wsmg.client.NotificationHandler;
+import org.apache.airavata.wsmg.msgbox.client.MsgBoxClient;
+import org.apache.axis2.addressing.EndpointReference;
+
+public class MsgboxHandler {
+
+    protected MsgBoxClient msgBoxUser = null;
+
+    public EndpointReference createPullMsgBox(String msgBoxLocation, long timeout) throws MsgBrokerClientException {
+        msgBoxUser = new MsgBoxClient();
+        EndpointReference msgBoxAddr = null;
+
+        try {
+            msgBoxAddr = msgBoxUser.createMessageBox(msgBoxLocation, timeout);
+        } catch (RemoteException e) {
+            throw new MsgBrokerClientException("unable to create msgbox", e);
+        }
+
+        return msgBoxAddr;
+    }
+
+    public EndpointReference createPullMsgBox(String msgBoxServerLoc) throws MsgBrokerClientException {
+        return createPullMsgBox(msgBoxServerLoc, 500L);
+    }
+
+    public MessagePuller startPullingEventsFromMsgBox(EndpointReference msgBoxEpr, NotificationHandler handler,
+            long interval, long timeout) throws MsgBrokerClientException {
+        if (msgBoxUser == null) {
+            throw new MsgBrokerClientException("Unable start pulling, the messagebox client was not initialized");
+        }
+
+        MessagePuller messagePuller = new MessagePuller(msgBoxUser, msgBoxEpr, handler, interval, timeout);
+        messagePuller.startPulling();
+        return messagePuller;
+    }
+
+    public MessagePuller startPullingFromExistingMsgBox(EndpointReference msgBoxAddr, NotificationHandler handler,
+            long interval, long timeout) throws MsgBrokerClientException {
+
+        String toAddress = msgBoxAddr.getAddress();
+        int biginIndex = toAddress.indexOf("clientid");
+        String clientId = toAddress.substring(biginIndex + "clientid".length() + 1);
+
+        if ((msgBoxAddr.getAllReferenceParameters() == null || msgBoxAddr.getAllReferenceParameters()
+                .get(new QName("http://org.apache.airavata/xgws/msgbox/2004/", "MsgBoxAddr")).getText() == null)
+                && biginIndex == -1)
+            throw new MsgBrokerClientException("Invalid Message Box Address");
+        this.msgBoxUser = new MsgBoxClient();
+        MessagePuller messagePuller = new MessagePuller(msgBoxUser, msgBoxAddr, handler, interval, timeout);
+        messagePuller.startPulling();
+        return messagePuller;
+    }
+
+    public String deleteMsgBox(EndpointReference msgBoxEpr, long timeout) throws MsgBrokerClientException {
+
+        String msgBoxEventSink = msgBoxEpr.getAddress();
+
+        String formattedEventSink = null;
+
+        if (msgBoxEpr.getAddress().contains("clientid")) {
+            formattedEventSink = msgBoxEventSink;
+        } else {
+            if (msgBoxEpr.getAllReferenceParameters() == null)
+                throw new MsgBrokerClientException("Invalid Message Box EPR, no reference parameters found");
+            String msgBoxId = msgBoxEpr.getAllReferenceParameters()
+                    .get(new QName("http://org.apache.airavata/xgws/msgbox/2004/", "MsgBoxAddr")).getText();
+            if (msgBoxId == null)
+                throw new MsgBrokerClientException("Invalid Message Box EPR, reference parameter MsgBoxAddr is missing");
+            String format = msgBoxEventSink.endsWith("/") ? "%sclientid/%s" : "%s/clientid/%s";
+
+            formattedEventSink = String.format(format, msgBoxEventSink, msgBoxId);
+
+        }
+
+        if (this.msgBoxUser == null) {
+            this.msgBoxUser = new MsgBoxClient();
+        }
+
+        String resp = null;
+        try {
+            resp = msgBoxUser.deleteMsgBox(msgBoxEpr, timeout);
+        } catch (RemoteException e) {
+            throw new MsgBrokerClientException("unable to delete the msg box", e);
+        }
+
+        return resp;
+    }
+
+    public void stopPullingEventsFromMsgBox(MessagePuller msgPuller) {
+        msgPuller.stopPulling();
+    }
+
+}

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/protocol/WSEProtocolClient.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/protocol/WSEProtocolClient.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/protocol/WSEProtocolClient.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/protocol/WSEProtocolClient.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,125 @@
+package org.apache.airavata.wsmg.client.protocol;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.wsmg.commons.WsmgCommonConstants;
+import org.apache.airavata.wsmg.commons.WsmgNameSpaceConstants;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.EndpointReferenceHelper;
+
+public class WSEProtocolClient {
+
+    public static EndpointReference createEndpointReference(String brokerURL, String topic) {
+        if (brokerURL == null) {
+            throw new IllegalArgumentException("Broker URL is null.");
+        }
+        if (topic == null) {
+            throw new IllegalArgumentException("Topic is null.");
+        }
+
+        String sinkLocation = brokerURL.endsWith("/") ? brokerURL + "topic/" + topic : brokerURL + "/topic/" + topic;
+
+        EndpointReference eventSinkReference = new EndpointReference(sinkLocation);
+        return eventSinkReference;
+    }
+
+    private static OMElement createFilter(String topicExpression, String xpathExpression) {
+
+        boolean hasTopicExpression = (topicExpression != null && topicExpression.length() != 0);
+        boolean hasXPathExpression = (xpathExpression != null && xpathExpression.length() != 0);
+
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        OMElement filterEl = null;
+
+        if (hasTopicExpression && hasXPathExpression) {
+            filterEl = factory.createOMElement("Filter", WsmgNameSpaceConstants.WSE_NS);
+
+            filterEl.addAttribute("Dialect", WsmgCommonConstants.TOPIC_AND_XPATH_DIALECT, null);
+            OMElement topicExpressionEl = factory.createOMElement("TopicExpression", WsmgNameSpaceConstants.WSNT_NS);
+            topicExpressionEl.addAttribute("Dialect", WsmgCommonConstants.TOPIC_EXPRESSION_SIMPLE_DIALECT, null);
+            topicExpressionEl.declareNamespace(WsmgNameSpaceConstants.WIDGET_NS);
+            topicExpressionEl.setText(WsmgNameSpaceConstants.WIDGET_NS.getPrefix() + ":" + topicExpression);
+            filterEl.addChild(topicExpressionEl);
+            OMElement xpathEl = factory.createOMElement("MessageContent", WsmgNameSpaceConstants.WSNT_NS);
+            xpathEl.addAttribute("Dialect", WsmgCommonConstants.XPATH_DIALECT, null);
+            xpathEl.setText(xpathExpression);
+            filterEl.addChild(xpathEl);
+        } else if (hasTopicExpression) {
+            filterEl = factory.createOMElement("Filter", WsmgNameSpaceConstants.WSE_NS);
+
+            filterEl.addAttribute("Dialect", WsmgCommonConstants.TOPIC_EXPRESSION_SIMPLE_DIALECT, null);
+            filterEl.declareNamespace(WsmgNameSpaceConstants.WIDGET_NS);
+            filterEl.setText(WsmgNameSpaceConstants.WIDGET_NS.getPrefix() + ":" + topicExpression);
+        } else if (hasXPathExpression) {
+            filterEl = factory.createOMElement("Filter", WsmgNameSpaceConstants.WSE_NS);
+
+            filterEl.addAttribute("Dialect", WsmgCommonConstants.XPATH_DIALECT, null);
+            filterEl.setText(xpathExpression);
+        }
+
+        return filterEl;
+    }
+
+    public static OMElement createSubscription(EndpointReference eventSink, String topicExpression,
+            String xpathExpression, long expireTime) throws AxisFault {
+
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        OMElement subscribeMsg = factory.createOMElement("Subscribe", WsmgNameSpaceConstants.WSE_NS);
+
+        OMElement delivery = factory.createOMElement("Delivery", WsmgNameSpaceConstants.WSE_NS);
+
+        OMElement expires = factory.createOMElement("Expires", WsmgNameSpaceConstants.WSE_NS);
+        expires.setText(Long.toString(expireTime));
+        subscribeMsg.addChild(expires);
+
+        OMElement notifyTo = EndpointReferenceHelper.toOM(factory, eventSink,
+                new QName(WsmgNameSpaceConstants.WSE_NS.getNamespaceURI(), "NotifyTo"),
+                WsmgNameSpaceConstants.WSA_NS.getNamespaceURI());
+
+        delivery.addChild(notifyTo);
+        subscribeMsg.addChild(delivery);
+
+        OMElement filterEl = createFilter(topicExpression, xpathExpression);
+
+        if (filterEl != null) {
+            subscribeMsg.addChild(filterEl);
+        }
+
+        subscribeMsg.declareNamespace(WsmgNameSpaceConstants.WSA_NS);
+
+        return subscribeMsg;
+    }
+
+    public static String decodeSubscribeResponse(OMElement responseSubscriptionsManagerElement) throws AxisFault {
+        String subscriptionId = null;
+        OMElement referencePropertiesEl = responseSubscriptionsManagerElement.getFirstChildWithName(new QName(
+                WsmgNameSpaceConstants.WSA_NS.getNamespaceURI(), "ReferenceProperties"));
+
+        if (referencePropertiesEl == null) {
+            referencePropertiesEl = responseSubscriptionsManagerElement.getFirstChildWithName(new QName(
+                    WsmgNameSpaceConstants.WSA_NS.getNamespaceURI(), "ReferenceParameters"));
+        }
+
+        OMElement identifierEl = referencePropertiesEl.getFirstChildWithName(new QName(WsmgNameSpaceConstants.WSE_NS
+                .getNamespaceURI(), WsmgCommonConstants.SUBSCRIPTION_ID));
+
+        if (identifierEl == null) {
+            throw new AxisFault("invalid response message, subscription id was not sent by broker");
+        }
+
+        subscriptionId = identifierEl.getText();
+        return subscriptionId;
+    }
+
+    public static OMElement createUnsubscribeMsg() {
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        OMElement message = factory.createOMElement("Unsubscribe", WsmgNameSpaceConstants.WSE_NS);
+
+        return message;
+    }
+
+}
\ No newline at end of file

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/protocol/WSNTProtocolClient.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/protocol/WSNTProtocolClient.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/protocol/WSNTProtocolClient.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/protocol/WSNTProtocolClient.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,108 @@
+package org.apache.airavata.wsmg.client.protocol;
+
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.wsmg.commons.WsmgCommonConstants;
+import org.apache.airavata.wsmg.commons.WsmgNameSpaceConstants;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.EndpointReferenceHelper;
+
+public class WSNTProtocolClient {
+
+        public static OMElement createSubscriptionMsg(EndpointReference eventSinkLocation, String topicExpression,
+                String xpathExpression) throws AxisFault {
+            OMFactory factory = OMAbstractFactory.getOMFactory();
+
+            OMElement message = factory.createOMElement("SubscribeRequest", WsmgNameSpaceConstants.WSNT_NS);
+
+            if (topicExpression != null) {
+                OMElement topicExpEl = factory.createOMElement("TopicExpression", WsmgNameSpaceConstants.WSNT_NS,
+                        message);
+
+                topicExpEl.addAttribute("Dialect", WsmgCommonConstants.TOPIC_EXPRESSION_SIMPLE_DIALECT,
+                        WsmgNameSpaceConstants.WSNT_NS);
+                topicExpEl.declareNamespace(WsmgNameSpaceConstants.WIDGET_NS);
+                topicExpEl.setText(WsmgNameSpaceConstants.WIDGET_NS.getPrefix() + ":" + topicExpression);
+            }
+
+            if (xpathExpression != null) {
+                OMElement xpathExpEl = factory.createOMElement("Selector", WsmgNameSpaceConstants.WSNT_NS, message);
+                xpathExpEl.addAttribute("Dialect", WsmgCommonConstants.XPATH_DIALECT, null);
+                xpathExpEl.setText(xpathExpression);
+            }
+
+            OMElement useNotifyEl = factory.createOMElement("UseNotify", message.getNamespace(), message);
+            useNotifyEl.setText("true");// check wether we still need this
+
+            OMElement eprCrEl = EndpointReferenceHelper.toOM(factory, eventSinkLocation,
+                    new QName("ConsumerReference"), WsmgNameSpaceConstants.WSA_NS.getNamespaceURI());
+
+            message.addChild(eprCrEl);
+            eprCrEl.setNamespace(message.getNamespace());
+
+            return message;
+        }
+
+        public static String decodeSubscriptionResponse(OMElement subscriptionReference) throws AxisFault {
+
+            String subscriptionId = null;
+
+            EndpointReference subscriptionReferenceEPR = EndpointReferenceHelper.fromOM(subscriptionReference);
+
+            Map<QName, OMElement> referenceParams = subscriptionReferenceEPR.getAllReferenceParameters();
+
+            if (referenceParams != null) {
+                QName identifierQName = new QName(WsmgNameSpaceConstants.WSNT_NS.getNamespaceURI(),
+                        WsmgCommonConstants.SUBSCRIPTION_ID);
+
+                OMElement identifierEl = referenceParams.get(identifierQName);
+                subscriptionId = (identifierEl != null) ? identifierEl.getText() : null;
+
+            }
+
+            return subscriptionId;
+        }
+
+        public static OMElement createUnsubscribeMsg() {
+            OMFactory factory = OMAbstractFactory.getOMFactory();
+            OMElement message = factory.createOMElement("UnsubsribeRequest", WsmgNameSpaceConstants.WSNT_NS);
+
+            return message;
+        }
+
+        public static OMElement encodeNotification(String topic, OMElement message, EndpointReference producerReference)
+                throws AxisFault {
+            OMFactory factory = OMAbstractFactory.getOMFactory();
+
+            OMElement topicExpEl = factory.createOMElement("Topic", WsmgNameSpaceConstants.WSNT_NS);
+            topicExpEl.addAttribute("Dialect", WsmgCommonConstants.TOPIC_EXPRESSION_SIMPLE_DIALECT, null);
+            topicExpEl.declareNamespace(WsmgNameSpaceConstants.WIDGET_NS);
+            topicExpEl.setText(WsmgNameSpaceConstants.WIDGET_NS.getPrefix() + ":" + topic);
+
+            OMElement messageToNotify = factory.createOMElement("Notify", WsmgNameSpaceConstants.WSNT_NS);
+            messageToNotify.declareNamespace(WsmgNameSpaceConstants.WSNT_NS);
+            messageToNotify.declareNamespace(WsmgNameSpaceConstants.WSA_NS);
+            OMElement notificationMesssageEl = factory.createOMElement("NotificationMessage",
+                    messageToNotify.getNamespace(), messageToNotify);
+
+            notificationMesssageEl.addChild(topicExpEl);
+
+            notificationMesssageEl
+                    .addChild(EndpointReferenceHelper.toOM(factory, producerReference, new QName(notificationMesssageEl
+                            .getNamespace().getNamespaceURI(), "ProducerReference", notificationMesssageEl
+                            .getNamespace().getPrefix()), WsmgNameSpaceConstants.WSA_NS.getNamespaceURI()));
+
+            OMElement messageEl = factory.createOMElement("Message", notificationMesssageEl.getNamespace(),
+                    notificationMesssageEl);
+
+            messageEl.addChild(message);
+            return messageToNotify;
+        }
+
+    }
\ No newline at end of file

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/util/ClientUtil.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/util/ClientUtil.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/util/ClientUtil.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/util/ClientUtil.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,60 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.wsmg.client.util;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+
+public class ClientUtil {
+    
+    public static final long EXPIRE_TIME = 1000 * 60 * 60 * 72l;
+    
+    public static String formatMessageBoxUrl(String msgBoxServiceUrl, String msgboxId) {
+        return msgBoxServiceUrl.endsWith("/") ? msgBoxServiceUrl + "clientid/" + msgboxId : msgBoxServiceUrl
+                + "/clientid/" + msgboxId;
+    }
+    
+
+    public static String formatURLString(String url) {
+       if (url == null) {
+           throw new IllegalArgumentException("url can't be null");
+       }
+       if (url.indexOf("//") < 0) {
+           url = "http://" + url; // use default http
+       }
+       return url;
+   }
+    
+    public static String getHostIP() {
+        InetAddress localAddress = null;
+        try {
+            localAddress = InetAddress.getLocalHost();
+        } catch (UnknownHostException ex) {
+            System.out.println("Error - unable to resolve localhost");
+        }
+        // Use IP address since DNS entry cannot update the laptop's entry
+        // promptly
+        String hostIP = localAddress.getHostAddress();
+        return hostIP;
+    }
+}

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/util/DcDate.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/util/DcDate.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/util/DcDate.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/client/util/DcDate.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,472 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.wsmg.client.util;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TimeZone;
+
+//TODO: support for fractional seconds
+
+/**
+ * Represent dc:date as an immutable value object. http://www.w3.org/TR/NOTE-datetime
+ * http://www.sics.se/~preben/DC/date_help.html
+ * 
+ */
+public final class DcDate implements Cloneable {
+
+    public Object clone() throws CloneNotSupportedException {
+        // it is easy as object is immutable
+        DcDate dd = (DcDate) super.clone();
+        return dd;
+    }
+
+    private String canonical;
+
+    // private Date date;
+    private int year;
+
+    private int month; // 1-12
+
+    private int day; // 1-31
+
+    private int hh = -1; // 00-23
+
+    private int mm = -1; // 00-59
+
+    private int ss = -1; // 00-59
+
+    private String decimalFraction = null; // decimal fraction
+
+    private int zoneOffset; // in minutes +/-(12*60) ???
+
+    private Calendar instant;
+
+    private int millisOffset = -1; // milliseconds
+
+    // public DcDate() throws SException {
+    //
+    // this(System.currentTimeMillis());
+    // }
+    //
+    // public DcDate(long timeMillis) throws SException {
+    // this(timeMillis, null);
+    // Calendar local = new GregorianCalendar();
+    // local.setTimeInMillis(timeMillis);
+    // }
+
+    // public DcDate(String tzName) throws SException {
+    // TimeZone tz = tzName != null ? TimeZone.getTimeZone(tzName) :
+    // TimeZone.getDefault();
+    // TimeZone.getTimeZone("GMT")
+    public DcDate(TimeZone tz) throws RuntimeException {
+
+        // based on http://javaalmanac.com/egs/java.util/GetAllZones.html?l=rel
+
+        Calendar cal = new GregorianCalendar(tz);
+        init(cal, tz);
+    }
+
+    public DcDate(Calendar cal) throws RuntimeException {
+        init(cal, cal.getTimeZone());
+    }
+
+    private void init(Calendar cal, TimeZone tz) throws RuntimeException {
+        // Get the number of hours from GMT
+        int rawOffset = tz.getRawOffset();
+        zoneOffset = rawOffset / (60 * 1000);
+
+        instant = cal;
+        // http://javaalmanac.com/egs/java.util/GetCurDate.html
+        year = cal.get(Calendar.YEAR);
+        month = cal.get(Calendar.MONTH) + 1; // 0=Jan, 1=Feb, ...
+        day = cal.get(Calendar.DAY_OF_MONTH);
+        hh = cal.get(Calendar.HOUR_OF_DAY); // 0..23
+        mm = cal.get(Calendar.MINUTE); // 0..59
+        ss = cal.get(Calendar.SECOND); // 0..59
+        // int ms = cal.get(Calendar.MILLISECOND); // 0..999
+        // date = cal.getTime();
+        canonical = computeCanonical();
+    }
+
+    public DcDate(String dcDate) throws RuntimeException {
+        // try {
+        // synchronized(sdf) { //TODO REVISIT: SimpleFormat is not multi-thread
+        // safe!
+        // d = sdf.parse(dcDate);
+        // }
+        // } catch (ParseException e) {
+        // throw new SException("could not parse dc:date "+dcDate+getCtx(pp),
+        // e);
+        // }
+        // 2003-05-06T23:07:04Z
+        // 2003-08-09T18:36:00-05:00
+        // 1234567890123456789012345
+        // 2004-02-02T19:09:46-05:00
+        // 1997
+        // 1997-07
+        // 1997-07-16
+        // 1997-07-16T19:20+01:00
+        // 1997-07-16T19:20:30+01:00
+        // 1997-07-16T19:20:30.45+01:00
+        assert dcDate != null;
+        // assert pp != null;
+        canonical = dcDate;
+        year = getInt(dcDate, 1, 4); // add min, max check for all getInt
+        if (dcDate.length() == 4) {
+            return;
+        }
+        check(dcDate, 5, '-');
+        month = getInt(dcDate, 6, 2);
+        if (dcDate.length() == 7) {
+            return;
+        }
+        check(dcDate, 8, '-');
+        day = getInt(dcDate, 9, 2);
+        if (dcDate.length() == 10) {
+            return;
+        }
+        check(dcDate, 11, 'T');
+        hh = getInt(dcDate, 12, 2);
+        check(dcDate, 14, ':');
+        mm = getInt(dcDate, 15, 2);
+        if (dcDate.length() == 16) {
+            throw new RuntimeException("expected date formatted as YYYY-MM-DDThh:mm[:ss[.mmm]]TZD and not " + dcDate);
+        }
+        int pos = 17;
+        char c17 = dcDate.charAt(pos - 1);
+        if (c17 == ':') {
+            check(dcDate, 17, ':');
+            ss = getInt(dcDate, 18, 2);
+            pos = 20;
+        }
+        char zoneIndicator = dcDate.charAt(pos - 1);
+        if (zoneIndicator == '.') { // OK we have yet millliseocnds to parse
+            // (and ignore ...)
+            // Ex: 2004-04-13T11:53:15.4362784-04:00
+            // eat digits
+            char d;
+            int oldPos = pos;
+            do {
+                d = dcDate.charAt(pos);
+                ++pos;
+            } while (d >= '0' && d <= '9');
+            if (oldPos + 1 == pos) {
+                throw new RuntimeException("expected date formtted as YYYY-MM-DDThh:mm[:ss[.s]]TZD and not " + dcDate);
+
+            }
+            zoneIndicator = d;
+            int newPos = pos;
+            decimalFraction = dcDate.substring(oldPos, newPos - 1);
+            if (newPos - oldPos >= 3) {
+                newPos = oldPos + 3;
+            }
+            int len = newPos - (oldPos + 1);
+            int ii = getInt(dcDate, oldPos + 1, len);
+            if (len == 1) {
+                millisOffset = 100 * ii;
+            } else if (len == 2) {
+                millisOffset = 10 * ii;
+            } else if (len == 3) {
+                millisOffset = ii;
+            }
+        }
+        if (zoneIndicator == 'Z') {
+            // done
+        } else if (zoneIndicator == '-' || zoneIndicator == '+') {
+            int zoneHH = getInt(dcDate, pos + 1, 2);
+            check(dcDate, pos + 3, ':');
+            int zoneMM = getInt(dcDate, pos + 4, 2);
+            zoneOffset = 60 * zoneHH + zoneMM;
+            if (zoneIndicator == '-') {
+                zoneOffset *= -1;
+            }
+        } else {
+            throw new RuntimeException("unknown zone indicator " + zoneIndicator + " in " + dcDate);
+        }
+        // Get the number of hours from GMT
+
+        // TimeZone tz = TimeZone.
+        instant = new GregorianCalendar();
+        int rawOffset = zoneOffset * 60 * 1000;
+        instant.set(Calendar.ZONE_OFFSET, rawOffset);
+        instant.set(Calendar.YEAR, year);
+        instant.set(Calendar.MONTH, month - 1); // 0=Jan, 1=Feb, ...
+        instant.set(Calendar.DAY_OF_MONTH, day);
+        instant.set(Calendar.HOUR_OF_DAY, hh); // 0..23
+        instant.set(Calendar.MINUTE, mm); // 0..59
+        instant.set(Calendar.SECOND, ss); // 0..59
+        instant.set(Calendar.MILLISECOND, millisOffset); // /0..999 ?
+        instant.getTimeInMillis(); // full time in ms -- test?
+    }
+
+    public long getTimeInMillis() {
+        return instant.getTimeInMillis();
+    }
+
+    public int getYear() {
+        return year;
+    }
+
+    public int getMonth() {
+        return month;
+    }
+
+    public int getDay() {
+        return day;
+    }
+
+    public int getHour() {
+        return hh;
+    }
+
+    public int getMinute() {
+        return mm;
+    }
+
+    public int getSecond() {
+        return ss;
+    }
+
+    public int getTimeZoneOffset() {
+        return zoneOffset;
+    }
+
+    public String getDcDate() {
+        return canonical;
+    }
+
+    public String getDecimalFraction() {
+        return decimalFraction;
+    }
+
+    private String computeCanonical() {
+        // 2003-08-09T18:36:00-05:00
+        // 1234567890123456789012345
+        StringBuffer sb = new StringBuffer();
+        fill(sb, year, 4);
+        if (month > 0) {
+            sb.append('-');
+            fill(sb, month, 2);
+            if (day > 0) {
+                sb.append('-');
+                fill(sb, day, 2);
+                if (hh > -1) {
+                    sb.append('T');
+                    fill(sb, hh, 2);
+                    sb.append(':');
+                    fill(sb, mm, 2);
+                    if (ss > -1) {
+                        sb.append(':');
+                        fill(sb, ss, 2);
+                    }
+                    if (decimalFraction != null) {
+                        sb.append('.');
+                        sb.append(decimalFraction);
+                    }
+                    if (zoneOffset == 0) {
+                        sb.append('Z');
+                    } else {
+                        int off = zoneOffset;
+                        if (zoneOffset > 0) {
+                            sb.append('+');
+                        } else {
+                            sb.append('-');
+                            off *= -1;
+                        }
+                        int zoneHH = off / 60;
+                        int zoneMM = off % 60;
+                        fill(sb, zoneHH, 2);
+                        sb.append(':');
+                        fill(sb, zoneMM, 2);
+                    }
+                }
+            }
+        }
+        return sb.toString();
+    }
+
+    public String toString() {
+        return canonical;
+    }
+
+    public final static String LOCATION_PROPERTY = "http://xmlpull.org/v1/doc/properties.html#location";
+
+    public static String printable(char ch) {
+        return "'" + escape(ch) + "'";
+    }
+
+    public static String printable(String s) {
+        return "\"" + escape(s) + "\"";
+    }
+
+    public static String escape(char ch) {
+        if (ch == '\n') {
+            return "\\n";
+        } else if (ch == '\r') {
+            return "\\r";
+        } else if (ch == '\t') {
+            return "\\t";
+        } else if (ch == '\'') {
+            return "\\'";
+        }
+        if (ch > 127 || ch < 32) {
+            return "\\u" + Integer.toHexString((int) ch);
+        }
+        return "" + ch;
+    }
+
+    public static String escape(String s) {
+        if (s == null) {
+            return null;
+        }
+        final int sLen = s.length();
+        StringBuffer buf = new StringBuffer(sLen + 10);
+        for (int i = 0; i < sLen; ++i) {
+            buf.append(escape(s.charAt(i)));
+        }
+        s = buf.toString();
+        return s;
+    }
+
+    private static final int LOOKUP_10S[] = { 1, 10, 10 * 10, 10 * 100, 100 * 100 };
+
+    public static void fill(StringBuffer sb, int value, int fields) {
+        assert fields > 0;
+        assert fields <= 4;
+        assert value >= 0;
+        int mm = LOOKUP_10S[fields];
+        assert value < mm;
+        // assert mm > 0
+        // TODO: optimize it ...
+        while (fields-- > 0) {
+            mm /= 10;
+            if (value >= mm) {
+                sb.append((value / mm) % 10);
+                // i /= 10;
+            } else {
+                sb.append('0');
+            }
+        }
+
+        // String s = sb.toString();
+        // assert s.toString().length == fields;
+        // return s;
+    }
+
+    public static void check(String dcDate, int pos, char ch) {
+        if (pos > dcDate.length()) {
+            throw new RuntimeException("expected " + printable(ch) + " at position " + pos + " but " + dcDate
+                    + " is too short");
+        }
+        char c = dcDate.charAt(pos - 1);
+        if (c != ch) {
+            throw new RuntimeException("expected " + printable(ch) + " but got " + printable(c) + " in " + dcDate);
+        }
+    }
+
+    public static int getInt(String dcDate, int pos, int len) throws RuntimeException {
+        assert len > 0;
+        int end = pos + len - 1;
+        String s = dcDate.substring(pos - 1, end);
+        try {
+            int i = Integer.parseInt(s);
+            return i;
+        } catch (NumberFormatException e) {
+            throw new RuntimeException("expected number for " + printable(s) + " in " + dcDate, e);
+
+        }
+    }
+
+    /**
+     * Take string and return string that has no spaces, only alpahnumerics, each word is capitalized (like WikiWords)
+     * sometimes called CamelCase?!.
+     */
+    public static String getWikiTitle(String title) {
+        StringBuffer sb = new StringBuffer();
+        List<String> words = breakIntoWords(title);
+        boolean start = true;
+        for (Iterator<String> it = words.iterator(); it.hasNext();) {
+            String word = it.next();
+            boolean wordStart = true;
+            for (int i = 0; i < word.length(); i++) {
+                char c = word.charAt(i);
+                if (Character.isLetterOrDigit(c)) {
+                    if (wordStart && !start) {
+                        sb.append(Character.toUpperCase(c));
+                    } else {
+                        sb.append(c);
+                    }
+                    wordStart = false;
+                }
+            }
+            start = false;
+        }
+        return sb.toString();
+    }
+
+    public static List<String> breakIntoWords(String s) {
+        List<String> words = new ArrayList<String>(s.length() / 5);
+        boolean inWord = true;
+        int wordStart = 0;
+        for (int pos = 0; pos < s.length(); ++pos) {
+            char ch = s.charAt(pos);
+            boolean isWordSeparator = Character.isWhitespace(ch);
+            if (ch == ',') {
+                isWordSeparator = true;
+            }
+            if (ch == '.') {
+                isWordSeparator = true;
+            }
+            if (isWordSeparator) {
+                if (inWord) {
+                    words.add(s.substring(wordStart, pos));
+                    inWord = false;
+                }
+            } else {
+                if (!inWord) {
+                    inWord = true;
+                    wordStart = pos;
+                }
+            }
+            assert inWord == !isWordSeparator;
+        }
+        if (inWord) {
+            words.add(s.substring(wordStart));
+        }
+        return words;
+    }
+
+    public static String makeTwoDigit(int oneOrTwoDigits) {
+        if (oneOrTwoDigits < 0 || oneOrTwoDigits > 99) {
+            throw new IllegalArgumentException();
+        }
+        if (oneOrTwoDigits < 10) {
+            return "0" + oneOrTwoDigits;
+        }
+        return "" + oneOrTwoDigits;
+    }
+
+}

Added: incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/gui/NotificationViewer.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/gui/NotificationViewer.java?rev=1170887&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/gui/NotificationViewer.java (added)
+++ incubator/airavata/trunk/modules/ws-messenger/client/src/main/java/org/apache/airavata/wsmg/gui/NotificationViewer.java Wed Sep 14 22:56:19 2011
@@ -0,0 +1,140 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.airavata.wsmg.gui;
+
+import java.awt.Dimension;
+import java.awt.Toolkit;
+
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+
+public class NotificationViewer {
+
+    boolean packFrame = false;
+
+    /*
+     * private static String getAxis2Repository(String[] cmdArgs) {
+     * 
+     * // if its in system properties get it.
+     * 
+     * if (System.getProperty(WsmgCommonConstants.CONFIG_AXIS2_REPO) != null) { File repodir = new File(System
+     * .getProperty(WsmgCommonConstants.CONFIG_AXIS2_REPO));
+     * 
+     * if (repodir.isDirectory()) { return repodir.getAbsolutePath(); }
+     * 
+     * throw new RuntimeException( "axis2 repository given in system parameter is invalid: " +
+     * repodir.getAbsolutePath());
+     * 
+     * }
+     * 
+     * if (cmdArgs.length > 1) {
+     * 
+     * if (cmdArgs[0].startsWith("-" + WsmgCommonConstants.CONFIG_AXIS2_REPO)) {
+     * 
+     * File repoDir = new File(cmdArgs[1]);
+     * 
+     * if (repoDir.isDirectory()) { return repoDir.getAbsolutePath(); }
+     * 
+     * throw new RuntimeException( "axis2 repository given as a  command line argument is invalid: " +
+     * repoDir.getAbsolutePath()); }
+     * 
+     * throw new RuntimeException("unknown commandline argument");
+     * 
+     * }
+     * 
+     * String axis2Home = System.getenv().get("AXIS2_HOME");
+     * 
+     * 
+     * if (axis2Home != null) {
+     * 
+     * String repo = axis2Home.endsWith(File.pathSeparator) ? axis2Home + "repository" : axis2Home + File.separator +
+     * "repository";
+     * 
+     * File repoDir = new File(repo);
+     * 
+     * if (repoDir.isDirectory()) {
+     * 
+     * 
+     * return repoDir.getAbsolutePath(); } }
+     * 
+     * return null; }
+     * 
+     * private static void printHelp() { System.out.println("unable to determine axis2 repository");
+     * System.out.println("please provide the system property: " + WsmgCommonConstants.CONFIG_AXIS2_REPO);
+     * System.out.println("or set AXIS2_HOME envirnment variable"); }
+     */
+
+    /**
+     * Construct and show the application.
+     */
+    public NotificationViewer() {
+        NotificationViewerFrame frame = new NotificationViewerFrame();
+        // Validate frames that have preset sizes
+        // Pack frames that have useful preferred size info, e.g. from their
+        // layout
+        if (packFrame) {
+            frame.pack();
+        } else {
+            frame.validate();
+        }
+
+        // Center the window
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        Dimension frameSize = frame.getSize();
+        if (frameSize.height > screenSize.height) {
+            frameSize.height = screenSize.height;
+        }
+        if (frameSize.width > screenSize.width) {
+            frameSize.width = screenSize.width;
+        }
+
+        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
+        frame.setVisible(true);
+    }
+
+    /**
+     * Application entry point.
+     * 
+     * @param args
+     *            String[]
+     */
+    public static void main(String[] args) {
+
+        /*
+         * final String axis2Repo = getAxis2Repository(args);
+         * 
+         * if (axis2Repo == null) { printHelp(); System.exit(1); }
+         */
+
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                try {
+                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+                } catch (Exception exception) {
+                    exception.printStackTrace();
+                }
+
+                new NotificationViewer();
+            }
+        });
+    }
+}