Spring DSL for Synapse

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Charith Wickramarachchi
  • 16 Feb, 2009

Abstract

Spring framework is a light weight framework for developing java applications in which its core or commonly known as Spring Core is all about inversion of control. Using the inversion of Control capability provided by Spring we can separate module dependencies from the application logic and leave creation of those dependencies to the Spring framework. Spring uses the technique named Dependency injection to inject those dependencies to the application. Using Springs Dependency injection capability we can populate a object Structure of Spring beans using a XML file. So Idea here is to use Springs this feature to start Synapse in Spring-core and make it configurable in Spring syntax.

Table of Contents

Introduction

 Apache synapse is a Enterprise service bus for XML webservices which consists of a asynchronous core. It consists of several configuration files which enable users to control the of synapse in a desirable way. The main configurations that drives the synapse ESB are

 

  • The Synapse configuration file – synapse.xml

  • Underline Axis2 Configuration file – axis2.xml

  • The Registry resources

Synapse.xml is the file that used to configure synapse Mediation rules ,Proxies ect. It uses its own configuration language (Synapse Configuration language ) to do the configuration.

Since synapse is a Axis2 module axis2.xml is used to configure the transports and webservices support.

Synapse Configuration consist of following main top level configurations

  • Sequences

  • Proxy Services

  • Startup jobs

  • Registry

  • Local registry

  • Endpoints

 

a good description about synapse configuration language can be found at [3]

Synapse design is inherently a very extensible one which allow users to write there custom mediators endpoints etc .. and also it has given the capability to configure synapse in other XML DSL s other than the synapse Configuration Language.

Architecture and Implementation over view.

Following is an abstract overview of the project Architecture. It shows how this add on is plugged in to Synapse.

 

As the above diagram shows the axis2Config.xml written in Spring configuration will be used to build the Configuration context for synapse. It is build from the Spring ApplicationContext which get build inside a web application container The Configuration Context build from that will be used by the Server manger to start synapse in that context. Then at the synapse initialization phase Apache synapse will find the SynapseSpringXMLConfigurationfactory and build the Synapse Configuration it need.

Spring - DSL

Synapse Configuration is ultimately a Object hierarchy in the Run time which is build from the Configuration factories inside the synapse. Idea of a Spring DSL is to use the Spring Framework dependency injection capability and build that Object structure using a Spring XML configuration.Its is a great advantage to the Spring users who are comfortable in Spring syntax.

The main advantages of using a Spring DSL for synapse are follows as I see :

  1. No need to learn the Synapse Configuration language

At the end what synapse configuration language does is populating synapse Configuration Object structure. But people who are comfortable in spring will be able to do that using their own Spring XML. So that configuration will be much more transparent and extensible to the users

  1. User will be able to user the IDE support for configuration

Since Spring XML configuration is supported by many modern IDEs users will be able to easily configure Synapse with the IDE support.

  1. User will be able to extend the synapse easily.

    With the Spring configuration users can easily add there Spring Beans as mediators ,Endpoints ,Tasks to the Synapse with out much of effort. All they have to do is put there custom Spring Bean mediator ,Endpoint ,Task in class path and populate them in the Synapse Spring configuration xml and give a bean ref to desired place in the configuration.

This product not only use Spring to configure synapse but also it uses a Spring to Build the Underlying Axis2 Context using Spring. So that Spring core will build the Axis2 Context and Start it using that context build from Spring.So the spring users will find it easy to learn the underlying axis2configuration.

Spring Configuration Serializer

 Serializing the Synapse configuration to spring xml configuration is also a added feature to this which serialize the synapse configuration at run time to the Spring xml configuration. It can also serialize the the custom beans that are plugged to the Synapse configuration as Mediators ,Endpoints etc. But to be able to serialized by this they must follow the pojo conventions .( Must have proper setters and getters ).
 

How to Use

 As above Diagram shows Synapse/Spring uses two Spring artifacts axis2.xml and  synapse.xml . synapse.xml is the Synapse Configuration file that is used to Configure Synapse in Spring and axis2.xml is used to configure Axis2 in Spring .
