Blueprint, Apache Camel and cxfrs

3.3k Views Asked by At

I am trying to develop a rest service using blueprint, apache camel and apache cxf-rs - where the service implementation will be handled by camel.

The problem is the rest endpoint seems to not get allocated to camel.

This is the exception I get:

error occurred during starting Camel: CamelContext(blueprintContext) due There is an endpoint already running on /crm.

My blueprint is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
  http://www.osgi.org/xmlns/blueprint/v1.0.0     http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
  http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
  http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
  http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">


<jaxrs:server id="customerService" address="/crm" staticSubresourceResolution="true">
    <jaxrs:serviceBeans>
        <ref component-id="customerSvc"/>
    </jaxrs:serviceBeans>
    <jaxrs:features>
        <bean class="io.fabric8.cxf.endpoint.SwaggerFeature"/>
        <bean class="io.fabric8.cxf.endpoint.ManagedApiFeature"/>
    </jaxrs:features>
    <jaxrs:providers>
       <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
    </jaxrs:providers>
</jaxrs:server>




<bean id="customerSvc" class="restfuse.CustomerService"/>

<cxf:bus>
    <cxf:features>
      <cxf:logging />
    </cxf:features>
</cxf:bus>



<camelContext id="blueprintContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<route customId="true" id="timerToLog">
    <from uri="cxfrs:bean:customerService"/>
    <setBody>
        <method ref="helloBean" method="hello"></method>
    </setBody>
    <log message="The message contains ${body}"/>
    <to uri="mock:result"/>
</route>

2

There are 2 best solutions below

0
On

Using CXFRsServer instead of jaxrs server also solves this problem.

0
On

I was having the same issue regarding cxf-rs web services using blueprint. For what I was able to see if you try to mix camel cxf component with cxf definitions, when camel contexts starts it tries to create the same cxf-rs enpoints twice, therefore it ends with: error occurred during starting Camel: CamelContext(blueprintContext) due There is an endpoint already running...

I managed to solve this changing <from uri=cxfrs:bean:mybean> to <from uri=direct:start> and modifying jaxrs:servicebean pojo injecting direct:start endpoint and sending received object as body.

Here is my code:

blueprint.xml

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:camel="http://camel.apache.org/schema/blueprint"       
   xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
   xmlns:cxf="http://cxf.apache.org/blueprint/core"
   xsi:schemaLocation="
   http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
   http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
   http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/cxf/camel-cxf-blueprint.xsd
   http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
   http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd">


   <jaxrs:server id="rsAuthApiSvc" 
            address="http://localhost:9898/authservice"
            staticSubresourceResolution="true">
      <jaxrs:serviceBeans>
         <ref component-id="pmAuthService"/>
      </jaxrs:serviceBeans>
        <jaxrs:providers>
           <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
       </jaxrs:providers>
   </jaxrs:server>

<bean id="pmAuthService" class="com.platamovil.platamovil.auth.rs.PMAuthService"/>

<camelContext trace="false" streamCache="true" id="authApiContext" xmlns="http://camel.apache.org/schema/blueprint">

    <route id="restApiRoute">
        <from uri="direct:start"/>
        <log message="received from WS: ${body}"/>
        <setBody>
            <constant>{"status":"OK"}</constant>
        </setBody>
    </route>

</camelContext>

pmAuthService Bean

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import com.platamovil.platamovil.auth.api.PMAuthMessage;

public class PMAuthService {
  @EndpointInject(uri="direct:start")
  ProducerTemplate producer;

@POST   
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/authenticateclient")
  public PMAuthMessage processAuthService(PMAuthMessage in_msg) throws Exception{       

      System.out.println("message arrived");
      return producer.requestBody(in_msg).toString()
  }


}

After this fix CamelContext starts without error and works perfectly. I hope this helps!