2

我正在尝试使用蓝图、apache camel 和 apache cxf-rs 开发一个休息服务——服务实现将由骆驼处理。

问题是其余端点似乎没有分配给骆驼。

这是我得到的例外:

启动 Camel 时发生错误:CamelContext(blueprintContext) 由于 /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>

4

2 回答 2

2

关于使用蓝图的 cxf-rs Web 服务,我遇到了同样的问题。如果您尝试将骆驼 cxf 组件与 cxf 定义混合使用,我可以看到,当骆驼上下文启动时,它会尝试两次创建相同的 cxf-rs 端点,因此它以:启动骆驼时发生错误:CamelContext(blueprintContext)由于有一个端点已经在运行...

我设法解决了这个更改<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 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()
  }


}

在此修复后,CamelContext 启动时没有错误并且运行良好。我希望这有帮助!

于 2015-04-08T22:57:31.987 回答
1

使用 CXFRsServer 代替 jaxrs 服务器也可以解决这个问题。

于 2015-05-19T05:01:38.670 回答