使SOAP服务使用与Wsimport生成类的相同身份验证

发布于 2025-01-29 22:19:18 字数 3545 浏览 8 评论 0 原文

我在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类中,以便自动进行身份验证吗?

I have a WSDL file at the URL https://signatur.ak-ooe.at/primesign/services/workflowMTOM?wsdl . This is publicly accessable, however I have to use a VPN and when trying to access the URL while using the VPN I need to authenticate with my VPN-credentials. I know this may be strange, just know that while you may be able to access this withouth authentification, I do need to authenticate.
I use wsimport to generate the Java-classes from the WSDL file. I successfully managed to do so after providing an authentication file via the xAuthfile parameter :

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

Which results in the following command:

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

myauthfile.auth (Which contains my VPN-credentials) :

https://akooe\username:[email protected]/primesign/services/workflowMTOM?wsdl

Aside from the other classes, this produces this webservice class:

@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);
    }
 
    .....

Which looks good. However, when I try to build my project, I get the error:

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

As you can see, it appears that even though I was able to generate the webservice from the URL by authenticating with my authfile, the generated webservice does not automatically use the same authentication, thus it cannot access the URL.

How do I solve this problem? Can I somehow add code to the generated webservice class so that it authenticates automatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨死的猪 2025-02-05 22:19:18

无论您使用什么JAX-WS实现,都应有一种设置SOAP调用的代理身份验证的方法。检查文档。

如果这也适用于WSDL检索,则必须看到。

如果没有,我想您可以查看项目中JAX-WS实现的源代码,看看该URL在哪里使用,以及您可能需要介绍身份验证机制的选项,但是我可以还建议一条不同的路径:

  • 下载WSDL在某个地方您可以在网络中访问它并使用它。有一个参数 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:

  • download the WSDL somewhere you can access it within your network and use that instead. There is a parameter 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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文