简体   繁体   中英

Make SOAP-Service use the same authentication used for generating classes with wsimport

I have a WSDL file at the URLhttps://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:password@signatur.ak-ooe.at/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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM