骆驼(Camel)CXF POJO模式使用Java DSL

7

我有一个现有的Web服务"connect"(SOAP),如果可能的话,我希望不使用Swing框架来调用它。 我遵循了联系先开发的过程,使用cxf / wsdl2java工具生成了我的Java文件。

我希望从Java对象中提取用户名和密码,并将其放入SOAP对象中,然后发送到我的本地主机Web服务。

当将Connect对象作为主体发送到"direct:start"时,我会收到异常...

Caused by: java.lang.IllegalArgumentException: Get the wrong parameter size to invoke the out service, Expect size 2, Parameter size 1. Please check if the message body matches the CXFEndpoint POJO Dataformat request.

我已经检查过第一个参数实际上是传递进来的Connect对象的一个实例。
我需要在某个类中添加一些额外的注释吗?还是测试方法无效?或者有其他的模式可以遵循?
public class TestConnectCXF extends CamelTestSupport
{
    @Override
    protected RouteBuilder createRouteBuilder() throws Exception
    {
        return new RouteBuilder()
        {
            String cxfAddressLine = "cxf:http://localhost:8081/nuxeo/webservices/privateadservice?wsdlURL=wsdl/privateadservice.wsdl" //
                    + "&dataFormat=POJO" //
                    + "&serviceClass=com.sandbox.camelfeed.PrivateAdServiceInterface" //
                    + "&serviceName={http://ws.sandboxtest.com/}PrivateAdService" //
                    + "&synchronous=true" //
                    + "&loggingFeatureEnabled=true" //
                    + "&portName={http://ws.sandboxtest.com/}PrivateAdServiceInterfacePort";
            @Override
            public void configure() throws Exception
            {
                from("direct:start").to(cxfAddressLine).to("mock:end");
            }
        };
    }

    @Test
    public void testConnectViaPojo() throws InterruptedException
    {
        Connect connectToServer = new Connect();
        connectToServer.setUserName("FakeUser");
        connectToServer.setPassword("scrubbed");
        template.sendBody("direct:start", connectToServer);
        Thread.sleep(1000);
    }
}

我对camel和web服务都不熟悉,希望能得到一些有用的指导。

附加信息

使用camel 2.10,Java 1.6

从wsdl2java生成的类

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "connect", propOrder = {
   "userName",
   "password"
})
public class Connect {

protected String userName;
protected String password;

public String getUserName() {
    return userName;
}

public void setUserName(String value) {
    this.userName = value;
}


public String getPassword() {
    return password;
}

public void setPassword(String value) {
    this.password = value;
}
}

@WebService(targetNamespace = "http://ws.sandboxtest.com/", name = "PrivateAdServiceInterface")
@XmlSeeAlso({ObjectFactory.class})
public interface PrivateAdServiceInterface {

        // Omitted Code relating to other web calls

        @WebResult(name = "return", targetNamespace = "")
        @RequestWrapper(localName = "connect", targetNamespace = "http://ws.sandboxtest.com/", className = "com.sandbox.camelfeed.Connect")
        @WebMethod
        @ResponseWrapper(localName = "connectResponse", targetNamespace = "http://ws.sandboxtest.com/", className = "com.sandbox.camelfeed.ConnectResponse")
        public java.lang.String connect(
            @WebParam(name = "userName", targetNamespace = "")
            java.lang.String userName,
            @WebParam(name = "password", targetNamespace = "")
            java.lang.String password
        ) throws ClientException_Exception;
    }

@XmlRegistry
public class ObjectFactory {
{
    // Omitted other web calls information
      private final static QName _Connect_QNAME = new QName("http://ws.sandboxtest.com/", "connect");

    @XmlElementDecl(namespace = "http://ws.sandboxtest.com/", name = "connect")
    public JAXBElement<Connect> createConnect(Connect value) {
        return new JAXBElement<Connect>(_Connect_QNAME, Connect.class, null, value);
    }

}

你能找到一种解决这个问题的方法吗? - casper
建议客户使用自定义处理器以避免“魔法”。 - loffa
2个回答

4

根据我的经验,在Camel中有些事情,比如调用SOAP Web服务或进行REST调用,使用自定义处理器比使用CXF、HTTP或HTTP4等组件更容易实现。

我通常使用Spring,因此我倾向于使用Spring REST模板或JaxWsPortProxyFactoryBean(用于Webservice调用)进行出站调用。

以下是使用JAX-WS调用的示例:

    public class WebServiceProcessorBean {

    @Autowired
    private JAXWSProxy theProxy;


    public void callWebservice(Exchange exchange) {
        Response response = theProxy.call();

        //Do something with the response and Exchange.
    }
  }

在Spring应用程序上下文中的定义:

<bean id="theProxyService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
        <property name="serviceInterface" value="XXX"/>
        <property name="wsdlDocumentUrl" value="http://xxxxx.wsdl"/>
        <property name="namespaceUri" value="xxxx"/>
        <property name="serviceName" value="xxxx"/>
        <property name="portName" value="xxxxx"/>
</bean> 

使用在Spring应用上下文中定义的WebServiceProcessorBean,通过beanRef() DSL方法进行调用。
.beanRef("theProxyService", "callWebservice")

0

我也尝试着深入了解Apache Camel和CXF :)

我认为抛出的异常与参数数量有关。 template.sendBody(what_is_called, input_parameter_s, output_parameter);

输出参数很可能是调用cxf web服务后返回的值。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接