<?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 460</title>
    </properties>
    <body>
        <section name="Sample 460: Introduction to the Spring Mediator">
            <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;registry provider="org.apache.synapse.registry.url.SimpleURLRegistry"&gt;
        &lt;parameter name="root"&gt;file:repository/conf/sample/resources/&lt;/parameter&gt;
        &lt;parameter name="cachableDuration"&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;sequence name="main"&gt;
        &lt;!--Setting the Spring Mediator and its Spring Beans xml file location --&gt;
        &lt;!--Note that springtest is the bean id used in springCustomLogger.xml --&gt;
        &lt;spring bean="springtest" key="spring/springCustomLogger.xml"/&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</div>
            <p>
                This sample configuration loads an external SpringBean from a file named
                springCustomLogger.xml. Contents of this file are as follows.
            </p>
            <div class="xmlConf">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE beans PUBLIC  "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd"&gt;

&lt;beans&gt;

   &lt;bean id="springtest" class="samples.mediators.extentions.SpringCustomLogger" singleton="false"&gt;
	   &lt;property name="userName"&gt;&lt;value&gt;"Synapse User"&lt;/value&gt;&lt;/property&gt;
	   &lt;property name="email"&gt;&lt;value&gt;"usr@synapse.org"&lt;/value&gt;&lt;/property&gt;
   &lt;/bean&gt;

&lt;/beans&gt;</div>
            
            <subsection name="Objective">
                <p>
                    Demonstrate how to initialize and use a SpringBean as a mediator
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>
                        <li>
                            Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
                        </li>
                        <li>
                            Start Synapse using the configuration numbered 460 (repository/conf/sample/synapse_sample_460.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 460<br/>
                                Windows: synapse.bat -sample 460
                            </div>
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>
                    In this sample, the Spring Bean named 'SpringCustomLogger' gets loaded from the
                    springCustomLogger.xml file and then it is used to log the message ID of each
                    message being mediated. To see it in action, invoke the sample client as follows.
                </p>
                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</div>
                <p>
                    If you have enabled logging for the samples.mediators package in the log4j.properties
                    file, you will see an output similar to the following, on the console.
                </p>
                <div class="consoleOutput">2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger Starting Spring Meditor
2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger Bean in Initialized with User:["Synapse User"]
2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger E-MAIL:["usr@synapse.org"]
2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger Massage Id:  urn:uuid:383FA8B27D7CC549D91285514217720
2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger Logged....</div>
                <p>
                    Similarly you can import any SpringBean into the Synapse runtime using the
                    spring mediator, and use Spring to execute mediation rules.
                </p>
            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>        
    </body>
</document>