Multiples CXF Services in one CXFRS Server
chubutin Jun 16, 2014 4:42 PMHi! I'm trying to create one CXFRS server in http://localhost:8282/rest and append services from differents bundles. This is possible? I expect to create just one cxfrs:server and import it from differents bundles so all my services will be in that path.
In this test I'm trying to create just one cxfrs:server and multiples camel contexts with the from of the routs pointing to the same rsServer
{code}
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: There is an endpoint already running on http://localhost:8282/rest.
at org.apache.cxf.jaxrs.JAXRSBindingFactory.addListener(JAXRSBindingFactory.java:86)
at org.apache.cxf.endpoint.ServerImpl.start(ServerImpl.java:131)
at org.apache.camel.component.cxf.jaxrs.CxfRsConsumer.doStart(CxfRsConsumer.java:44)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:1929)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:2223)
at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:2159)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:2089)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1868)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1740)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1579)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1547)
at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:221)
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:118)
{code}
My Code contains one server jaxrs server and two contexts trying to use the same jaxrs server
{code}
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<cxf:rsServer id="rsServer" address="http://localhost:8282/rest"
loggingFeatureEnabled="true" loggingSizeLimit="20" skipFaultLogging="true">
<cxf:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
<bean
class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter" />
</cxf:providers>
</cxf:rsServer>
<bean id="myProcessor" class="com.smg.camel.processor.DefaultProcessor" />
<camel:camelContext id="helloWorldContext">
<camel:route id="helloWorldRoute">
<camel:from
uri="cxfrs://bean://rsServer?resourceClasses=com.smg.service.HelloCamelService&bindingStyle=SimpleConsumer" />
<camel:setHeader headerName="headerRouting">
<camel:simple>direct:${header.operationName}${header.CamelHttpMethod}</camel:simple>
</camel:setHeader>
<camel:process ref="myProcessor" />
<camel:to uri="log:before?showHeaders=true" />
<camel:routingSlip>
<camel:header>headerRouting</camel:header>
</camel:routingSlip>
<camel:log message="Finalizacion de ruta principal"></camel:log>
</camel:route>
</camel:camelContext>
<camel:camelContext id="byeWorldContext">
<camel:route id="helloWorldRoute">
<camel:from
uri="cxfrs://bean://rsServer?resourceClasses=com.smg.service.ByeCamelService&bindingStyle=SimpleConsumer" />
<camel:setHeader headerName="headerRouting">
<camel:simple>direct:${header.operationName}${header.CamelHttpMethod}</camel:simple>
</camel:setHeader>
<camel:process ref="myProcessor" />
<camel:to uri="log:before?showHeaders=true" />
<camel:routingSlip>
<camel:header>headerRouting</camel:header>
</camel:routingSlip>
<camel:log message="Finalizacion de ruta principal"></camel:log>
</camel:route>
</camel:camelContext>
</beans>
{code}
My interfaces are like this interface:
{code}
package com.smg.service;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
@Path(value = "/hello")
public interface HelloCamelService {
@GET
@Produces("application/json")
String returnHello();
@GET
@Produces("application/json")
@Path("/{name}")
String returnHelloName(@QueryParam(value = "name") String name);
@POST
@Produces("application/json")
String returnHello(@HeaderParam(value = "body") String name);
}
{code}