...
ServiceMix CXF SE
ServiceMix CXF SE component is a JBI Service Engine exposing (annotated) POJO as services on the JBI Bus.
It uses Apache CXF internally to perform service invocations and xml marshaling.
Features:
- jsr181 JSR-181 annotations
- jaxb2JAXB2/aegisAegis/xmlbeans XMLBeans databinding
- wsdl WSDL auto generation
- java Java proxy support
- MTOM / attachments support
Installation
...
- drop the installer zip in an hotdeploy directory monitored by ServiceMix
- using ant tasks
Maven Archetype
You can use the servicemix-cxf-se-service-unit archetype to create a CXF SE Service Unit (including a simple sample POJO):
Code Block |
---|
mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-cxf-se-service-unit \ -DarchetypeVersion=2010.01 \ -DgroupId=your.group.id \ -DartifactId=your.artifact.id \ -Dversion=your-version |
Deployment
You can deploy Service Units containing a file named xbean.xml for activating consumer and provider endpoints.
This xml file should respect the given syntax, though this is a spring based xml configuration file
See a full example here. Note that you have to define the cxf-se namespace with
...
<beans xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0">
...
</beans>
Once you've customized the service unit, simply install the SU:
Code Block |
---|
mvn install
|
Info | ||
---|---|---|
Remember that to be deployable in ServiceMix, the ServiceUnit has to be embedded in a Service Assembly: only the Service Assembly zip file can be deployed in ServiceMix.
|
Endpoint Configuration
The CXF SE endpoint provides a property named pojo. You can expose any POJO which contains the @WebService annotation.
A simple example follows
Any numbers of endpoints can be specified in the xbean.xml file.
As the main purpose is to expose a POJO, you will have to include the needed class files / jars in the service unit and reference them using the following tags in your xbean.xml configuration file:
Code Block | ||
---|---|---|
| ||
<classpath>
<location>.</location>
</classpath>
|
This will add the content of the location tags (relative to the unzipped service unit) to the classpath. The previous configuration will just add the class files contained in the service unit, as if it is a plain jar.
If you want to embed jars, just use something like
Code Block | ||
---|---|---|
| ||
<classpath>
<location>lib/foo.jar</location>
</classpath>
|
Endpoint
A few examples:
Code Block | ||
---|---|---|
| ||
<cxfse:endpoint> <cxfse:pojo> <bean class="org.apache.cxf.calculator.CalculatorImpl"> </bean> </cxfse:pojo> </cxfse:endpoint> |
You can use a proxy (see Proxies section of this page):
Code Block | ||
---|---|---|
| ||
<cxfse:endpoint> <cxfse:pojo> <bean class="org.apache.servicemix.cxfse.GreeterImplForClientProxy"> <property name="calculator"> <cxfse:proxy service="calculator:CalculatorService" context="#context" type="org.apache.cxf.calculator.CalculatorPortType" /> </property> </bean> </cxfse:pojo> </cxfse:endpoint> |
Info | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||
|
...
You can find a whole context injection test case here
Lightweight mode
The servicemix-cxf-se component can also be configured in a spring/xbean configuration file, for use in an embedded ServiceMix. Here is an example of such a configuration:
Code Block | ||
---|---|---|
| ||
<sm:activationSpec>
<sm:component>
<cxfse:component>
<cxfse:endpoints>
<cxfse:endpoint>
<cxfse:pojo>
<bean class="org.apache.cxf.calculator.CalculatorImpl"/>
</cxfse:pojo>
</cxfse:endpoint>
</cxfse:endpoints>
</cxfse:component>
</sm:component>
</sm:activationSpec>
|
Warning | ||
---|---|---|
| ||
When using the servicemix.xml configuration file to create cxfse endpoints, you must include the servicemix-cxfse-xxx.jar in your classpath. |
Proxies
You can create java proxies for JBI endpoints, provided that they expose a WSDL.
...
Info | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||
|
From a cxfse CXF SE Service Unit, it could be used as following:
...
MTOM is supported for the following classes:
- DataSource
- DataHandlerunmigrated-wiki-markup
- byte\[\]
If you have a bean with the following method:
...
Code Block | ||
---|---|---|
| ||
<cxfse:endpoint> <cxfse:pojo>inFaultInterceptors> <bean class="org.apache.cxf.calculatorinterceptor.CalculatorImplLoggingInInterceptor"/> </bean> </cxfse:pojo>inFaultInterceptors> <cxfse:inInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> </cxfse:inInterceptors> <cxfse:outInterceptors>outFaultInterceptors> <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> </cxfse:outInterceptors>outFaultInterceptors> <cxfse:inFaultInterceptors>outInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptorLoggingOutInterceptor"/> </cxfse:inFaultInterceptors>outInterceptors> <cxfse:outFaultInterceptors>pojo> <bean class="org.apache.cxf.interceptorcalculator.LoggingOutInterceptor"/>CalculatorImpl"> </bean> </cxfse:outFaultInterceptors>pojo> </cxfse:endpoint> |
Can find document for CXF interceptors here