【问题标题】:How to call external webservice using Fuse ESB and cxf如何使用 Fuse ESB 和 cxf 调用外部 Web 服务
【发布时间】:2012-11-26 17:26:00
【问题描述】:

我想在 Fuse ESB 的路由中调用外部 Web 服务。从外观上看,您应该使用 cxf 来执行此操作。我有代码要添加到我的 POM 文件中,如下所示。 Maven 不喜欢这样。它抱怨“生命周期配置未涵盖插件执行:org.apache.cxf:cxf-codegen-plugin:2.6.0:wsdl2java (execution: generate-sources, phase: generate-sources)”。我使用什么版本并不重要——我都试过了。另外,当 Maven 构建时,我得到的错误是“'UTF-8' 每个字符使用 1 个字节;但物理编码似乎使用 2”。出了点问题,但是什么? 此代码来自 Fusesource 作为示例。有没有人有这个工作?我的 WSDL 看起来不错。我想做的就是调用一个网络服务,这肯定不会这么难!!!

<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>

【问题讨论】:

    标签: cxf fuseesb jbossfuse


    【解决方案1】:

    试试这个 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();
       }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-30
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-18
      • 2012-06-06
      相关资源
      最近更新 更多