Author: asankaa
Date: Tue Nov 25 11:34:18 2008
New Revision: 24865
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=24865

Log:
Introduce fault messages 
Debug log messages added 


Modified:
   
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/EventSource.java
   
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/builders/ResponseMessageBuilder.java

Modified: 
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/EventSource.java
URL: 
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/EventSource.java?rev=24865&r1=24864&r2=24865&view=diff
==============================================================================
--- 
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/EventSource.java
 (original)
+++ 
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/EventSource.java
 Tue Nov 25 11:34:18 2008
@@ -28,6 +28,8 @@
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.InOutAxisOperation;
 import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.config.SynapseConfiguration;
 import org.apache.synapse.core.SynapseEnvironment;
@@ -50,7 +52,7 @@
 
     private String name;
     private SubscriptionManager subscriptionManager;
-
+    private static final Log log = LogFactory.getLog(EventSource.class);
 
     public EventSource(String name) {
         this.name = name;
@@ -103,9 +105,15 @@
         if (EventingConstants.WSE_SUBSCRIBE.equals(mc.getWSAAction())) {
             // add new subscription to the Subscription store through 
subscription manager
             Subscription subscription = 
SubscriptionMessageBuilder.createSubscription(smc);
+            if (log.isDebugEnabled()) {
+                log.debug("Subscription request recived  : " + 
subscription.getId());
+            }
             String subID = subscriptionManager.addSubscription(subscription);
             if (subID != null) {
                 // Send the subscription responce
+                if (log.isDebugEnabled()) {
+                    log.debug("Sending sunscription response for Subscription 
ID : " + subscription.getId());
+                }
                 SOAPEnvelope soapEnvelope = 
messageBuilder.genSubscriptionResponse(subscription);
                 String replyAddress = 
mc.getOptions().getReplyTo().getAddress();
                 AddressEndpoint endpoint = new AddressEndpoint();
@@ -115,17 +123,40 @@
                 org.apache.synapse.MessageContext rmc = new 
Axis2MessageContext(mc, synCfg, synEnv);
                 rmc.setEnvelope(soapEnvelope);
                 rmc.setTo(new EndpointReference(replyAddress));
-                rmc.setWSAAction(EventingConstants.WSE_SUbSCRIBE_RESPONSE);
+                rmc.setWSAAction(EventingConstants.WSE_SUbSCRIBE_RESPONSE);  
//TODO: headers dose not set, repsonce carry the original message header
                 rmc.setSoapAction(EventingConstants.WSE_SUbSCRIBE_RESPONSE);
+                rmc.setResponse(true);
                 endpoint.send(rmc);
             } else {
-                //TODO: send the fault message  
+                // Send the Fault responce
+                if (log.isDebugEnabled()) {
+                    log.debug("Subscription Failed, sending fault response");
+                }
+                SOAPEnvelope soapEnvelope = 
messageBuilder.genFaultResponse(EventingConstants.WSE_FAULT_CODE_RECEIVER, 
"wse:EventSourceUnableToProcess", "", "");
+                String replyAddress = 
mc.getOptions().getReplyTo().getAddress();
+                AddressEndpoint endpoint = new AddressEndpoint();
+                EndpointDefinition def = new EndpointDefinition();
+                def.setAddress(replyAddress.trim());
+                endpoint.setDefinition(def);
+                org.apache.synapse.MessageContext rmc = new 
Axis2MessageContext(mc, synCfg, synEnv);
+                rmc.setEnvelope(soapEnvelope);
+                rmc.setTo(new EndpointReference(replyAddress));
+                rmc.setWSAAction(EventingConstants.WSA_FAULT);
+                rmc.setSoapAction(EventingConstants.WSA_FAULT);
+                rmc.setResponse(true);
+                endpoint.send(rmc);
             }
         } else if 
(EventingConstants.WSE_UNSUBSCRIBE.equals(mc.getWSAAction())) {
             // Unsubscribe for responce
             Subscription subscription = 
SubscriptionMessageBuilder.createUnSubscribeMessage(smc);
+            if (log.isDebugEnabled()) {
+                log.debug("UnSubscribe response recived for Subscription ID : 
" + subscription.getId());
+            }
             if (subscriptionManager.deleteSubscription(subscription.getId())) {
                 //send the response
+                if (log.isDebugEnabled()) {
+                    log.debug("Sending UnSubscribe responce for Subscription 
ID : " + subscription.getId());
+                }
                 SOAPEnvelope soapEnvelope = 
messageBuilder.genUnSubscribeResponse(subscription);
                 String replyAddress = 
mc.getOptions().getReplyTo().getAddress();
                 AddressEndpoint endpoint = new AddressEndpoint();
@@ -138,16 +169,39 @@
                 rmc.setWSAAction(EventingConstants.WSE_UNSUBSCRIBE_RESPONSE);
                 rmc.setSoapAction(EventingConstants.WSE_UNSUBSCRIBE_RESPONSE);
                 RelatesTo relatesTo = new RelatesTo(subscription.getId());
-                rmc.setRelatesTo(new RelatesTo[] { relatesTo });
+                rmc.setRelatesTo(new RelatesTo[]{relatesTo});
+                rmc.setResponse(true);
                 endpoint.send(rmc);
             } else {
-                //TODO: send the fault message
+                // Send the Fault responce
+                if (log.isDebugEnabled()) {
+                    log.debug("UnSubscription failed, sending fault 
repsponse");
+                }
+                SOAPEnvelope soapEnvelope = 
messageBuilder.genFaultResponse(EventingConstants.WSE_FAULT_CODE_RECEIVER, 
"wse:EventSourceUnableToProcess", "", "");
+                String replyAddress = 
mc.getOptions().getReplyTo().getAddress();
+                AddressEndpoint endpoint = new AddressEndpoint();
+                EndpointDefinition def = new EndpointDefinition();
+                def.setAddress(replyAddress.trim());
+                endpoint.setDefinition(def);
+                org.apache.synapse.MessageContext rmc = new 
Axis2MessageContext(mc, synCfg, synEnv);
+                rmc.setEnvelope(soapEnvelope);
+                rmc.setTo(new EndpointReference(replyAddress));
+                rmc.setWSAAction(EventingConstants.WSA_FAULT);
+                rmc.setSoapAction(EventingConstants.WSA_FAULT);
+                rmc.setResponse(true);
+                endpoint.send(rmc);
             }
         } else if (EventingConstants.WSE_GET_STATUS.equals(mc.getWSAAction())) 
{
             // Get responce status
             Subscription subscription = 
SubscriptionMessageBuilder.createGetStatusMessage(smc);
+            if (log.isDebugEnabled()) {
+                log.debug("GetStatus request recived for Subscription ID : " + 
subscription.getId());
+            }
             subscription = 
subscriptionManager.getSubscription(subscription.getId());
-            if(subscription !=null){
+            if (subscription != null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Sending GetStatus responce for Subscription ID 
: " + subscription.getId());
+                }
                 //send the responce
                 SOAPEnvelope soapEnvelope = 
messageBuilder.genGetStatusResponse(subscription);
                 String replyAddress = 
mc.getOptions().getReplyTo().getAddress();
@@ -161,16 +215,39 @@
                 rmc.setWSAAction(EventingConstants.WSE_GET_STATUS_RESPONSE);
                 rmc.setSoapAction(EventingConstants.WSE_GET_STATUS_RESPONSE);
                 RelatesTo relatesTo = new RelatesTo(subscription.getId());
-                rmc.setRelatesTo(new RelatesTo[] { relatesTo });
-                endpoint.send(rmc);                   
+                rmc.setRelatesTo(new RelatesTo[]{relatesTo});
+                rmc.setResponse(true);
+                endpoint.send(rmc);
             } else {
-                //TODO: send the fault message
+                // Send the Fault responce
+                if (log.isDebugEnabled()) {
+                    log.debug("GetStatus failed, sending fault response");
+                }
+                SOAPEnvelope soapEnvelope = 
messageBuilder.genFaultResponse(EventingConstants.WSE_FAULT_CODE_RECEIVER, 
"wse:EventSourceUnableToProcess", "", "");
+                String replyAddress = 
mc.getOptions().getReplyTo().getAddress();
+                AddressEndpoint endpoint = new AddressEndpoint();
+                EndpointDefinition def = new EndpointDefinition();
+                def.setAddress(replyAddress.trim());
+                endpoint.setDefinition(def);
+                org.apache.synapse.MessageContext rmc = new 
Axis2MessageContext(mc, synCfg, synEnv);
+                rmc.setEnvelope(soapEnvelope);
+                rmc.setTo(new EndpointReference(replyAddress));
+                rmc.setWSAAction(EventingConstants.WSA_FAULT);
+                rmc.setSoapAction(EventingConstants.WSA_FAULT);
+                rmc.setResponse(true);
+                endpoint.send(rmc);
             }
         } else if (EventingConstants.WSE_RENEW.equals(mc.getWSAAction())) {
             // Renew subscription
             Subscription subscription = 
SubscriptionMessageBuilder.createRenewSubscribeMessage(smc);
-            if (subscriptionManager.renewSubscription(subscription)){
+            if (log.isDebugEnabled()) {
+                log.debug("ReNew request recived for Subscription ID : " + 
subscription.getId());
+            }
+            if (subscriptionManager.renewSubscription(subscription)) {
                 //send the response
+                if (log.isDebugEnabled()) {
+                    log.debug("Sending ReNew response for Subscription ID : " 
+ subscription.getId());
+                }
                 SOAPEnvelope soapEnvelope = 
messageBuilder.genRenewSubscriptionResponse(subscription);
                 String replyAddress = 
mc.getOptions().getReplyTo().getAddress();
                 AddressEndpoint endpoint = new AddressEndpoint();
@@ -183,17 +260,41 @@
                 rmc.setWSAAction(EventingConstants.WSE_RENEW_RESPONSE);
                 rmc.setSoapAction(EventingConstants.WSE_RENEW_RESPONSE);
                 RelatesTo relatesTo = new RelatesTo(subscription.getId());
-                rmc.setRelatesTo(new RelatesTo[] { relatesTo });
+                rmc.setRelatesTo(new RelatesTo[]{relatesTo});
+                rmc.setResponse(true);
+                endpoint.send(rmc);
+            } else {
+                // Send the Fault responce
+                if (log.isDebugEnabled()) {
+                    log.debug("ReNew failed, sending fault response");
+                }
+                SOAPEnvelope soapEnvelope = 
messageBuilder.genFaultResponse(EventingConstants.WSE_FAULT_CODE_RECEIVER, 
"wse:UnableToRenew", "", "");
+                String replyAddress = 
mc.getOptions().getReplyTo().getAddress();
+                AddressEndpoint endpoint = new AddressEndpoint();
+                EndpointDefinition def = new EndpointDefinition();
+                def.setAddress(replyAddress.trim());
+                endpoint.setDefinition(def);
+                org.apache.synapse.MessageContext rmc = new 
Axis2MessageContext(mc, synCfg, synEnv);
+                rmc.setEnvelope(soapEnvelope);
+                rmc.setTo(new EndpointReference(replyAddress));
+                rmc.setWSAAction(EventingConstants.WSA_FAULT);
+                rmc.setSoapAction(EventingConstants.WSA_FAULT);
+                rmc.setResponse(true);
                 endpoint.send(rmc);
-            }else{
-                //TODO: send the fault message
             }
         } else {
             // Treat as an Event
+            if (log.isDebugEnabled()) {
+                log.debug("Event recived");
+            }
             List<Subscription> subscribers = 
subscriptionManager.getMatchingSubscribers(smc);
             for (Subscription subscription : subscribers) {
+                //TODO: send a 202 responce to the client, client wait and 
time outs 
                 smc.setProperty("OUT_ONLY", "true");    // Set one way message 
for events
                 
subscription.getEndpoint().send(MessageHelper.cloneMessageContext(smc));
+                if (log.isDebugEnabled()) {
+                    log.debug("Event push to  : " + 
subscription.getEndpoint().toString());
+                }
             }
         }
     }

Modified: 
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/builders/ResponseMessageBuilder.java
URL: 
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/builders/ResponseMessageBuilder.java?rev=24865&r1=24864&r2=24865&view=diff
==============================================================================
--- 
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/builders/ResponseMessageBuilder.java
     (original)
+++ 
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/eventing/builders/ResponseMessageBuilder.java
     Tue Nov 25 11:34:18 2008
@@ -5,11 +5,11 @@
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.databinding.utils.ConverterUtil;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.addressing.EndpointReferenceHelper;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.databinding.utils.ConverterUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseException;
@@ -41,7 +41,7 @@
     private static final Log log = 
LogFactory.getLog(ResponseMessageBuilder.class);
 
     public ResponseMessageBuilder(MessageContext messageCtx) {
-        factory = (SOAPFactory) messageCtx.getEnvelope().getOMFactory();       
+        factory = (SOAPFactory) messageCtx.getEnvelope().getOMFactory();
     }
 
     /**
@@ -204,6 +204,66 @@
         return message;
     }
 
+    /**
+     * <S:Envelope>
+     * <S:Header>
+     * <wsa:Action>
+     * http://schemas.xmlsoap.org/ws/2004/08/addressing/fault
+     * </wsa:Action>
+     * <!-- Headers elided for clarity.  -->
+     * </S:Header>
+     * <S:Body>
+     *  <S:Fault>
+     *      <S:Code>
+     *          <S:Value>[Code]</S:Value>
+     *          <S:Subcode>
+     *              <S:Value>[Subcode]</S:Value>
+     *          </S:Subcode>
+     *      </S:Code>
+     *      <S:Reason>
+     *          <S:Text xml:lang="en">[Reason]</S:Text>
+     *      </S:Reason>
+     *      <S:Detail>
+     *          [Detail]
+     *      </S:Detail>
+     *  </S:Fault>
+     * </S:Body>
+     * </S:Envelope>
+     *     
+     * @param code
+     * @param subCode
+     * @param reason
+     * @param detail
+     * @return
+     */
+    public SOAPEnvelope genFaultResponse(String code,String subCode,String 
reason,String detail) {
+        SOAPEnvelope message = factory.getDefaultEnvelope();
+        OMElement faultElement = 
factory.createOMElement(EventingConstants.WSE_FAULT_EN_FAULT, null);
+        OMElement codeElement = 
factory.createOMElement(EventingConstants.WSE_FAULT_EN_CODE, null);
+        OMElement codeValueElement = 
factory.createOMElement(EventingConstants.WSE_FAULT_EN_VALUE, null);
+        OMElement subCodeElement = 
factory.createOMElement(EventingConstants.WSE_FAULT_EN_SUB_CODE, null);
+        OMElement subCodeValueElement = 
factory.createOMElement(EventingConstants.WSE_FAULT_EN_VALUE, null);
+        OMElement reasonElement = 
factory.createOMElement(EventingConstants.WSE_FAULT_EN_REASON, null);
+        OMElement reasonTextElement = 
factory.createOMElement(EventingConstants.WSE_FAULT_EN_TEXT, null);
+        OMElement detailElement = 
factory.createOMElement(EventingConstants.WSE_FAULT_EN_DETAIL, null);
+        factory.createOMText(codeValueElement,code);
+        factory.createOMText(subCodeValueElement,subCode);
+        factory.createOMText(reasonTextElement,reason);
+        factory.createOMText(detailElement,detail);
+        OMNamespace xmlNameSpace = factory.createOMNamespace("xml",null);
+        
reasonTextElement.addAttribute(EventingConstants.WSE_FAULT_EN_TEXT_ATTR,"en",xmlNameSpace);
+
+        codeElement.addChild(codeValueElement);
+        subCodeElement.addChild(subCodeValueElement);
+        codeElement.addChild(subCodeElement);
+        faultElement.addChild(codeElement);
+        reasonElement.addChild(reasonTextElement);
+        faultElement.addChild(reasonElement);
+        faultElement.addChild(detailElement);
+        message.getBody().addChild(faultElement);
+        return message;
+    }
+
     private void handleException(String message) {
         log.error(message);
         throw new SynapseException(message);

_______________________________________________
Esb-java-dev mailing list
[email protected]
https://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev

Reply via email to