You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2008/06/29 19:33:49 UTC

svn commit: r672650 - in /synapse/trunk/java/modules/core/src: main/java/org/apache/synapse/config/xml/ main/java/org/apache/synapse/mediators/transform/ test/java/org/apache/synapse/config/xml/

Author: ruwan
Date: Sun Jun 29 10:33:49 2008
New Revision: 672650

URL: http://svn.apache.org/viewvc?rev=672650&view=rev
Log:
Fixing the issue SYNAPSE-367

now the <makeFault> will optionally mark the message as a response when the response attribute value is set to true

Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java
    synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/FaultMediatorSerializationTest.java

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorFactory.java?rev=672650&r1=672649&r2=672650&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorFactory.java Sun Jun 29 10:33:49 2008
@@ -35,7 +35,7 @@
  * <p>
  * Configuration syntax:
  * <pre>
- * &lt;makefault [version="soap11|soap12|pox"]&gt;
+ * &lt;makefault [version="soap11|soap12|pox"] response=("true"|"false")&gt;
  *   &lt;code (value="literal" | expression="xpath")/&gt;?
  *   &lt;reason (value="literal" | expression="xpath")&gt;?
  *   &lt;node&gt;?
@@ -51,6 +51,8 @@
 
     private static final QName ATT_VERSION_Q
             = new QName(XMLConfigConstants.NULL_NAMESPACE, "version");
+    private static final QName ATT_RESPONSE_Q
+            = new QName(XMLConfigConstants.NULL_NAMESPACE, "response");
     private static final QName CODE_Q
             = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "code");
     private static final QName REASON_Q
@@ -83,6 +85,19 @@
             }
         }
 
+        OMAttribute response = elem.getAttribute(ATT_RESPONSE_Q);
+        if (response != null) {
+            if ("true".equals(response.getAttributeValue())) {
+                faultMediator.setMarkAsResponse(true);
+            } else if ("false".equals(response.getAttributeValue())) {
+                faultMediator.setMarkAsResponse(false);
+            } else {
+                handleException("Invalid value '" + response.getAttributeValue()
+                        + "' passed as response. Expected 'true' or 'false'");
+            }
+            faultMediator.setSerializeResponse(true);
+        }
+
         OMElement code = elem.getFirstChildWithName(CODE_Q);
         if (code != null) {
             OMAttribute value = code.getAttribute(ATT_VALUE);

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorSerializer.java?rev=672650&r1=672649&r2=672650&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/FaultMediatorSerializer.java Sun Jun 29 10:33:49 2008
@@ -57,10 +57,18 @@
                 "version", nullNS, POX));
         }
 
+        if (mediator.isSerializeResponse()) {
+            if (mediator.isMarkAsResponse()) {
+                fault.addAttribute(fac.createOMAttribute("response", nullNS, "true"));
+            } else {
+                fault.addAttribute(fac.createOMAttribute("response", nullNS, "false"));
+            }
+        }
+
         OMElement code = fac.createOMElement("code", synNS, fault);
         if (mediator.getFaultCodeValue() != null) {
             code.addAttribute(fac.createOMAttribute(
-                "value", nullNS, mediator.getFaultCodeValue().getPrefix() + ":"
+                    "value", nullNS, mediator.getFaultCodeValue().getPrefix() + ":"
                     + mediator.getFaultCodeValue().getLocalPart()));
             code.declareNamespace(mediator.getFaultCodeValue().getNamespaceURI(),
                     mediator.getFaultCodeValue().getPrefix());

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java?rev=672650&r1=672649&r2=672650&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java Sun Jun 29 10:33:49 2008
@@ -58,6 +58,10 @@
     public static final int POX = 3;
     /** Holds the SOAP version to be used to make the fault, if specified */
     private int soapVersion;
+    /** Whether to mark the created fault as a response or not */
+    private boolean markAsResponse = false;
+    /** Whether it is required to serialize the response attribute or not */
+    private boolean serializeResponse = false;
 
     // -- fault elements --
     /** The fault code QName to be used */
@@ -92,17 +96,17 @@
 
         switch (soapVersion) {
             case SOAP11:
-                return makeSOAPFault(synCtx, SOAP11, traceOrDebugOn, traceOn);
+                makeSOAPFault(synCtx, SOAP11, traceOrDebugOn, traceOn);
             case SOAP12:
-                return makeSOAPFault(synCtx, SOAP12, traceOrDebugOn, traceOn);
+                makeSOAPFault(synCtx, SOAP12, traceOrDebugOn, traceOn);
             case POX:
-                return makePOXFault(synCtx, traceOrDebugOn, traceOn);
+                makePOXFault(synCtx, traceOrDebugOn, traceOn);
 
             default : {
                 // if this is a POX or REST message then make a POX fault
                 if (synCtx.isDoingPOX() || synCtx.isDoingGET()) {
                     
-                    return makePOXFault(synCtx, traceOrDebugOn, traceOn);
+                    makePOXFault(synCtx, traceOrDebugOn, traceOn);
 
                 } else {
                     
@@ -114,23 +118,31 @@
                             envelop.getNamespace().getNamespaceURI())) {
 
                             soapVersion = SOAP12;
-                            return makeSOAPFault(synCtx, SOAP12, traceOrDebugOn, traceOn);
+                            makeSOAPFault(synCtx, SOAP12, traceOrDebugOn, traceOn);
 
                         } else {
                             soapVersion = SOAP11;
-                            return makeSOAPFault(synCtx, SOAP11, traceOrDebugOn, traceOn);
+                            makeSOAPFault(synCtx, SOAP11, traceOrDebugOn, traceOn);
                         }
                         
                     } else {
                         // default to SOAP 11
-                        return makeSOAPFault(synCtx, SOAP11, traceOrDebugOn, traceOn);
+                        makeSOAPFault(synCtx, SOAP11, traceOrDebugOn, traceOn);
                     }
                 }
             }
         }