To use Synapse /Spring first users must copy the  synapse.war to the webapplication deployment directory and extract it then users must edit the web.xml  in the WEB-INF directory following is an example web.xml file which is edited to use Synapse in Spring mode.

<?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.
 */
  -->

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <display-name>Apache Synapse</display-name>
	<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>/WEB-INF/conf/axis2.xml</param-value>
  </context-param>
   
    <servlet>
        <servlet-name>StartUpServlet</servlet-name>
        <servlet-class>org.wso2.spring.esb.synapse.SynapseSpringStartUpServlet</servlet-class>

        <!-- The following init parameters are *required* to start the ESB -->
        <!-- They must be configured correctly here, or made available as Java System Properties -->

        <!-- Synapse currently only supports the extracted WAR deployment model. Thus you need
        to extract the synapse.war to a directory, and then configure your servlet engine to
        deploy it off the file system.

        At a minimum, the synapse.home parameter must be specified, as the full and
        absolute path to the extracted synapse.war file. You must also edit the axis2.xml
        inside the WEB-INF/conf directory, and specify full absolute paths to all https
        keystores (e.g. replace "lib/identity.jks" etc..) You may also have to change the
        default http port (8280) to something else, if it conflict with the servlet engine port-->
        <init-param>
            <param-name>synapse.home</param-name>
            <param-value>/home/charith/software/apache-tomcat-6.0.18/webapps/synapse</param-value>
        </init-param>
        <init-param>
            <param-name>synapse.xml</param-name>
            <param-value>WEB-INF/conf/synapse.xml</param-value>
        </init-param>
        <init-param>
            <param-name>axis2.repo</param-name>
            <param-value>WEB-INF/repository</param-value>
        </init-param>
        <init-param>
            <param-name>axis2.xml</param-name>
            <param-value>WEB-INF/conf/axis2.xml</param-value>
        </init-param>
        <init-param>
            <param-name>resolve.root</param-name>
            <param-value>WEB-INF/repository</param-value>
        </init-param>
        <!--<init-param>
            <param-name>serverName</param-name>
            <param-value>localhost</param-value>
        </init-param>-->
	 <init-param>
            <param-name>springStartEnable</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>SynapseServlet</servlet-name>
        <servlet-class>org.apache.synapse.core.axis2.SynapseAxisServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>SynapseServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <!-- 30 minutes -->
        <session-timeout>30</session-timeout>
    </session-config>


</web-app>

As shown in above example we set a Spring Context Loader Listener and set axis2t.xml as a Context parameter to that. So when the web application get deployed SynapseStartupServlet get the Spring ApplicationContext which is created form the axis2.xml and use that to create the Axis2 Context and start synapse in that context.

Following are sample axis2 configuration and Spring Configuration done in Spring

Sample axis2 Configuration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
 
