How to define a password to wsdl in cxf-maven-plugin

半世苍凉 提交于 2019-12-24 00:27:01

问题


I want to use the cxf-maven-plugin to generate Java code from a WSDL per this doc: http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html

The service I am trying to reach is password protected. How do I specify a password? This doesn't seem to be documented.

 <plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <executions>
    <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration>
        <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
        <wsdlOptions>
          <wsdlOption>
            <wsdl>http://host/TheService.wsdl</wsdl>
          </wsdlOption>
        </wsdlOptions>
      </configuration>
      <goals>
        <goal>wsdl2java</goal>
      </goals>
    </execution>
  </executions>
</plugin>

回答1:


You can use the basic auth scheme for URI like this :

<wsdl>http://username:password@host/TheService.wsdl</wsdl>

But if your wsdl reference xsd with a relative path, the username and password won't be used for loading those xsd... What you can do is to set an Authenticator globaly... What you need to do is to add the exec plugin to run a Class that will set the defaut Authenticator for the currently running jvm :

use http://mojo.codehaus.org/exec-maven-plugin/ and exec:java to run your class in the same jvm as the codegen plugin. The wsdl2java execution must happen after the exec:java. Your run class will set the Authenticator as explain here : http://docs.oracle.com/javase/7/docs/technotes/guides/net/http-auth.html

Some day, we'll have a usefull -Ddefault.authenticatorClass=package.to.my.AuthenticatorImpl jvm arg...




回答2:


Have you tried to include the user/password of the host within your user settings file (~/.m2/settings.xml)? I would try this and see what happens.




回答3:


It seems there's no way to download password protected wsdl with this plugin, at least there are no corresponding fields in WsdlOption that you actually configure.

Instead, in CXF versions 2.3+ you can configure a wsdl from maven repository with <wsdlArtifact> and install the manually downloaded wsldfile



来源:https://stackoverflow.com/questions/4802919/how-to-define-a-password-to-wsdl-in-cxf-maven-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!