<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
  ~  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.
  -->

<document>
    <properties>
        <title>Apache Synapse - Sample 5</title>
    </properties>
    <body>
        <section name="Sample 5: Creating SOAP Faults and Changing the Direction of Messages">
            <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="myFaultHandler"&gt;
        &lt;makefault response="true"&gt;
            &lt;code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/&gt;
            &lt;reason expression="get-property('ERROR_MESSAGE')"/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

    &lt;sequence name="main" onError="myFaultHandler"&gt;
        &lt;in&gt;
            &lt;switch xmlns:m0="http://services.samples" source="//m0:getQuote/m0:request/m0:symbol"&gt;
                &lt;case regex="MSFT"&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;
                            &lt;address uri="http://bogus:9000/services/NonExistentStockQuoteService"/&gt;
                        &lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
                &lt;case regex="SUN"&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;
                            &lt;address uri="http://localhost:9009/services/NonExistentStockQuoteService"/&gt;
                        &lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
            &lt;/switch&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</div>
            <subsection name="Objective">
                <p>
                    Demonstrating how makefault mediator can be used to construct custom SOAP
                    faults and change the direction (in/out) of messages.
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>                        
                        <li>
                            Start Synapse using the configuration numbered 5 (repository/conf/sample/synapse_sample_5.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 5<br/>
                                Windows: synapse.bat -sample 5
                            </div>
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>
                    When the MSFT stock quote is requested, an unknown host exception would be
                    generated. A connection refused exception would be generated for the SUN stock
                    request. These errors are captured and returned to the original client as a SOAP
                    fault in this example.
                </p>
                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT</div>
                <p>returns,</p>
                <div class="consoleOutput">&lt;soapenv:Fault xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
    &lt;faultcode&gt;soapenv:Client&lt;/faultcode&gt;
    &lt;faultstring&gt;java.net.UnknownHostException: bogus&lt;/faultstring&gt;
    &lt;detail /&gt;
&lt;/soapenv:Fault&gt;</div>
                <p>And </p>
                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN</div>
                <p>returns, </p>
                <div class="consoleOutput">&lt;soapenv:Fault xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
    &lt;faultcode&gt;soapenv:Client&lt;/faultcode&gt;
    &lt;faultstring&gt;java.net.ConnectException: Connection refused&lt;/faultstring&gt;
    &lt;detail /&gt;
&lt;/soapenv:Fault&gt;</div>
                <p>
                    Note that the response attribute is set to 'true' on the makefault mediator.
                    This instructs the mediator to change the direction of messages to 'response'
                    as messages are transformed into SOAP faults.
                </p>
            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>
    </body>
</document>