CXF端点定义,并且无法解析端点:在注册表中找不到bean

时间:2015-01-27 14:01:11

标签: cxf apache-camel

我尝试定义一个CXF端点,但它不起作用。 当我想要解决端点时,我得到了“未找到bean”的异常。

CXF定义:

    @Override
    public void configure() throws Exception
    {

        errorHandler(deadLetterChannel(systemInfo.getQueuName())
                .allowRedeliveryWhileStopping(true)
                .maximumRedeliveries(-1)
                );

        onException(Exception.class).process(routeHandlingBean);


        CamelContext camelContext = getContext();

        CxfEndpoint partnerTestService = new CxfEndpoint();
        partnerTestService.setEndpointNameString("partnerTestService");
        partnerTestService.setAddress("http://localhost:9081/MockPartnerService");
        partnerTestService.setWsdlURL("http://localhost:9081/MockPartnerService?wsdl");
        partnerTestService.setServiceClass(aaa.bbb.ccc.service.PartnerService.class);
        partnerTestService.setServiceNameString("partnerTestService");
        partnerTestService.setDataFormat(DataFormat.CXF_MESSAGE);
        partnerTestService.setCamelContext(camelContext);

        try {
            camelContext.addEndpoint("partnerTestService", partnerTestService);
        } catch (Exception e) {
            e.printStackTrace();
        }

当我尝试呼叫端点时:

cxf:bean:partnerTestService

然后我收到此错误消息:

org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: cxf://bean:partnerTestService due to: No bean could be found in the registry for: partnerTestService of type: org.apache.camel.component.cxf.CxfEndpoint

我不知道还有什么我需要设置。

THX! FERI

1 个答案:

答案 0 :(得分:0)

解决方案是使用CxfEndpoint类。我写了一个函数,它返回一个所需的对象(而不是字符串端点),因此它是有用的。

路线定义:

    ValueBuilder dynRouterMethod = method(esbDynRouter, "endpointRoute");

    from(queueName).id(systemInfo.getRouteId()).routeId(systemInfo.getRouteId()).autoStartup(false)
    .transacted()
    .log(LoggingLevel.INFO, systemInfo.getRouteId() + " route usage.")
    .beanRef("statusUpdaterBean", "updateSendingStatus")
    .dynamicRouter(dynRouterMethod)
    .beanRef("statusUpdaterBean", "updateSentStatus")
    ;

程序(在动态路由器程序中调用):

private CxfEndpoint getCxfEndpoint(DispConfView target) throws Exception
    {
        CxfEndpoint cxfEndpoint = (CxfEndpoint) camelContext.getEndpoint(<Something>);

        if (cxfEndpoint == null)
        {
            String serviceClassNme = <class name what represent the POJO class>;
            String methodName = <WS methode name>;

            cxfEndpoint = new CxfEndpoint();
            cxfEndpoint.setAddress(methodName);
            cxfEndpoint.setDataFormat(DataFormat.POJO);
            cxfEndpoint.setServiceClass(serviceClassNme);

            cxfEndpoint.setCamelContext(camelContext);

            camelContext.addEndpoint(<Something>, cxfEndpoint);
        }

        return cxfEndpoint;
    }

如果邮件是POJO类型,此解决方案有效。