+
+        // if the message has to be marked as a response mark it as response
+        if (markAsResponse) {
+            synCtx.setResponse(true);
+            synCtx.setTo(synCtx.getReplyTo());
+        }
+        
+        return true;
     }
 
-    private boolean makePOXFault(MessageContext synCtx, boolean traceOrDebugOn, boolean traceOn) {
+    private void makePOXFault(MessageContext synCtx, boolean traceOrDebugOn, boolean traceOn) {
 
         OMFactory fac = synCtx.getEnvelope().getOMFactory();
         OMElement faultPayload = fac.createOMElement(new QName("Exception"));
@@ -198,8 +210,6 @@
             
             body.addChild(faultPayload);
         }
-
-        return true;
     }
 
     /**
@@ -208,9 +218,8 @@
      * @param soapVersion SOAP version of the resulting fault desired
      * @param traceOrDebugOn is trace or debug logging on?
      * @param traceOn is tracing on?
-     * @return true, always
      */
-    private boolean makeSOAPFault(MessageContext synCtx, int soapVersion,
+    private void makeSOAPFault(MessageContext synCtx, int soapVersion,
         boolean traceOrDebugOn, boolean traceOn) {
 
         if (traceOrDebugOn) {
@@ -293,8 +302,6 @@
         if (traceOrDebugOn) {
             traceOrDebug(traceOn, "End : Fault mediator");
         }
-        
-        return true;
     }
 
     private void setFaultCode(MessageContext synCtx, SOAPFactory factory, SOAPFault fault) {
@@ -387,6 +394,22 @@
         this.soapVersion = soapVersion;
     }
 
+    public boolean isMarkAsResponse() {
+        return markAsResponse;
+    }
+
+    public void setMarkAsResponse(boolean markAsResponse) {
+        this.markAsResponse = markAsResponse;
+    }
+
+    public boolean isSerializeResponse() {
+        return serializeResponse;
+    }
+
+    public void setSerializeResponse(boolean serializeResponse) {
+        this.serializeResponse = serializeResponse;
+    }
+
     public QName getFaultCodeValue() {
         return faultCodeValue;
     }

Modified: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/FaultMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/FaultMediatorSerializationTest.java?rev=672650&r1=672649&r2=672650&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/FaultMediatorSerializationTest.java (original)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/FaultMediatorSerializationTest.java Sun Jun 29 10:33:49 2008
@@ -44,7 +44,13 @@
     }
 
     public void testFaultMediatorSerializationSOAP12() throws Exception {
-        String inputXml = getXmlOfMediatorForSOAP12(SOAP12, "soap:Sender", "reason", EMPTY, EMPTY, EMPTY);
+        String inputXml = getXmlOfMediatorForSOAP12(SOAP12, "soap:Sender", "reason", EMPTY, EMPTY, EMPTY, "false");
+        assertTrue(serialization(inputXml, faultMediatorFactory, faultMediatorSerializer));
+        assertTrue(serialization(inputXml, faultMediatorSerializer));
+    }
+
+    public void testFaultMediatorSerializationSOAP12withResponse() throws Exception {
+        String inputXml = getXmlOfMediatorForSOAP12(SOAP12, "soap:Sender", "reason", EMPTY, EMPTY, EMPTY, "true");
         assertTrue(serialization(inputXml, faultMediatorFactory, faultMediatorSerializer));
         assertTrue(serialization(inputXml, faultMediatorSerializer));
     }
@@ -57,8 +63,8 @@
     }
 
     private String getXmlOfMediatorForSOAP12(String version, String attrOfCode, String attrOfReasion
-            , String node, String role, String details) throws Exception {
-        return "<makefault xmlns=\"http://ws.apache.org/ns/synapse\" version=\"" + version + "\"><code value=\"" + attrOfCode + "\" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"/><reason value=\"" + attrOfReasion + "\"/>" +
+            , String node, String role, String details, String response) throws Exception {
+        return "<makefault xmlns=\"http://ws.apache.org/ns/synapse\" version=\"" + version + "\" response=\"" + response + "\"><code value=\"" + attrOfCode + "\" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"/><reason value=\"" + attrOfReasion + "\"/>" +
                 "<node>" + node + "</node><role>" + role + "</role><detail>" + details + "</detail></makefault>";
 
     }



