synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Fremantle" <pzf...@gmail.com>
Subject Re: svn commit: r393790 - in /incubator/synapse/trunk/java: modules/core/src/org/apache/synapse/mediators/builtin/axis2/ modules/core/src/org/apache/synapse/mediators/filters/ modules/core/src/org/apache/synapse/xml/ repository/conf/
Date Thu, 13 Apr 2006 13:00:51 GMT
Hi Glen

Thanks for this.... looks good. I just posted a proposal to clean up the
synapse.xml (and => the mediators). One of the proposals was for the fault
mediator. http://wiki.apache.org/incubator/Synapse/SynapseXMLFormat

    <fault version="soap11|soap12">
      <code value="literal" | source-property=""/>
      <reason>
      <node>
      <role>
      <detail>
    </fault>


I guess there also ought to be an "auto" version which uses the current SOAP
version (as the mediator does today).

Paul

On 4/13/06, gdaniels@apache.org <gdaniels@apache.org> wrote:
>
> Author: gdaniels
> Date: Thu Apr 13 05:15:58 2006
> New Revision: 393790
>
> URL: http://svn.apache.org/viewcvs?rev=393790&view=rev
> Log:
> * Fix synapse.xml so the demo works (correct regexp)
>
> * Check log.isDebugEnabled() before logging each result of RegexMediator
> (saves a little time)
>
> * Add ability to specify <faultCode> and <reason> in the FaultMediator
> configuration.  Will improve this (and connect it up to the actual fault
> generation) as soon as I figure out how to easily configure AXIOM SOAP
> faults.
>
> Modified:
>
>     incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/axis2/FaultMediator.java
>
>     incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/RegexMediator.java
>
>     incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/FaultMediatorFactory.java
>     incubator/synapse/trunk/java/repository/conf/synapse.xml
>
> Modified:
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/axis2/FaultMediator.java
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/axis2/FaultMediator.java?rev=393790&r1=393789&r2=393790&view=diff
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/axis2/FaultMediator.java
> (original)
> +++
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/builtin/axis2/FaultMediator.java
> Thu Apr 13 05:15:58 2006
> @@ -28,47 +28,71 @@
> import org.apache.axiom.om.OMAbstractFactory;
> import org.apache.axiom.om.OMDocument;
>
> +import javax.xml.namespace.QName;
> +
> /**
>   * <p/> This returns a fault in response to this message
>   */
> public class FaultMediator implements Mediator{
>
> -       private Log log = LogFactory.getLog(getClass());
> -
> -       public boolean mediate(SynapseMessage smc) {
> -               log.debug("process");
> -
> -               SOAPEnvelope envelop = smc.getEnvelope();
> -               SOAPFactory factory;
> -               if (envelop != null) {
> -                       if (envelop.getNamespace().getName().equals(
> -
> SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
> -                               factory =
> OMAbstractFactory.getSOAP12Factory();
> -                       } else {
> -                               factory =
> OMAbstractFactory.getSOAP11Factory();
> -                       }
> -
> -               } else {
> -                       factory = OMAbstractFactory.getSOAP11Factory();
> -               }
> -               try {
> -                       OMDocument soapFaultDocument =
> factory.createOMDocument();
> -                       SOAPEnvelope faultEnvelope =
> factory.getDefaultFaultEnvelope();
> -                       soapFaultDocument.addChild(faultEnvelope);
> -                       smc.setEnvelope(faultEnvelope);
> -               } catch (Exception e) {
> -                       throw new SynapseException(e);
> -               }
> -               smc.setResponse(true);
> -
> -               // Flipping the headers
> -               EndpointReference tempEPR = smc.getTo();
> -               smc.setTo(smc.getReplyTo());
> -               smc.setReplyTo(tempEPR);
> +    private Log log = LogFactory.getLog(getClass());
>
> -               smc.getSynapseEnvironment().injectMessage(smc);
> +    private QName faultCode;
> +    private String reason;
>
> -               return false;
> -       }
> +    public boolean mediate(SynapseMessage smc) {
> +        log.debug("process");
>
> +        SOAPEnvelope envelop = smc.getEnvelope();
> +        SOAPFactory factory;
> +        if (envelop != null) {
> +            if (envelop.getNamespace().getName().equals(
> +                    SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
> +                factory = OMAbstractFactory.getSOAP12Factory();
> +            } else {
> +                factory = OMAbstractFactory.getSOAP11Factory();
> +            }
> +
> +        } else {
> +            factory = OMAbstractFactory.getSOAP11Factory();
> +        }
> +        try {
> +            // TODO : Figure out how to easily gen the correct fault
> +
> +            // Replace this
> +            OMDocument soapFaultDocument = factory.createOMDocument();
> +            SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope
> ();
> +            soapFaultDocument.addChild(faultEnvelope);
> +
> +            smc.setEnvelope(faultEnvelope);
> +        } catch (Exception e) {
> +            throw new SynapseException(e);
> +        }
> +        smc.setResponse(true);
> +
> +        // Flipping the headers
> +        EndpointReference tempEPR = smc.getTo();
> +        smc.setTo(smc.getReplyTo());
> +        smc.setReplyTo(tempEPR);
> +
> +        smc.getSynapseEnvironment().injectMessage(smc);
> +
> +        return false;
> +    }
> +
> +    public QName getFaultCode() {
> +        return faultCode;
> +    }
> +
> +    public void setFaultCode(QName faultCode) {
> +        this.faultCode = faultCode;
> +    }
> +
> +    public String getReason() {
> +        return reason;
> +    }
> +
> +    public void setReason(String reason) {
> +        this.reason = reason;
> +    }
> }
>
> Modified:
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/RegexMediator.java
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/RegexMediator.java?rev=393790&r1=393789&r2=393790&view=diff
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/RegexMediator.java
> (original)
> +++
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/RegexMediator.java
> Thu Apr 13 05:15:58 2006
> @@ -74,7 +74,8 @@
>                         log.debug("trying to process with empty pattern");
>                         return true;
>                 }
> -               String toMatch = null;
> +
> +        String toMatch;
>                 if (property != null) {
>                         toMatch = smc.getProperty(property).toString();
>                 } else {
> @@ -84,11 +85,18 @@
>                 if (toMatch==null) return false;
>
>                 if (pattern.matcher(toMatch).matches()) {
> -                       log.debug("Regex pattern " + pattern.toString() +
> " matched "
> -                                       + toMatch);
> +            if (log.isDebugEnabled()) {
> +                log.debug("Regex pattern " + pattern.pattern() + "
> matched "
> +                        + toMatch);
> +            }
>              return true;
>                 }
> -               return false;
> +
> +        if (log.isDebugEnabled()) {
> +            log.debug("Regex pattern '" + pattern.pattern() +
> +                    "' failed to match '" + toMatch);
> +        }
> +        return false;
>         }
>
> }
>
> Modified:
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/FaultMediatorFactory.java
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/FaultMediatorFactory.java?rev=393790&r1=393789&r2=393790&view=diff
>
> ==============================================================================
> ---
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/FaultMediatorFactory.java
> (original)
> +++
> incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/xml/FaultMediatorFactory.java
> Thu Apr 13 05:15:58 2006
> @@ -33,16 +33,27 @@
>      private static final QName HEADER_Q = new QName(
>              Constants.SYNAPSE_NAMESPACE, "fault");
>
> -
> -
> +    private static final QName FAULTCODE = new QName(
> +            Constants.SYNAPSE_NAMESPACE, "faultCode");
> +    private static final QName REASON = new QName(
> +            Constants.SYNAPSE_NAMESPACE, "reason");
>
>      public Mediator createMediator(SynapseEnvironment se, OMElement el) {
>          FaultMediator fp = new FaultMediator();
> +
> +        OMElement code = el.getFirstChildWithName(FAULTCODE);
> +        if (code != null) {
> +            fp.setFaultCode(code.getTextAsQName());
> +        }
> +        OMElement reason = el.getFirstChildWithName(REASON);
> +        if (reason != null) {
> +            fp.setReason(reason.getText());
> +        }
>          super.setNameOnMediator(se, el, fp);
>          return fp;
>      }
>
> -        public QName getTagQName() {
> +    public QName getTagQName() {
>          return HEADER_Q;
>      }
>
>
> Modified: incubator/synapse/trunk/java/repository/conf/synapse.xml
> URL:
> http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/repository/conf/synapse.xml?rev=393790&r1=393789&r2=393790&view=diff
>
> ==============================================================================
> --- incubator/synapse/trunk/java/repository/conf/synapse.xml (original)
> +++ incubator/synapse/trunk/java/repository/conf/synapse.xml Thu Apr 13
> 05:15:58 2006
> @@ -6,7 +6,7 @@
>         <log/>
>
>      <!-- Check if the URL matches the stockquote gateway/dumb case -->
> -       <regex message-address="to" pattern="/StockQuote.*">
> +       <regex message-address="to" pattern=".*/StockQuote.*">
>                 <ref ref="stockquote"/>
>         </regex>
>
> @@ -26,7 +26,9 @@
>              <!-- check if the symbol is MSFT -->
>              <xpath expr="//*[wsx:symbol='MSFT']" xmlns:wsx="
> http://www.webserviceX.NET/">
>                  <!-- if it is throw a fault -->
> -                <fault/>
> +                <fault>
> +                    <reason>Isn't there a Windows API for that?</reason>
> +                </fault>
>              </xpath>
>          </stage>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: synapse-dev-help@ws.apache.org
>
>


--
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

Mime
View raw message