This documentation is work in progress and will be released with the next WSO2 EI version.
Sample 470: How to Initialize and use a Spring Bean as a Mediator - WSO2 Enterprise Integrator 6.x.x - WSO2 Documentation

All docs This doc
||
Skip to end of metadata
Go to start of metadata

Note

Please note that this feature is deprecated.


Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:

  • <PRODUCT_HOME>/repository/samples/ directory that includes all Integration profile samples is changed to <EI_HOME>/samples/service-bus/.
  • <PRODUCT_HOME>/repository/samples/resources/ directory that includes all artifacts related to the Integration profile samples is changed to <EI_HOME>/samples/service-bus/resources/.

Objective: Demonstrate how to initialize and use a SpringBean as a mediator.

In your Synapse configuration file, add the Spring bean as shown below:

<definitions xmlns="http://ws.apache.org/ns/synapse"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd">

    <registry provider="org.apache.synapse.registry.url.SimpleURLRegistry">
        <parameter name="root">file:repository/conf/sample/resources/</parameter>
        <parameter name="cachableDuration">15000</parameter>
    </registry>

    <sequence name="main">
        <in>
            <!--Setting the Spring Mediator and its Spring Beans xml file location -->
            <!--Note that springtest is the bean id used in springCustomLogger.xml -->
            <spring:spring bean="springtest" key="spring/springCustomLogger.xml" xmlns:spring="http://ws.apache.org/ns/synapse"/>
            <send/>
        </in>
        <out/>
    </sequence>

</definitions>

In the springCustomLogger.xml file, define the Spring bean:

<!DOCTYPE beans PUBLIC  "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

   <bean id="springtest" class="samples.mediators.extensions.SpringCustomLogger" singleton="false">
	   <property name="username"><value>"Synapse User"</value></property>
	   <property name="email"><value>"usr@synapse.org"</value></property>
   </bean>

</beans>

Prerequisites:

  • Enable logging for the samples.mediators package by adding the following line to the <EI_HOME>/conf/log4j.properties file:
    log4j.category.samples.mediators=INFO
  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start it on port 9000.
  • Start the EI with sample configuration 470 as follows: wso2ei-samples -sn 470

In this sample, the Spring Bean SpringCustomLogger gets initialized using the springCustomLogger.xml file and then logs the message ID. Invoke the client as follows:

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/

If you have successfully enabled logging for the samples.mediators package, you will see an output similar to the following on the console:

    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....
  • No labels