Blueprint, Apache Camel и cxfrs

Я пытаюсь разработать службу отдыха, используя план, верблюд apache и apache cxf-rs, где реализация службы будет обрабатываться верблюдом.

Проблема в том, что остальная конечная точка, похоже, не выделяется для верблюда.

Это исключение, которое я получаю:

при запуске Camel произошла ошибка: CamelContext(blueprintContext) due Существует конечная точка, уже работающая в /crm.

Мой план выглядит следующим образом:

<?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>


person Magick    schedule 01.06.2014    source источник
comment
Возможно, у вас уже есть другой пример/приложение, использующее CXF с адресом /crm. Попробуйте изменить адрес=/crm на что-то другое, например, /crm2 или что-то в этом роде.   -  person Claus Ibsen    schedule 04.06.2014
comment
Спасибо, Клаус, да, я изменил это, но это не помогло.   -  person Magick    schedule 05.06.2014


Ответы (2)


У меня была такая же проблема с веб-сервисами cxf-rs, использующими план. Для того, что я смог увидеть, если вы попытаетесь смешать компонент cxf верблюда с определениями cxf, когда контекст верблюда запускается, он пытается создать одни и те же точки cxf-rs дважды, поэтому это заканчивается: ошибка произошла при запуске Camel: CamelContext (blueprintContext) due Конечная точка уже запущена...

Мне удалось решить эту проблему, изменив <from uri=cxfrs:bean:mybean> на <from uri=direct:start> и изменив jaxrs:servicebean pojo, внедрив конечную точку direct:start и отправив полученный объект в виде тела.

Вот мой код:

план.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

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()
  }


}

После этого исправления CamelContext запускается без ошибок и работает отлично. Надеюсь, это поможет!

person rickespana    schedule 08.04.2015

Использование CXFRsServer вместо сервера jaxrs также решает эту проблему.

person Balakumar Narayanasamy    schedule 19.05.2015