[英]How to call external webservice using Fuse ESB and cxf
我想在Fuse ESB中的路由內調用外部Web服務。 從外觀上看,您應該使用cxf來執行此操作。 我有添加到我的POM文件中的代碼,如下所示。 Maven不喜歡這樣。 它抱怨“生命周期配置未涵蓋插件執行:org.apache.cxf:cxf-codegen-plugin:2.6.0:wsdl2java(執行:generate-sources,階段:generate-sources)”。 我使用哪個版本都沒有關系-我已經嘗試了所有版本。 Alos,當Maven構建錯誤時,我得到的錯誤是“'UTF-8'每個字符使用1個字節;但是物理編碼似乎使用2個字節”。 出了點問題,但是呢? 該代碼以Fusesource為例。 有人有這個工作嗎? 我的WSDL看起來不錯。 我要做的就是調用一個Web服務,這一定不難!
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.6.0</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<!-- Maven auto-compiles any source files under target/generated-sources/ -->
<sourceRoot>${basedir}/target/generated-sources/jaxws</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>C:/bolt-poc/src/main/resources/WSDL/esbWebService.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
嘗試使用此Maven插件從WSDL生成類:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.6.0</version>
<executions>
<execution>
<id>generate-jaxb</id>
<phase>generate-sources</phase>
<configuration>
<additionalJvmArgs>-Dfile.encoding=UTF8</additionalJvmArgs>
<wsdlOptions>
<wsdlOption>
<wsdl>src/main/resources/WSDL/esbWebService.wsdl</wsdl>
<extraargs>
<extraarg>-exsh</extraarg>
<extraarg>true</extraarg>
<extraarg>-p</extraarg>
<extraarg>your.pkg</extraarg>
<extraarg>-wsdlLocation</extraarg>
<extraarg></extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
然后使用Spring創建一個客戶端。 像這樣:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:client id="yourService"
address="http://your/web/service/url"
serviceClass="your.generated.service.class.YourClass"
username="inCaseYouNeedUsername"
password="inCaseYouNeedPassword"/>
</beans>
然后創建一個類並注入您的服務客戶端:
@Component
public class YourBean {
@Autowired
@Qualifier(value = "yourService")
private YourService service;
public void someMethod() {
service.doSmth();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.