如何在cxf-maven-plugin中为wsdl定义密码 [英] How to define a password to wsdl in cxf-maven-plugin

查看:80
本文介绍了如何在cxf-maven-plugin中为wsdl定义密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据此文档使用cxf-maven-plugin从WSDL生成Java代码:

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>

推荐答案

您可以对URI使用基本的身份验证方案,如下所示:

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

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

但是,如果您的wsdl参考带有相对路径的xsd,则不会使用用户名和密码来加载这些xsd.您可以做的是设置一个Authenticator全局值.您需要做的是添加exec插件以运行一个类,该类将为当前正在运行的jvm设置defaut Authenticator:

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 :

使用 http://mojo.codehaus.org/exec-maven-plugin/和exec:java以在与Codegen插件相同的jvm中运行您的类. wsdl2java执行必须在exec:java之后执行.您的运行类将按照以下说明设置Authenticator: http://docs.oracle.com/javase/7/docs/technotes/guides/net/http-auth.html

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

总有一天,我们会提供有用的-Ddefault.authenticatorClass = package.to.my.AuthenticatorImpl jvm arg ...

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

这篇关于如何在cxf-maven-plugin中为wsdl定义密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