<bean id="axisConfig" class="org.wso2.spring.esb.SpringAxisConfiguration">
		<property name="parameters">
			<list> 
				<bean id="hd" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="hotdeployment"></property>
					<property name="value" value="false"></property>
 
				</bean>
				<bean id="hu" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="hotupdate"></property>
					<property name="value" value="false"></property>
				</bean>				
				
				<bean id="eMTOM" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="enableMTOM"></property>
					<property name="value" value="false"></property>
				</bean>
 
				<bean id="eSwA" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="enableSwA"></property>
					<property name="value" value="false"></property>
				</bean>
				
				<bean id="timeOut" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="ConfigContextTimeoutInterval"></property>
					<property name="value" value="30000"></property>
				</bean>
 
				<bean id="stacktrace" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="sendStacktraceDetailsWithFaults"></property>
					<property name="value" value="false"></property>
				</bean>
				<bean id="drillFaultReason" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="DrillDownToRootCauseForFaultReason"></property>
					<property name="value" value="false"></property>
				</bean>
				<bean id="username" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="userName"></property>
					<property name="value" value="admin"></property>
				</bean>
				<bean id="passwd" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="password"></property>
					<property name="value" value="axis2"></property>
				</bean>
				<bean id="disRest" class="org.wso2.spring.esb.beans.ParameterBean">
					<property name="name" value="disableREST"></property>
					<property name="value" value="false"></property>
					<property name="locked" value="true"></property>
				</bean>
 
			</list>
 
		</property>
		<property name="messageReceivers">
			<list>
				<ref bean="axis2MsgReceiverIN"/>
				<ref bean="axis2MsgReceiverINOUT"/>
				<ref bean="axis2MsgReceiverIN2"/>
				<ref bean="axis2MsgReceiverINOUT2"/>
			</list>
		</property>
		<property name="messageFormatters">
			<list>
				<ref bean="axis2MsgFormatterURL"/>
				<ref bean="axis2MsgFormatterForm"/>
				<ref bean="axis2MsgFormatterXML"/>
			</list>
		</property>
		<property name="messageBuilders">
			<list>
				<ref bean="axis2MsgBuilderURL"/>
				<ref bean="axis2MsgBuilderForm"/>
				<ref bean="axis2MsgBuilderXML"/>
			</list>
		</property>
		<property name="transportReceivers">
			<list>
				<ref bean="axis2TransportReceiver"/>
				<ref bean="axis2HttpsTransportReceiver"/>
                                <ref bean="axis2MailToTransportReceiver"/> 
			</list>
		</property>
		<property name="transportSenders">
			<list>
				<ref bean="axis2TransportSender"/>
				<ref bean="axis2HttpsTransportSender"/>
				<ref bean="axis2JMSTransportSender"/>
			</list>
		</property>

		<property name="modules">
			<list>
				<value>addressing</value>
				<value>synapse</value>
			</list>
		</property>
		<property name="phaseOrders">
			<list>
				<ref bean="axis2InPhaseOrder"/>
				<ref bean="axis2InFaultPhaseOrder"/>
				<ref bean="axis2OutPhaseOrder"/>
				<ref bean="axis2OutFaultPhaseOrder"/>
			</list>
		</property>
 
	</bean>
 
	<!-- Message Receiver definitions -->
 
	<bean id="axis2MsgReceiverIN" class="org.wso2.spring.esb.beans.MessageReceiverBean">
		<property name="mep" value="http://www.w3.org/2004/08/wsdl/in-only"></property>
		<property name="clazz" value="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"></property>
	</bean>
	<bean id="axis2MsgReceiverINOUT" class="org.wso2.spring.esb.beans.MessageReceiverBean">
		<property name="mep" value="http://www.w3.org/2004/08/wsdl/in-out"></property>
		<property name="clazz" value="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"></property>
	</bean>
	<bean id="axis2MsgReceiverIN2" class="org.wso2.spring.esb.beans.MessageReceiverBean">
		<property name="mep" value="http://www.w3.org/2006/01/wsdl/in-only"></property>
		<property name="clazz" value="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"></property>
	</bean>
	<bean id="axis2MsgReceiverINOUT2" class="org.wso2.spring.esb.beans.MessageReceiverBean">
		<property name="mep" value="http://www.w3.org/2006/01/wsdl/in-out"></property>
		<property name="clazz" value="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"></property>
	</bean>
 
 
 
	<!-- Message Formatter Definitions -->
 
	<bean id="axis2MsgFormatterURL" class="org.wso2.spring.esb.beans.MessageFormatterBean">
		<property name="contentType" value="application/x-www-form-urlencoded"></property>
		<property name="clazz" value="org.apache.axis2.transport.http.XFormURLEncodedFormatter"></property>
	</bean>
	<bean id="axis2MsgFormatterForm" class="org.wso2.spring.esb.beans.MessageFormatterBean">
		<property name="contentType" value="multipart/form-data"></property>
		<property name="clazz" value="org.apache.axis2.transport.http.MultipartFormDataFormatter"></property>
	</bean>
	<bean id="axis2MsgFormatterXML" class="org.wso2.spring.esb.beans.MessageFormatterBean">
		<property name="contentType" value="application/xml"></property>
		<property name="clazz" value="org.apache.axis2.transport.http.ApplicationXMLFormatter"></property>
	</bean>
 
 
 
	<!-- Message Builder Definitions -->
 
	<bean id="axis2MsgBuilderXML" class="org.wso2.spring.esb.beans.MessageBuilderBean">
		<property name="contentType" value="application/xml"></property>
		<property name="clazz" value="org.apache.axis2.builder.ApplicationXMLBuilder"></property>
	</bean>
	<bean id="axis2MsgBuilderURL" class="org.wso2.spring.esb.beans.MessageBuilderBean">
		<property name="contentType" value="application/x-www-form-urlencoded"></property>
		<property name="clazz" value="org.apache.axis2.builder.XFormURLEncodedBuilder"></property>
	</bean>
	<bean id="axis2MsgBuilderForm" class="org.wso2.spring.esb.beans.MessageBuilderBean">
		<property name="contentType" value="multipart/form-data"></property>
		<property name="clazz" value="org.apache.axis2.builder.MultipartFormDataBuilder"></property>
	</bean>
 
 
	<!-- Transport Receiver Definitions -->
 
	<bean id="axis2TransportReceiver" class="org.wso2.spring.esb.beans.TransportReceiverBean">
		<property name="name" value="http"></property>
		<property name="clazz" value="org.apache.synapse.transport.nhttp.HttpCoreNIOListener"></property>
		<property name="parameters">
			<map>
				<entry key="port">

                    <bean class="org.wso2.spring.esb.beans.ParameterBean">
                        <property name="name" value="port"/>
                        <property name="value" value="8280"/>
                    </bean>


                </entry>
                <entry key="non-blocking">
                     <bean class="org.wso2.spring.esb.beans.ParameterBean">
                         <property name="name" value="non-blocking"/>
                         <property name="locked" value="false"/>
                         <property name="value"  value="true"/> 
                     </bean>
                </entry>

            </map>
		</property>
	</bean>
    <bean id="axis2HttpsTransportReceiver" class="org.wso2.spring.esb.beans.TransportReceiverBean">
        <property name="name" value="https"/>
        <property name="clazz" value="org.apache.synapse.transport.nhttp.HttpCoreNIOSSLListener"/>
        <property name="parameters">
            <map>
                  <entry key="port">

                    <bean class="org.wso2.spring.esb.beans.ParameterBean">
                        <property name="name" value="port"/>
                        <property name="value" value="8243"/>
                    </bean>


                </entry>
                <entry key="non-blocking">
                     <bean class="org.wso2.spring.esb.beans.ParameterBean">
                         <property name="name" value="non-blocking"/>
                         <property name="locked" value="false"/>
                         <property name="value"  value="true"/>
                     </bean>
                </entry>

                <entry key="keystore">
                    <bean class="org.wso2.spring.esb.beans.ParameterBean">
                        <property name="locked" value="false"/>
                        <property name="name" value="keystore"/>
                        <property name="omParameter" value="true"/>
                        <property name="xmlFragment"> <value>
                            <![CDATA[
				<parameter name="keystore" locked="false">
           			  <KeyStore>
                			<Location>/home/charith/software/apache-tomcat-6.0.18/webapps/synapse/WEB-INF/lib/identity.jks</Location>
                			<Type>JKS</Type>
                			<Password>password</Password>
                			<KeyPassword>password</KeyPassword>
            		          </KeyStore>
        			</parameter>
                            ]]>
                        </value></property>

                    </bean>
                </entry>
                
                <entry key="truststore">
                    <bean class="org.wso2.spring.esb.beans.ParameterBean">
                        <property name="locked" value="false"/>
                        <property name="name" value="truststore"/>
                        <property name="omParameter" value="true"/>
                        <property name="xmlFragment"><value>
                            <![CDATA[
                            <parameter name="truststore" locked="false">
           			 <TrustStore>
                			<Location>/home/charith/software/apache-tomcat-6.0.18/webapps/synapse/WEB-INF/lib/trust.jks</Location>
                			<Type>JKS</Type>
               				 <Password>password</Password>
            			</TrustStore>
        		</parameter>

]]>
                        </value></property>

                    </bean>
                </entry>
            </map>
        </property>

    </bean>
     <bean id="axis2MailToTransportReceiver" class="org.wso2.spring.esb.beans.TransportReceiverBean">
		<property name="name" value="mailto"></property>
		<property name="clazz" value="org.apache.axis2.transport.mail.MailTransportListener"></property>
	</bean>
 
	<!-- Transport Sender Definitions -->
 
	<bean id="axis2TransportSender" class="org.wso2.spring.esb.beans.TransportSenderBean">
		<property name="name" value="http"></property>
		<property name="clazz" value="org.apache.synapse.transport.nhttp.HttpCoreNIOSender"></property>
		
	</bean>
    <bean id="axis2HttpsTransportSender" class="org.wso2.spring.esb.beans.TransportSenderBean">
        <property name="name" value="https"/>
        <property name="clazz" value="org.apache.synapse.transport.nhttp.HttpCoreNIOSSLSender"/>
        <property name="parameters">
            <map>
              <entry key="non-blocking">
                     <bean class="org.wso2.spring.esb.beans.ParameterBean">
                         <property name="name" value="non-blocking"/>
                         <property name="locked" value="false"/>
                         <property name="value"  value="true"/>
                     </bean>
                </entry>

                   <entry key="keystore">
                    <bean class="org.wso2.spring.esb.beans.ParameterBean">
                        <property name="locked" value="false"/>
                        <property name="name" value="keystore"/>
                        <property name="omParameter" value="true"/>
                        <property name="xmlFragment"> <value>
                            <![CDATA[
                           <parameter name="keystore" locked="false">
           			 <KeyStore>
               				 <Location>/home/charith/software/apache-tomcat-6.0.18/webapps/synapse/WEB-INF/lib/identity.jks</Location>
                			<Type>JKS</Type>
                			<Password>password</Password>
                			<KeyPassword>password</KeyPassword>
           			 </KeyStore>
        		   </parameter>

				]]>
                        </value></property>

                    </bean>
                </entry>

               <entry key="truststore">
                    <bean class="org.wso2.spring.esb.beans.ParameterBean">
                        <property name="locked" value="false"/>
                        <property name="name" value="truststore"/>
                        <property name="omParameter" value="true"/>
                        <property name="xmlFragment"><value>
                            <![CDATA[
                           <parameter name="truststore" locked="false">
           			 <TrustStore>
                			<Location>/home/charith/software/apache-tomcat-6.0.18/webapps/synapse/WEB-INF/lib/trust.jks</Location>
               	 			<Type>JKS</Type>
                			<Password>password</Password>
          			  </TrustStore>
       			 </parameter>
			]]>
                        </value></property>

                    </bean>
                </entry>
                    
            </map>
        </property>

    </bean>

     <bean id="axis2JMSTransportSender" class="org.wso2.spring.esb.beans.TransportSenderBean">
		<property name="name" value="jms"/>
		<property name="clazz" value="org.apache.axis2.transport.jms.JMSSender"/>

	</bean>
	<!-- <bean id="axis2TransportSenderTCP" class="org.wso2.spring.esb.beans.TransportSenderBean">
		<property name="name" value="tcp"></property>
		<property name="clazz" value="org.apache.axis2.transport.tcp.TCPTransportSender"></property>
	</bean>
 
	<bean id="axis2TransportSenderlocal" class="org.wso2.spring.esb.beans.TransportSenderBean">
		<property name="name" value="local"></property>
		<property name="clazz" value="org.apache.axis2.transport.local.LocalTransportSender"></property>
	</bean>
 
	<bean id="axis2TransportSenderHTTPS" class="org.wso2.spring.esb.beans.TransportSenderBean">
		<property name="name" value="https"></property>
		<property name="clazz" value="org.apache.axis2.transport.http.CommonsHTTPTransportSender"></property>
		<property name="parameters">
			<map>
				<entry key="PROTOCOL" value="HTTP/1.1" />
				<entry key="Transfer-Encoding" value="chunked" />
			</map>
		</property>
	</bean> -->
 
	<!-- Addressing phase definition -->
 
	<bean id="axis2AddressingPhase" class="org.wso2.spring.esb.beans.PhaseBean">
		<property name="name" value="Addressing"></property>
		<property name="handlers">
			<list>
				<ref bean="addressingHandler"/>
			</list>
		</property>
	</bean>
 
	<!-- Addressing handler -->
 
	<bean id="addressingHandler" class="org.wso2.spring.esb.beans.HandlerBean">
		<property name="name" value="AddressingBasedDispatcher"></property>
		<property name="clazz" value="org.apache.axis2.dispatchers.AddressingBasedDispatcher"></property>
		<property name="orderPhase" value="Addressing"></property>
 
	</bean>
 
	<!-- In Phase Order definition -->
 
	<bean id="axis2InPhaseOrder" class="org.wso2.spring.esb.beans.PhaseOrderBean">
		<property name="phaseOrderType" value="InFlow"></property>
		<property name="phases">
			<list>
				<ref bean="axis2TransportPhase"/>
				<ref bean="axis2AddressingPhase"/>
				<ref bean="security"/>
				<ref bean="preDispatchPhase"/>
				<bean id="InDispatchPhase" class="org.wso2.spring.esb.beans.PhaseBean">
					<property name="name" value="Dispatch"></property>
					<property name="clazz" value="org.apache.axis2.engine.DispatchPhase"></property>
					<property name="handlers">
						<list>
							<ref bean="RequestURI"/>
							<ref bean="SOAPAction"/>
							<ref bean="RequestURIOperation"/>
							<ref bean="SOAPMessageBody"/>
							<ref bean="HTTPLocationBased"/>
						</list>
					</property>
				</bean>
 
			</list>
		</property>
	</bean>
 
 
	<!--  Transport Phase -->
 
	<bean id="axis2TransportPhase" class="org.wso2.spring.esb.beans.PhaseBean">
		<property name="name" value="Transport"></property>
		<property name="handlers">
		<list>
				<bean id="URIBasedDispather" class="org.wso2.spring.esb.beans.HandlerBean">
					<property name="name" value="RequestURIBasedDispatcher"></property>
					<property name="clazz" value="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"></property>
					<property name="orderPhase" value="Transport"></property>
				</bean>
 
 
				<bean id="ActionBasedDispatcher" class="org.wso2.spring.esb.beans.HandlerBean">
					<property name="name" value="SOAPActionBasedDispatcher"></property>
					<property name="clazz" value="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"></property>


					<property name="orderPhase" value="Transport"></property>
				</bean>
 
		</list>
		</property>
	</bean>
 
	<!-- Common handlers for InDispatch Phase of In and InFault Phase Orders -->
 
	<bean id="RequestURI" class="org.wso2.spring.esb.beans.HandlerBean">
		<property name="name" value="RequestURIBasedDispatcher"></property>
		<property name="clazz"
			value="org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
		</property>
	</bean>
	<bean id="SOAPAction" class="org.wso2.spring.esb.beans.HandlerBean">
		<property name="name" value="SOAPActionBasedDispatcher"></property>
		<property name="clazz"
			value="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher">
		</property>
	</bean>
	<bean id="RequestURIOperation" class="org.wso2.spring.esb.beans.HandlerBean">
		<property name="name" value="RequestURIOperationDispatcher"></property>
		<property name="clazz"
			value="org.apache.axis2.dispatchers.RequestURIOperationDispatcher">
		</property>
	</bean>
	<bean id="SOAPMessageBody" class="org.wso2.spring.esb.beans.HandlerBean">
		<property name="name" value="SOAPMessageBodyBasedDispatcher"></property>
		<property name="clazz"
			value="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher">
		</property>
	</bean>
	<bean id="HTTPLocationBased" class="org.wso2.spring.esb.beans.HandlerBean">
		<property name="name" value="HTTPLocationBasedDispatcher"></property>
		<property name="clazz"
			value="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher">
		</property>
	</bean>
 
 
	<!-- In Fault Phase Order definition -->
 
	<bean id="axis2InFaultPhaseOrder" class="org.wso2.spring.esb.beans.PhaseOrderBean">
		<property name="phaseOrderType" value="InFaultFlow"></property>
		<property name="phases">
			<list>
				<ref bean="axis2AddressingPhase"/>
				<ref bean="security"/>
				<ref bean="preDispatchPhase"/>
				<bean id="InFaultDispatchPhase" class="org.wso2.spring.esb.beans.PhaseBean">
					<property name="name" value="Dispatch"></property>
					<property name="clazz" value="org.apache.axis2.engine.DispatchPhase"></property>
					<property name="handlers">
						<list>
							<ref bean="RequestURI"/>
							<ref bean="SOAPAction"/>
							<ref bean="RequestURIOperation"/>
							<ref bean="SOAPMessageBody"/>
							<ref bean="HTTPLocationBased"/>
						</list>
					</property>
				</bean>
			</list>
		</property>
	</bean>
 
 
	<!-- Pre Dispatch Phase -->
 
	<bean id="preDispatchPhase" class="org.wso2.spring.esb.beans.PhaseBean">
		<property name="name" value="PreDispatch"></property>
	</bean>
 
 
	<!-- Out Phase Order definition -->
 
	<bean id="axis2OutPhaseOrder" class="org.wso2.spring.esb.beans.PhaseOrderBean">
		<property name="phaseOrderType" value="OutFlow"></property>
		<property name="phases">
			<list>
				<ref bean="messageOut" />
				<ref bean="security" />
			</list>
		</property>
	</bean>
 
 
	<!-- Out Fault Phase Order definition -->
 
	<bean id="axis2OutFaultPhaseOrder" class="org.wso2.spring.esb.beans.PhaseOrderBean">
		<property name="phaseOrderType" value="OutFaultFlow"></property>
		<property name="phases">
			<list>
				<ref bean="messageOut" />
				<ref bean="security" />
			</list>
		</property>
	</bean>
 
 
	<!--  Message out phase (Common for Out and Out Fault Phases) -->
 
	<bean id="messageOut" class="org.wso2.spring.esb.beans.PhaseBean">
		<property name="name" value="MessageOut"></property>
	</bean>
 
	<bean id="security" class="org.wso2.spring.esb.beans.PhaseBean">
		<property name="name" value="Security" />
	</bean>
 
</beans>

 

Sample Synapse Configuration

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"  "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

  <bean id="synapseConfiguration" class="org.wso2.spring.esb.synapse.SynapseConfiguration">
      <property name="sequence">
          <map>
              <entry key="main">
                  <bean class="org.apache.synapse.mediators.base.SequenceMediator">
                      <property name="name" value="main"/>
                      <property name="list">
                          <list>
                              <ref bean="in"/>
                              <ref bean="send"/>
                          </list>
                      </property>
                  </bean>
              </entry>

          </map>
      </property>
  </bean>


 <bean id="in" class="org.apache.synapse.mediators.filters.InMediator">
     <property name="list">
         <list>
             <bean class="org.apache.synapse.mediators.transform.HeaderMediator">
                 <property name="QName">
                     <bean class="javax.xml.namespace.QName">
                         <constructor-arg value="To"/>
                     </bean>
                 </property>
                 <property name="value" value="http://localhost:9000/services/SimpleStockQuoteService"/>
             </bean>
         </list>
     </property>
 </bean>

<bean id="send" class="org.apache.synapse.mediators.builtin.SendMediator"/>
</beans>

Conclusion

In this artical we looked at an Intoduction to Spring DSL for Synapse project and how it will  going to fit in to the Synapse and how we can use Spring Configuration for Synapse.

 

References

  1. Apache Synapse : http://synapse.apache.org/
  2. Pro Spring by Rob Harrop and Jan Machacek
  3. Syapse configuration language: http://synapse.apache.org/Synapse_Configuration_Language.html

 

Author

Charith Danushka Wikramarachchi

Student, University of Moratuwa

 

About Author

  • Charith Wickramarachchi
  • Software Engineer
  • WSO2