我正在尝试使用蓝图,apache camel和apache cxf-rs开发一个休息服务 - 其中服务实现将由camel处理。
问题是其他端点似乎没有分配给驼峰。
这是我得到的例外:
启动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>
答案 0 :(得分:1)
我在使用蓝图时遇到了与cxf-rs web服务相同的问题。如果你试图将camel cxf组件与cxf定义混合,我可以看到,当camel contexts启动时,它尝试创建相同的cxf-rs enpoints两次,因此它结束于:启动Camel期间出错:CamelContext(blueprintContext) due已经有一个端点正在运行...
我设法解决了这个改变<from uri=cxfrs:bean:mybean>
到<from uri=direct:start>
并修改jaxrs:servicebean pojo注入直接:开始端点并将接收到的对象作为正文发送。
这是我的代码:
<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>
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启动时没有错误并且工作正常。我希望这有帮助!
答案 1 :(得分:1)
使用CXFRsServer而不是jaxrs服务器也解决了这个问题。