Generate java classes from a wsdl url with basic authentication

爱⌒轻易说出口 提交于 2019-12-22 08:08:44

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/45795362/generate-java-classes-from-a-wsdl-url-with-basic-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!