我有基于SOAP的服务,它接受一些预定义的请求对象,例如:AccountRequest有一些字段。
示例代码
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");
}
上面的代码会抛出错误
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
这是通过驼峰调用soap服务的正确方法吗?
依赖
<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>
答案 0 :(得分:1)
这是我的SOAP WS示例使用cxf
看起来的样子。
首先,在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>
现在骆驼路线看起来像这样:
from("somewhere")
.to("cxf:bean:insuranceService")
你可能需要一些这样的依赖:
<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>
答案 1 :(得分:1)
您需要通过添加
将“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");
}