使SOAP服务使用与Wsimport生成类的相同身份验证
我在url https://signatur.ak-oooe。 at/primesign/services/workflowmtom?wsdl 。这是可以公开访问的,但是我必须使用VPN,并且在使用VPN时尝试访问URL时,我需要使用VPN-CREDentials 进行身份验证。我知道这可能很奇怪,只是知道,尽管您可以访问此使用inter authentification,但我确实需要进行身份验证。
我使用 wsimport
从WSDL文件生成Java类。通过 xauthfile
参数提供了身份验证文件后,我成功地做到了这一点:
我的pom.xml:
<plugin>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<wsdlUrls>
<wsdlUrl>https://signatur.ak-ooe.at/primesign/services/workflowMTOM?wsdl</wsdlUrl>
</wsdlUrls>
<xauthFile>src/main/resources/myauthfile.auth</xauthFile>
<keep>true</keep>
<extension>true</extension>
<sourceDestDir>src/main/java/</sourceDestDir>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
</plugin>
在以下命令中导致
jaxws:wsimport args: [-keep, -s, 'C:\mypath\src\main\java', -d, 'C:\mypath\target\classes', -encoding, UTF-8, -extension, -Xnocompile, -Xauthfile, 'C:\mypath\src\main\resources\myauthfile.auth', "https://signatur.ak-ooe.at/primesign/services/workflowMTOM?wsdl"]
包含我的vpn-credentials):
https://akooe\username:[email protected]/primesign/services/workflowMTOM?wsdl
myauthfile.auth.auth(其中 其他类,这会产生此Web服务类:
@WebServiceClient(name = "PrimeSignWorkflowService", targetNamespace = "http://primesign.at/workflow/v1", wsdlLocation = "https://signatur.ak-ooe.at/primesign/services/workflowMTOM?wsdl")
public class PrimeSignWorkflowService
extends Service
{
private final static URL PRIMESIGNWORKFLOWSERVICE_WSDL_LOCATION;
private final static WebServiceException PRIMESIGNWORKFLOWSERVICE_EXCEPTION;
private final static QName PRIMESIGNWORKFLOWSERVICE_QNAME = new QName("http://primesign.at/workflow/v1", "PrimeSignWorkflowService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("https://signatur.ak-ooe.at/primesign/services/workflowMTOM?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
PRIMESIGNWORKFLOWSERVICE_WSDL_LOCATION = url;
PRIMESIGNWORKFLOWSERVICE_EXCEPTION = e;
}
public PrimeSignWorkflowService() {
super(__getWsdlLocation(), PRIMESIGNWORKFLOWSERVICE_QNAME);
}
.....
看起来不错。但是,当我尝试构建项目时,我会收到错误:
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'https://signatur.ak-ooe.at/primesign/services/workflowMTOM?wsdl'.: java.io.IOException: Server returned HTTP response code: 401 for URL: https://signatur.ak-ooe.at/primesign/services/workflowMTOM?wsdl
如您所见,即使我能够通过使用我的authfile来验证我的Authfile来从URL生成Web服务,但生成的Webservice也不会自动使用相同的网络服务身份验证,因此无法访问URL。
如何解决这个问题?我可以以某种方式将代码添加到生成的WebService类中,以便自动进行身份验证吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论您使用什么JAX-WS实现,都应有一种设置SOAP调用的代理身份验证的方法。检查文档。
如果这也适用于WSDL检索,则必须看到。
如果没有,我想您可以查看项目中JAX-WS实现的源代码,看看该URL在哪里使用,以及您可能需要介绍身份验证机制的选项,但是我可以还建议一条不同的路径:
wsimport
具有使您可以更改位置:-wsdllocation&lt; location&gt;
。您甚至可以将WSDL包装在罐子里并从那里使用它(生成的代码可能需要一些较小的更改才能从JAR加载)。例如,请参阅这些帖子以获取一些详细信息:
Whatever JAX-WS implementation you are using should have a way to set proxies authentication for SOAP calls. Check the documentation.
If that will apply to the WSDL retrieval also, you will have to see.
If not, I guess you could have a look over the source code of the JAX-WS implementation you have in your project, and see where that URL is getting used, and what options you might have to introduce the authentication mechanism, but I can also suggest a different path:
wsimport
has that allows you to change the location:-wsdllocation <location>
.You can even pack the WSDL inside your JAR and use it from there (some minor changes might be needed to the generated code to load from the JAR). See for example these post for some details: