0

我想在 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>
4

1 回答 1

0

Try this Maven plugin to generate classes from 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>

Then use Spring to create a client. Something like this:

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

Then create a class and inject your service client:

@Component
public class YourBean {

   @Autowired
   @Qualifier(value = "yourService")
   private YourService service;

   public void someMethod() {
       service.doSmth();
   }

}
于 2012-11-27T08:13:46.983 回答