Axis2M Spring module was designed to simplify the Axis2 web service development in Spring way. Generally it requires a service.xml descriptor file other than Spring bean definition file in order to deploy any Spring based Axis2 Web Service. Axis2M Spring module facilitates to define Axis2 Web Services and Modules within the Spring bean definition file and does not require any other files such as services.xml and module.xml. Basically Axis2M-spring module provides following features.
Generally it requires a service.xml descriptor file other than the Spring bean definition file to deploy any Spring based Axis2 Web Service. Most of the times, developers use Spring as a dependency injection ( DI) container and also to assemble and configure other frameworks components within the Spring ApplicationContext . Also another great feature provided by the Spring framework is, that you can convert pure java objects (POJOs) in to native components using spring context, as a XML configuration or Java Annotations. Qurtz scheduler and Castor data binding framework are some of the ideal examples that come under above category. Some of the web service frameworks also provide such features.
Some people comment, that Axis2 is not specifically designed for first class Spring support. But the reality is, there were no such serious design issues found in Axis2 but absence of good Spring supporting module mislead people to get such wrong impression. There were few recent efforts to fill that gap by developing a good Axis2 Spring support module , WSO2 WSF/Spring project was the first notable effort for this, WSO2 WSF/Spring framework provides way to configure Axis2 within Spring bean definition file and define web Services using Spring "bean" element. Axis2M Spring module also reuse some of the basic concepts from WSO2 WSF/Spring framework specially like it's service deployment approach but both these frameworks provide their own unique features. Axis2M Spring module does not provide any feature to configure Axis2 framework within the Spring context, it still utilizes standread axis2.xml file for configuration. With Axis2M -Spring it is possible to configure Axis2 by simply placing axis2.xml file on the CLASSPATH. One of the new features available with Axis2M Spring module is, it's ability to deploy Axis2 Modules only using Spring context. It is possible to define Axis2 modules using Spring "bean" element or <module> element. Along with that it is possible to convert POJOs in to Axis2 modules using popular Spring factory approach.
Spring XML namesapace supports is a popular trend used by the framework developers to implement Spring support for their frameworks without using Spring <bean> tag. it facilitate to define your own XML grammar for your framework that can be used within the Spring context file. Earlier Apache XBean project provided such features, but now Spring framework itself supports for this useful feature. Axis2M Spring provide two such elements called <service> and <module>.
Spring OXM is a very useful package for data binding and it provides wrappers for some of the popular frameworks like Castor , XStream , JIBX and JAXB. One of the key features with Spring OXM is, it's ability to keep Java objects as POJOs and define data banding rules using external files or Java Annotations. This enables to use Spring POJO based practices with data binding tool. Axis2 already supports wide range of data-binding frameworks but Axis2M -Spring module facilitates to achieve data binding through the Spring - OXM package . Having many alternatives is a beneficial feature for any project, Axis2M Spring-OXM module provide two new data-binding frameworks XStream and Castor support for Axis2 users. Further this will not required to generate any legacy code using tools like WSDL2JAVA.
Other than the Spring XML based configuration approach, there is a plan to supports annotations to define services and modules, but this feature will not be implemented in first few releases.
POJO Service development
Spring -OXM based service development
Module development
Step - 1
AXIS2- Spring utilize a special Servlet based on Axis2 AxisServlt. You need to define this servlet in web.xml file.
<servlet> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.axis2m.spring.servlet.SpringAxis2Servlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>
Step - 2
As usual, you have to define Spring ContextLoaderListener to load the spring context at start-up time .
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/service-app.xml</param-value> </context-param>
Above two steps are the only required configurations for this extension.
Follow the steps listed in Axis2M getting started guide and in the 2nd step select "2" instead of "1" to select Axis2M-Spring Maven archetype. This is the only modification for getting started guide.
Follow the steps listed in getting started guide and in the 2nd step select "3" instead of "1" to select Axis2M-Spring Maven archetype. This is the only modification for getting started guide.
Define Service as Spring benas.
This extension facilitates to define axis2 services as Spring bean and further does not required to have any external descriptor files such as service.xml separately .
<bean id="HelloService" class="org.axis2m.spring.beans.ServiceBean"> <property name="serviceName" value="helloService"/> <property name="serviceBean" ref="helloServiceBean"/> </bean> <bean id="helloServiceBean" class="my.HelloService" />
Define Service using namespace support with <service> element.
Spring namespace support is a one of the latest trend with spring based developments, instead of configuring everything as a bean this provide to use XML domain specific language use within the spring context file. In this case these elements are much more similar to service.xml file.
<axis:service id="helloService" name="helloService"> <axis:description>testService description</axis:description> <axis:serviceBean>helloServiceBean</axis:serviceBean> </axis:service> <bean id="helloServiceBean" class="my.HelloService" />
For more configuration options refer the configuration guide from here .
Define Module using Spring beans.
Once you have a module class that inherited from Axis2's Module and Handler classes, you can define axis2 module within the Spring configuration file and there is no need to have module.xml . Module bean is used to define Axis2 module and HandlerBean is used to define Axis2 handlers.
e.g .
<bean id="module" class="org.axis2m.spring.beans.ModuleBean"> <property name="moduleName" value="counterModule" /> <property name="moduleDescription" value="Counts the incoming and outgoing messages" /> <property name="modulebean" ref="modulebean" /> <property name="inFlowHandlers"> <list> <ref bean="inFlowHandler"/> </list> </property> <property name="outFlowHandlers"> <list> <ref bean="outFlowHandler"/> <ref bean="outFlowHandler"/> </list> </property> </bean> <bean id="modulebean" class="my.module.CounterModule"/> <bean id="inFlowHandler" class="org.axis2m.spring.beans.HandlerBean"> <property name="handlerName" value="IncomingMessageCountHandler" /> <property name="handPhsse" value="Transport" /> <property name="handlerAfter" value="RequestURIBasedDispatcher" /> <property name="handlerBefore" value="SOAPActionBasedDispatcher" /> <property name="handlerBean" ref="inFlowHandlerBean"/> </bean> <bean id="inFlowHandlerBean" class="my.module.IncomingCounterHandler"/> <bean id="outFlowHandler" class="org.axis2m.spring.beans.HandlerBean"> <property name="handlerName" value="OutgoingMessageCountHandler" /> <property name="handPhsse" value="MessageOut" /> <property name="handlerBean" ref="outFlowHandlerBean"/> </bean> <bean id="outFlowHandlerBean" class="my.module.OutgoingCounterHandler"/>
POJO based Module development.
Instead of legacy Axis2 Modules and handlers you can use POJOs and possible to configure them at run-time.
e.g -
<bean id="module" class="org.axis2m.spring.beans.ModuleBean"> <property name="moduleName" value="counterModule" /> <property name="moduleDescription" value="Counts the incoming and outgoing messages" /> <property name="moduleFactoryBean" ref="moduleFactoryBean" /> <property name="inFlowHandlerFactoryBeans"> <list> <ref bean="inFlowHandlerFactoryBean"/> <ref bean="inFlowHandlerFactoryBean2"/> </list> </property> <property name="outFlowHandlerFactoryBeans"> <list> <ref bean="outFlowHandlerFactoryBean"/> <!-- <ref bean="outFlowHandlerFactoryBean"/> --> </list> </property> </bean> <bean id="moduleFactoryBean" class="org.axis2m.spring.beans.factory.ModuleFactoryBean"> <property name="modulebean" ref="module2Bean" /> <property name="init" value="start" /> <property name="shutdown" value="stop" /> </bean> <bean id="module2Bean" class="my.module.CounterBean" /> <bean id="inFlowHandlerFactoryBean" class="org.axis2m.spring.beans.factory.HandlerFactoryBean"> <property name="name" value="IncomingMessageCountHandler" /> <property name="handlerBean" ref="inhandlerBean" /> <property name="init" value="start" /> <property name="invoke" value="doitNow" /> <property name="handPhsse" value="Transport" /> <property name="handlerAfter" value="RequestURIBasedDispatcher" /> <property name="handlerBefore" value="SOAPActionBasedDispatcher" /> </bean> <bean id="inFlowHandlerFactoryBean2" class="org.axis2m.spring.beans.factory.HandlerFactoryBean"> <property name="name" value="IncomingMessageCountHandler2" /> <property name="handlerBean" ref="inhandlerBean2" /> <property name="init" value="start" /> <property name="invoke" value="doitNow" /> <property name="handPhsse" value="Transport" /> <property name="handlerAfter" value="RequestURIBasedDispatcher" /> <property name="handlerBefore" value="SOAPActionBasedDispatcher" /> </bean> <bean id="inhandlerBean" class="my.module.IncomingCounterBean" > <property name="msgFrom" value="Spring value"/> </bean> <bean id="inhandlerBean2" class="my.module.IncomingCounterBean2" > <property name="msgFrom" value="second handler"/> </bean> <bean id="outFlowHandlerFactoryBean" class="org.axis2m.spring.beans.factory.HandlerFactoryBean"> <property name="name" value="OutgoingMessageCountHandler" /> <property name="handlerBean" ref="outhandlerBean" /> <property name="init" value="start" /> <property name="invoke" value="doit" /> <property name="handPhsse" value="MessageOut" /> </bean> <bean id="outhandlerBean" class="my.module.OutgoingCounterBean" />
<module> namspace supports for module development.
e.g - 1
<axis:module id="counterModule" name="counterModule" > <axis:description>counterModule description1</axis:description> <axis:modulebean>modulebean</axis:modulebean> <axis:inflow> <axis:handler name="IncomingMessageCountHandler" handlerBean="inFlowHandlerBean" phase="Transport" after="RequestURIBasedDispatcher" before="SOAPActionBasedDispatcher" /> </axis:inflow> <axis:outflow> <axis:handler name="OutgoingMessageCountHandler" handlerBean="outFlowHandlerBean" phase="MessageOut" /> </axis:outflow> </axis:module> <bean id="modulebean" class="my.module.CounterModule"/> <bean id="inFlowHandlerBean" class="my.module.IncomingCounterHandler"> <property name="msgFrom" value="Spring value"/> </bean> <bean id="outFlowHandlerBean" class="my.module.OutgoingCounterHandler"/>
e.g - 2
<axis:module id="counterModule" name="counterModule" > <axis:description>counterModule description1</axis:description> <axis:moduleFactoryBean modulebean="module2Bean" init="start" shutdown="stop"/> <axis:inflow> <axis:handlerFactoryBean name="IncomingMessageCountHandler" handlerBean="inhandlerBean" phase="Transport" after="RequestURIBasedDispatcher" before="SOAPActionBasedDispatcher" init="start" invoke="doitNow" flowComplete="stop" /> </axis:inflow> <axis:outflow> <axis:handlerFactoryBean name="OutgoingMessageCountHandler" handlerBean="outhandlerBean" phase="MessageOut" init="start" invoke="doit" flowComplete="stop" /> </axis:outflow> </axis:module> <bean id="module2Bean" class="my.module.CounterBean" /> <bean id="inhandlerBean" class="my.module.IncomingCounterBean" > <property name="msgFrom" value="Spring value"/> </bean> <bean id="outhandlerBean" class="my.module.OutgoingCounterBean" />
In Namespace support you can use <service>element as alone or inside the <serviceGroup> element. Also it is required to specify "id" attribute for service element for Spring specig needs ..you can use service name as the value for "id" attribute.
Bean property |
XML element |
description |
serviceName |
name (A) |
Name of the Web service |
serviceBean | <serviceBean> |
Reference to the actual bean that will expose as the web service. |
type | type(A) |
web service type either "pojo" or "oxm" default value is "pojo" |
targetNameSpace | tns(A) |
targetNameSpace value for web service |
sessionScope |
session (A) |
Axis2 specific session scope for the service |
serviceDescription | <description> |
description about the service. |
modulesStr |
<moduleRefs> |
coma separated list of module names that should enable with this web service. |
excludeOperationsStr | <excludeOperations> |
coma separated list operation names for exclusion |
policies | <policies> |
specify any related policy for the service |
policyFiles | <policyFiles> |
specify policy file for the web service . |
parameters | <parameter> |
specify Axis2 Parameters as a Map |
operation | <operation> |
specify list of operations. |
marshaller |
|
specify marshaller for Spring OXM databindings |
unmarshaller |
|
specify unmarshaller for Spring OXM databindings |
|
|
|
|
|
|
|
|
|
For detailed information about how to use and configure Spring OXM package please refer this guide
In Namespace support you can use <module> element to specify modules.
moduleName |
|
|
version |
|
Module name |
|
|
|
|
|
|
moduleDescription | <description> |
Module version |
moduleFactoryBean | <modulebean> |
for factoryBean approach this specify the bean |
modulebean | <moduleFactoryBean> |
for Axis2 module approach this specify the bean that derived from Axis2 Module class. |
supportedPolicyNamespaces |
|
specify supported Policy Namespacaces |
inFlowHandlers | <inflow> | Specify beans that derived from Axis2 Handler class as the In Flow Handlers |
outFlowHandlers | <outflow> | Specify beans that derived from Axis2 Handler class as the Out Flow Handlers |
faultInFlowHandlers | <Outfaultflow> | Specify beans that derived from Axis2 Handler class as the Fault InFlow Handlers |
faultOutFlowHandlers | <INfaultflow> | Specify beans that derived from Axis2 Handler class as the Fault Out Flow Handlers |
inFlowHandlerFactoryBeans | <inflow> | For Factory approach this specify bean to use as the In Flow Handlers |
outFlowHandlerFactoryBeans | <outflow> | For Factory approach this specify bean to use as the Out Flow Handlers. |
faultInFlowHandlerFactoryBeans | <Outfaultflow> | For Factory approach this specify bean to use as the Fault In Flow Handlers |
operation | <operation> |
|
|
|
|
faultOutFlowHandlerFactoryBeans |
|
For Factory approach this specify bean to use as the Fault Out Flow Handlers |
parameter | <parameter> |
|
handlerName |
|
|
Name of the Handler |
handlerBean |
|
|
Actual Handler bean class |
handPhsse |
|
|
|
handlerAfter |
|
|
|
handlerBefore |
|
|
|
|
|
|
|
name |
|
|
|
handlerBean |
|
|
name of the Handler |
init |
|
|
method to run with Axis2 Hanlder # init method |
invoke |
|
|
method to run with Axis2 Hanlder # invork method |
flowComplete |
|
|
method to run with Axis2 Hanlder # flowComplete method |
handPhsse |
|
|
Actual Handler bean class |
handlerAfter |
|
|
|
handlerBefore |
|
|
|
|
|
|
|
|
|
|
|