简体   繁体   English

使用Apache Camel和spring-ws组件调用基于SOAP的服务

[英]Invoke SOAP based service using Apache Camel and spring-ws component

I have SOAP based service which accepts some predefined request object, 我有基于SOAP的服务,可以接受一些预定义的请求对象,

for example, AccountRequest having some fields. 例如,AccountRequest具有一些字段。

Sample code 样例代码

from("direct:test")
    .routeId("account.get")
    .process(exchange -> {
        exchange.getIn().setBody(createAccountRequest());
    })
    .to("spring-ws:http://localhost:8090/AccountServices/AccountOverviewService")
    .log("Got Request for account-detail");
}

Above code throws an error 上面的代码抛出错误

org.apache.camel.NoTypeConversionAvailableException: 
No type converter available to convert from type: 
com.test.AccountRequest to the required type: 
javax.xml.transform.Source with value com.test.AccountRequest@4e1c1763

Is this right way to invoke soap service via camel? 通过骆驼调用肥皂服务的正确方法吗?

Dependencies 依存关系

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>2.18.3</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-ws</artifactId>
    <version>2.18.3</version>
</dependency>

Here's how my SOAP WS example looks using cxf . 这是使用cxf SOAP WS示例的外观。

Firstly, in camel-context.xml , define the web service bean: 首先,在camel-context.xml ,定义Web服务bean:

<cxf:cxfEndpoint id="insuranceService"
                 address="http://localhost:8080/insuranceService"
                 serviceClass="com.mycompany.insurance.insurancePort"
                 wsdlURL="schema/InsuranceService.wsdl">
</cxf:cxfEndpoint>

Now the camel route looks like this: 现在,骆驼路线如下所示:

from("somewhere")
    .to("cxf:bean:insuranceService")

And you might need some dependencies like these: 您可能需要一些类似的依赖项:

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
        <version>${framework.camel}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>${framework.cxf}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-http</artifactId>
        <version>${framework.camel}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jaxb</artifactId>
        <version>${framework.camel}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-soap</artifactId>
        <version>${framework.camel}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-saxon</artifactId>
        <version>${framework.camel}</version>
    </dependency>

You would need to marshal the "com.test.AccountRequest" to the xml by adding 您需要通过添加将“ com.test.AccountRequest”编组到xml中

  JaxbDataFormat jaxb = new JaxbDataFormat(false); //add
  jaxb.setContextPath("com.accountservice.model"); //add - path to your generated stubs

    from("direct:test")
        .routeId("account.get")
        .process(exchange -> {
            exchange.getIn().setBody(createAccountRequest());
        })
        .marshal(jaxb) //add
        .to("spring-ws:http://localhost:8090/AccountServices/AccountOverviewService")
        .log("Got Request for account-detail");
    }

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

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