Re: svn commit: r672650 - in /synapse/trunk/java/modules/core/src: main/java/org/apache/synapse/config/xml/ main/java/org/apache/synapse/mediators/transform/ test/java/org/apache/synapse/config/xml/

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Asankha and Eric,

I also think the default value of the markAsResponse field has to be true
and I will change that. For the second question, that is to check the
ReplyTo for the presence and remove the To header if it is not present is a
redundant work, here is the explanation for that :-)

When we use the configuration to set the To header with the ReplyTo header,
if the ReplyTo header has not been set, then it returns null and on the
configuration this will lead to a String "null" being set as the To header
which in-turn causes a malformed URI exception. There for when we use the
configuration language to do this you need to check the presence of the
ReplyTo header and copy it as the To header if there is a one and should
remove the To header to make it null if there is no ReplyTo. But,
programatically null (not string "null") being set as the To header (When
the ReplyTo header is not there this is the case) is same as removing the To
header. There for the existing code is doing what is expected.

So one line change of

- private boolean markAsResponse = false;
+ private boolean markAsResponse = true;

would fix all these.

At the same time I think the FaultMediator has to be aware of addressing
specification and should consider the existence of FaultTo header as well,
because this is a fault according to WS-Adressing, if there is a wsa:FaultTo
header, then the fault has to be sent to the specified address but not to
the ReplyTo address nor on the same channel.

Thanks,
Ruwan

On Fri, Aug 1, 2008 at 12:18 PM, Hubert, Eric <er...@jamba.net> wrote:

>  Hi,
>
>
>
> yes, marking a fault as a response by default sounds also reasonable to me.
> If there are really cases where this is not what you want, you can simply
> leave the code as it is, but just initialize the markAsResponse to true by
> default so the user would only need to configure something if he wants to
> change the default to not send the fault as a response.
>
>
>
> Removing the To header programmatically here if no ReplyTo exists sounds
> like a good idea. This would further reduce the need of configuration.
>
>
>
> Good ideas Asankha, I'm also interested whether Ruwan has some cases in
> mind, where this would not be a desired behaviour.
>
>
>
>
>
> Regards,
>
>    Eric
>
>
>   ------------------------------
>
> *From:* Asankha C. Perera [mailto:asankha@wso2.com]
> *Sent:* Friday, August 01, 2008 8:12 AM
> *To:* dev@synapse.apache.org
> *Subject:* Re: svn commit: r672650 - in
> /synapse/trunk/java/modules/core/src:
> main/java/org/apache/synapse/config/xml/
> main/java/org/apache/synapse/mediators/transform/
> test/java/org/apache/synapse/config/xml/
>
>
>
> Ruwan
>
> I think by default, we should mark a fault as a response? Any reason to not
> do this?
>
> Also for the below code, shall we check if a ReplyTo exists, and else
> remove the 'To' header like we now do in config?
>
> thanks
> asankha
>
> ruwan@apache.org wrote:
>
> Author: ruwan
>
> Date: Sun Jun 29 10:33:49 2008
>
> New Revision: 672650
>
>
>
> Fixing the issue SYNAPSE-367
>
>
>
> now the <makeFault> will optionally mark the message as a response when the response attribute value is set to true
>
>
>
> ==============================================================================
>
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java (original)
>
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java Sun Jun 29 10:33:49 2008
>
> @@ -114,23 +118,31 @@
>
> ...
>
> +        // if the message has to be marked as a response mark it as response
>
> +        if (markAsResponse) {
>
> +            synCtx.setResponse(true);
>
> +            synCtx.setTo(synCtx.getReplyTo());
>
> +        }
>
> +
>
> +        return true;
>
>
>
>
>
> --
> Asankha C. Perera
>
> WSO2 - http://wso2.org
> http://esbmagic.blogspot.com
>



-- 
Ruwan Linton
http://wso2.org - "Oxygenating the Web Services Platform"
http://ruwansblog.blogspot.com/

RE: svn commit: r672650 - in /synapse/trunk/java/modules/core/src: main/java/org/apache/synapse/config/xml/ main/java/org/apache/synapse/mediators/transform/ test/java/org/apache/synapse/config/xml/

Posted by "Hubert, Eric" <er...@jamba.net>.
Hi,

 

yes, marking a fault as a response by default sounds also reasonable to
me. If there are really cases where this is not what you want, you can
simply leave the code as it is, but just initialize the markAsResponse
to true by default so the user would only need to configure something if
he wants to change the default to not send the fault as a response.

 

Removing the To header programmatically here if no ReplyTo exists sounds
like a good idea. This would further reduce the need of configuration.

 

Good ideas Asankha, I'm also interested whether Ruwan has some cases in
mind, where this would not be a desired behaviour.

 

 

Regards,

   Eric

 

________________________________

From: Asankha C. Perera [mailto:asankha@wso2.com] 
Sent: Friday, August 01, 2008 8:12 AM
To: dev@synapse.apache.org
Subject: Re: svn commit: r672650 - in
/synapse/trunk/java/modules/core/src:
main/java/org/apache/synapse/config/xml/
main/java/org/apache/synapse/mediators/transform/
test/java/org/apache/synapse/config/xml/

 

Ruwan

I think by default, we should mark a fault as a response? Any reason to
not do this?

Also for the below code, shall we check if a ReplyTo exists, and else
remove the 'To' header like we now do in config?

thanks
asankha

ruwan@apache.org wrote: 

Author: ruwan
Date: Sun Jun 29 10:33:49 2008
New Revision: 672650
 
Fixing the issue SYNAPSE-367
 
now the <makeFault> will optionally mark the message as a response when
the response attribute value is set to true
 
========================================================================
======
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediato
rs/transform/FaultMediator.java (original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediato
rs/transform/FaultMediator.java Sun Jun 29 10:33:49 2008
@@ -114,23 +118,31 @@
...
+        // if the message has to be marked as a response mark it as
response
+        if (markAsResponse) {
+            synCtx.setResponse(true);
+            synCtx.setTo(synCtx.getReplyTo());
+        }
+        
+        return true;
  

 

-- 
Asankha C. Perera 

WSO2 - http://wso2.org
http://esbmagic.blogspot.com


Re: svn commit: r672650 - in /synapse/trunk/java/modules/core/src: main/java/org/apache/synapse/config/xml/ main/java/org/apache/synapse/mediators/transform/ test/java/org/apache/synapse/config/xml/

Posted by "Asankha C. Perera" <as...@wso2.com>.
Ruwan

I think by default, we should mark a fault as a response? Any reason to 
not do this?

Also for the below code, shall we check if a ReplyTo exists, and else 
remove the 'To' header like we now do in config?

thanks
asankha

ruwan@apache.org wrote:
> Author: ruwan
> Date: Sun Jun 29 10:33:49 2008
> New Revision: 672650
>
> Fixing the issue SYNAPSE-367
>
> now the <makeFault> will optionally mark the message as a response when the response attribute value is set to true
>
> ==============================================================================
> --- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java (original)
> +++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java Sun Jun 29 10:33:49 2008
> @@ -114,23 +118,31 @@
> ...
> +        // if the message has to be marked as a response mark it as response
> +        if (markAsResponse) {
> +            synCtx.setResponse(true);
> +            synCtx.setTo(synCtx.getReplyTo());
> +        }
> +        
> +        return true;
>   

-- 
Asankha C. Perera

WSO2 - http://wso2.org
http://esbmagic.blogspot.com