Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate java classes from a wsdl url with basic authentication

I am trying to generate the java classes from a WSLD file, that uses basic authentication.

Although there are many plugins out there, I have to use the following one: org.jvnet.jaxb2.maven2:maven-jaxb2-plugin

With wsimport or wsdl2java i have found the way to configure the basic authentication parameters. Using the maven-jaxb2-plugin i had no luck.

My configuration follows:

       <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <packageName>com.mycompany</packageName>
                        <sourceType>wsdl</sourceType>
                        <specVersion>2.2</specVersion>
                        <schemas>
                            <schema>
                                <url>https://some-url?wsdl</url>
                            </schema>
                        </schemas>

                        <outputDirectory>target/generated-sources/xjb</outputDirectory>
                        <clearOutputDir>false</clearOutputDir>
                        <useActiveProxyAsHttpproxy>true</useActiveProxyAsHttpproxy>
                    </configuration>
                </execution>
            </executions>
        </plugin>

As expected, the build fails with the following message:

Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: https://some-url?wsdl
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:2275)
... 36 more

Any ideas about the basic authentication configuration? Thank's in advance!

Note: https://username:pass@some-url?wsdl, i still get an IOException because of the unauthorized request.

like image 375
Eirini Graonidou Avatar asked Aug 21 '17 10:08

Eirini Graonidou


People also ask

How to Generate Java client from WSDL?

Generate the client code as follows: In the Project Explorer, right-click your client project's WSDL file, and then select WebLogic Web Services > Generate Web Service Client from the drop-down menu, as Figure 1 shows. This will open the New Web Service Client dialog that Figure 2 shows.

How to Generate Java classes from WSDL IntelliJ?

Select the desired client module in the Project tool window and select Tools | XML WebServices and WSDL | Generate Java Code from WSDL from the main menu. In the Web Service WSDL URL field, specify the URL address of the desired Web service WSDL descriptor.

How to Generate Java classes from WSDL in eclipse?

Eclipse comes with the webservice tools. You just need to right click the wsdl and click the generate the java client option. No need to use any third party jar file.


2 Answers

I haven't found any way of solving this. I ended up downloading the .wsdl and the needed .xsd files and edited them (changed the import URL's) properly.

Note: For people that have the same issue, i would recommend the jaxws:wsimport plugin, that supports an xauthFile option for the configuration of the basic authentication.

like image 120
Eirini Graonidou Avatar answered Oct 18 '22 06:10

Eirini Graonidou


wsimport, wsdl2java, maven-jaxb2 are meant for generating Proxy classes out of the Descriptor file. Since you are getting Unauthorized (401), it could be either due to wrong creds or may be you are not sending credentials et all in a request.

For Basic Auth, refer another stackoverflow question here

Also, if you can post your exact code here where you configure the Creds, it will be helpful in identifying the cause

like image 37
Sunil Singhal Avatar answered Oct 18 '22 07:10

Sunil Singhal