简体   繁体   English

具有多个输入参数的Camel CXF Soap Client调用Web服务

[英]Camel CXF Soap Client calling web service with multiple input parameters

I'm using Camel and have generated code from a WSDL using CXF. 我正在使用Camel,并已使用CXF从WSDL生成了代码。 I generated a client stub and the implementation appears like this: 我生成了一个客户端存根,实现如下所示:

    SetDeviceDetailsv4 port = ss.getSetDeviceDetailsv4Port();  

    com.vodafone.gdsp.ws.SetDeviceDetailsv4_Type _setDeviceDetailsv4_parameters = null;
    com.vodafone.gdsp.ws.GdspHeader _setDeviceDetailsv4_gdspHeader = null;

    com.vodafone.gdsp.ws.SetDeviceDetailsv4Response _setDeviceDetailsv4__return = port.setDeviceDetailsv4(_setDeviceDetailsv4_parameters, _setDeviceDetailsv4_gdspHeader);

    System.out.println("setDeviceDetailsv4.result=" + _setDeviceDetailsv4__return);

As you one can see, the port takes two parameters and returns the response, which I want to delegate back to my Camel Route. 如您所见,该端口带​​有两个参数并返回响应,我想将其委托给我的Camel Route。 What's the best way to implement this in Camel? 在Camel中实现此功能的最佳方法是什么? I already have my CXF Enpoint defined, I'm just struggling with the DSL Routing part of it. 我已经定义了CXF Enpoint,但我只是在努力解决它的DSL路由部分。 Should I add a processor like what is found in this link? 是否应该添加像在此链接中找到的处理器一样的处理器? Apache Camel and web services Apache Camel和Web服务

Thanks 谢谢

You can use jax-ws client (implement as bean) and use it in camel DSL. 您可以使用jax-ws客户端(以bean的形式实现)并将其用于骆驼DSL。 JAX-WS client bean definition takes service class/interface and allow you configure additional properties like SSL config & etc. In route, we can use it as bean. JAX-WS客户端bean定义采用服务类/接口,并允许您配置其他属性,例如SSL config&等。在路由中,我们可以将其用作bean。 It takes JAXB generated Request object (WSDL request object) as input and returns the JAXB generated Response Object (WSDL response object). 它以JAXB生成的Request对象(WSDL请求对象)作为输入,并返回JAXB生成的Response对象(WSDL响应对象)。 To convert you pojo to JAXB classes, Dozer framework can be used or custom mapping can be also used. 要将pojo转换为JAXB类,可以使用Dozer框架,也可以使用自定义映射。 Jax-WS client is also flexible to take XML as request and response. Jax-WS客户端还可以灵活地将XML作为请求和响应。 In that case, properties need to be set as DATAFORMAT as PAYLOAD. 在这种情况下,需要将属性设置为DATAFORMAT作为PAYLOAD。

I'm not sure if this is the correct way to do it but I added both of my "input" objects as a Camel Header, then I wrote a processor that grabbed what I needed and put the two objects that the service call needed as parameters. 我不确定这是否是正确的方法,但是我将两个“输入”对象都添加为驼峰标头,然后我编写了一个处理器,抓取了我需要的东西,并将服务调用所需的两个对象放入其中。参数。

public void process(Exchange exchange) throws Exception {
        Message inMessage = exchange.getIn();
        gdspHeader = inMessage.getHeader(GDSP_HEADER, com.vodafone.gdsp.ws.GdspHeader.class);
        commModule = inMessage.getHeader(COMM_MODULE_HEADER, resmed.hi.ngcs.datastore.model.CommModule.class);
        SetDeviceDetailsv4_Type deviceDetails = createSetDeviceDetailsv4(commModule);

        List<Object> params = new ArrayList<>();
        params.add(deviceDetails);
        params.add(gdspHeader);

        inMessage.setBody(params);

    }
`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM