...
Code Block | ||||
---|---|---|---|---|
| ||||
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<!-- implementation of the webservice, and we refer to our camel context with the id = camel from camel-context.xml -->
<bean id="reportIncidentEndpoint" class="org.apache.camel.example.reportincident.ReportIncidentEndpointImpl">
<property name="context" ref="camel"/>
</bean>
<!-- export the webservice using jaxws -->
<jaxws:endpoint id="reportIncident"
implementor="#reportIncidentEndpoint"
address="/incident"
wsdlLocation="/WEB-INF/wsdl/report_incident.xml"
endpointName="s:ReportIncidentPort"
serviceName="s:ReportIncidentService"
xmlns:s="http://reportincident.example.camel.apache.org"/>
</beans>
|
So
...
now
...
we
...
have
...
two
...
spring
...
XML
...
files
...
- cxf-config.xml
...
- camel-config.xml
...
And
...
since
...
cxf-config.xml
...
is
...
dependent
...
on
...
camel-config.xml
...
we
...
need
...
to
...
have
...
correct
...
ordering
...
in
...
our
...
web.xml
...
where
...
we
...
have
...
defined
...
the
...
XML
...
files
...
to
...
load
...
by
...
Spring.
...
So
...
we
...
set
...
the
...
camel-config.xml
...
before
...
the
...
cxf-config.xml
...
so
...
Spring
...
have
...
created
...
the
...
SpringCamelContext
...
and
...
registered
...
it
...
in
...
its
...
registry
...
with
...
the
...
id
...
=
...
camel.
Code Block | ||||
---|---|---|---|---|
| ||||
{code:xml} <!-- location of spring xml files --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:camel-config.xml</param-value> <param-value>classpath:cxf-config.xml</param-value> </context-param> |
But hey this isn't using CXF directly in the routing? Yes it's not but I wanted to show the halfway solution as well. What we have now is having Spring creating and handling lifecycle of Camel and showing how you can inject CamelContext using standard Spring into whatever code you have. This is very powerful as you can use the solution that you (or your team) already master and is familiar with. If they have Spring experience then the IoC principle of injecting resources is of course also possible with Camel as well. In fact it's a best practice principle. Later you will learn that you can inject other Camel types such as Endpoints, ProducerTemplate as well.
Using the camel-cxf component
Okay let's continue and try to integrate CXF directly into our routing in Camel. This can be a bit more tricky than at first sight. Our goal is to avoid implementing the ReportIncidentEndpoint
as we did with our code in ReportIncidentEndpointImpl
(see above). Camel should be able to handle this automatically and integrate directly within our route.
Before we started our routing using the Direct endpoint with "direct:start"
. We should replace this with the CXF endpoint.