Search code examples
javaspringjakarta-eecxfapache-camel

Spring and Camel CXF playing nicely inside a WAR


I have a web application. It has Servlets and JSPs, etc. Now I'm adding a web service.

I can get CXF working. My @WebService works fine.

But I need the web service to have access to my beans, which are set up in Spring.

If I try adding the following, to forward requests to an EJB (because this works fine for standalone apps) :

<bean id="webServ" class="com.company.application.MyWebServiceHandler" />

<camelContext id="FindCode" xmlns="http://camel.apache.org/schema/spring">
    <route id="FindCodeRoute">
        <from uri="cxf:bean:myEndpoint?dataFormat=POJO" />
        <to uri="log:input?showAll=true&amp;level=INFO"/>
        <to uri="bean:webServ?method=process" />
        <to uri="log:input?showAll=true&amp;level=INFO" />
    </route>
</camelContext>

It gives me "Cannot find any registered HttpDestinationFactory from the Bus." I've Googled the hell out of this.

I've got

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

and I've tried importing

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>2.7.13</version>
    </dependency>

and/or org.apache.cxf cxf-rt-transports-http-jetty 2.7.13

But nope.

Does anyone know how to inject an EJB into a WebService?

If I slap a @Stateless on the @WebService, it doesn't find my injected EJBs. NPE. I'm using JBoss EAP 6.3.


Solution

  • I solved it using camel-example-cxf-tomcat as a basis.