Camel CXF POJO模式使用Java DSL [英] Camel CXF POJO mode using Java DSL

查看:32
本文介绍了Camel CXF POJO模式使用Java DSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个预先存在的 Web 服务连接"(SOAP),如果可能,我想在不使用 Swing 框架的情况下调用.我遵循了使用 cxf/wsdl2java 工具生成我的 java 文件的联系优先开发.

I have a pre-existing web service "connect" (SOAP) I would like to call without using the Swing framework if possible. I have followed the contact first development generating my java files using cxf/wsdl2java tool.

我希望从 java 对象中提取用户名和密码,并将其放入 SOAP 对象中,然后发送到我的 localhost Web 服务.

I wish for the userName and password to be extracted from the java object and placed in a SOAP object then sent onot my localhost web service.

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

When sending the Connect object as a body to the "direct:start" I get an exception...

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 对象的一个​​实例.

I've checked the first argument is actually an instance of the Connect object passed in.

是否需要在其中一个类中添加一些注释,是测试方法无效还是
我应该遵循其他模式吗?

Do I need some additional annotations in the one of the classes, is the method of testing invalid or
is there an alternative pattern I should follow?

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

我是骆驼和网络服务的新手,因此非常感谢任何有用的指点.

I'm new to camel and web services so any helpful pointers would be greatly appreciated.

其他信息

使用骆驼 2.10、Java 1.6

Using 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);
    }

}

推荐答案

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

In my experience there are some things in Camel, like calling a SOAP Web service or making a REST call, that are easier to do in a custom processor, than using a component like CXF, HTTP or HTTP4.

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

I usually work with Spring, so I tend to use either Spring REST template or the JaxWsPortProxyFactoryBean (for Webservice calls) for outbound calls.

这是一个使用 JAX-WS 调用的示例:

Here is an example using a JAX-WS call:

    public class WebServiceProcessorBean {

    @Autowired
    private JAXWSProxy theProxy;


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

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

Spring应用上下文中的定义:

The definition in the Spring application context:

<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 方法一起使用.

Use the WebServiceProcessorBean defined in Spring application context with beanRef() DSL method.

.beanRef("theProxyService", "callWebservice")

这篇关于Camel CXF POJO模式使用Java DSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