InaccessibleWSDLException error from SOAP generated client in JAVA - java

We are working with service provider's wsdl which is not discoverable due to security reason and they provide us a bunch of files including wsdl ,xsd etc.We need to access the provider's api. For these reason we have done these following things:
We have generated a web service client using netbean 8.0 form desktop location (Local File )
Using generated client code we have called the api using these following code
URL url = new URL("http://serverip:port/payment/services/MgrService");
MgrService svc = new MgrService(url);
Response response = svc.getMgrServicePort().apiRequest(request);
but getting these exception
com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
java.io.IOException: Server returned HTTP response code: 500 for URL: http://serviceip:port/payment/services/MgrService
java.io.IOException: Server returned HTTP response code: 500 for URL: http://serviceip:port/payment/services/MgrService?wsdl
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:260)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:231)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:194)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:163)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:348)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:306)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:215)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:196)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:192)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:104)
at javax.xml.ws.Service.<init>(Service.java:77)
By Wireshark, we have noticed that it is calling a get method with no soap body, where it should call only post method . We have tested the api using soapUI , service is ok . We also getting successful response using raw xml soap request.
Is it possible to work with generated client both for JAX-WS and Spring WS when WSDL is not discoverable ? or it only work with JAX-WS's wsdl file.
If so then do we need to edit wsdl? or some other approach

After few research, I have found these !
1)For Spring WS, generated client is not working (As like Netbean Generated SOAP client)
2) This link help me a lot to consume a Spring-WS service using Spring STS
Consuming a SOAP web service
but few things need to be done before you proceed
a) fix maven-jaxb2-plugin version to lower version (0.12.1)
b) add a binding.xjb file with these contains
<?xml version="1.0"?>
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc= "http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings>
<jxb:globalBindings>
<xjc:simple/>
</jxb:globalBindings>
</jxb:bindings>
</jxb:bindings>
other wise xjc will not work
3) Copy wsdl & xsd files to local project directory and pom configuration will
be as follows (for scenario where wsdl is not hosted for security reason)
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
</configuration>
3)It is not recommended to edit the wsdl file

Related

Impossible to generate java client code from some wsdl

I'm trying with this specific URL:
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.7.9</version>
<configuration>
<wsdlFile>https://web.rbsuat.com/ab/webservices/merchant-ws?wsdl</wsdlFile>
</configuration>
</plugin>
But got the exception during the plugin execution:
[ERROR] Failed to execute goal org.apache.axis2:axis2-wsdl2code-maven-plugin:1.7.9:wsdl2code (default-cli) on project test: Error parsing WSDL: Connection reset -> [Help 1]
The most likely is that it would be SSLv3 related issue for the newset java when the SSLv3 is disabled and I should enable it by removing the
jdk.tls.disabledAlgorithms=SSLv3
from JRE_HOME/lib/security/java.security, however, I did it and still face the same problem
Actually, the URL https://web.rbsuat.com/ab/webservices/merchant-ws?wsdl can be reached from the browser without any problem.
1 - To generate Java client from a given WSDL file, you can use SoapUI tool to achieve that by following the instructions given in below links. It basically shows you how you can use different code generation tools like Axis 1.X, Axis 2, CXF 2.X, and .NET 2.0 to generate client code.
SOAP Code Generation
Generating Client JAVA code for WSDL using SOAP UI
2 - Once the Java client code is generated you can add the following parameter in your Java client before calling the external service to generate the SSL logs.
System.setProperty("javax.net.debug", "all");
Then by seeing the SSL logs will come to know what is the problem you are facing when trying to call this service.
the IDE didn't picked up my config changes in jre folder until it was restarted, that was the reason. I had to restart my IDE

How to add Authentication Header to WebService Stub?

I have generated stubs using Apache CXF, IBM Jax-WS and Axis as well in Eclipse and RAD 7.0 .
In all the 3 above scenarios it gives me the following exception
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: ARERR [149] A user name must be supplied in the control record
After searching i concluded that i have to add Authentication Info to the Soap header created by Client Stubs.
i tried the answer on this link
How do you add a Soap Header defined in a wsdl to a web service client in CXF?
but couldn't succeed. I am newbie to SOAP and WebServices
So if anyone has worked on it kindly Help.
I had this problem a few days ago and it was a headache for me. When generating the stubs you have to add a the flag -XadditionalHeaders to the wsimport command.
"C:\Program Files\Java\jdk1.X.X_XX\bin\wsimport.exe" -p com.company.package -keep -XadditionalHeaders -d folder1 http://mywsdllocation.com/doc.wsdl
Where:
-p: package that will contain generated classes
-keep: keep .java files (otherwise tou'll only get .class files)
-XadditionalHeaders: classes for authentication will be created
-d: Folder where generated classes will be placed.
After that, you only have to copy generated java files to your project, under the picked package (com.company.package in this case). Then you have you create an AuthenticationInfo object and inserting it in the stub method's call, something like this:
WSService service = new WSService();
WSPortTypePortType port = service.WSPortTypeSoap();
AuthenticationInfo auth = new AuthenticationInfo();
auth.setUserName(yourUsername);
auth.setPassword(yourPassword);
port.method(param1,param2,auth);
Hope it helps!

SugarCRM, WSDL and RPC

There are many url for SugarCRM CE Web Service API like:
http://localhost/soap.php?wsdl
AND
http://localhost/service/v2/soap.php?wsdl
http://localhost/service/v3/soap.php?wsdl
http://localhost/service/v4/soap.php?wsdl
http://localhost/service/v4_1/soap.php?wsdl
They all produce WSDL for RPC/Encoded
When I consume the WSDL using wscompile Java tool with command line
wscompile -gen:client config.xml -keep
and config.xml contains
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<wsdl location="http://localhost/service/v4_1/soap.php?wsdl" packageName="com.crm.imported"/>
</configuration>
I could get the generated classes.
But all the URLs have different structure in the generated classes.
Moreover, only the classes generated by http://localhost/soap.php?wsdl is working and the rest of them give error:
java.rmi.RemoteException: Runtime exception; nested exception is:
unexpected element type: expected={http://www.w3.org/2001/XMLSchema}QName, actual={http://www.w3.org/2001/XMLSchema}int
My Questions:
What is the difference in the API versions?
What is this XMLSchema QName error? How to solve it.
I got the answers:
All the API version have different implementations.
For example: Later versions expect password to be MD5 coded.
XMLSchema Error is raised by providing wrong information to the parameters.
java.rmi.RemoteException will simply give the error message irrelevantly.

SoapUI error on request - NoClassDefFoundError

I am new to web services and I have deployed a web service locally ( I am able to see the wsdl)
I tried to query the web service by creating a request in SOAPUI.
The response I got back was
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>java.lang.NoClassDefFoundError: org/apache/commons/lang/StringEscapeUtils
</faultstring>
</env:Fault>
I see a bunch of errors in the jboss console in eclipse...
11:53:06,226 ERROR [SOAPFaultHelperJAXWS]
SOAP requestexceptionjava.lang.RuntimeException:
java.lang.NoClassDefFoundError:org/apache/commons/lang/StringEscapeUtils
Can someone help me in figuring out what the problem could be?
Is something wrong with the way I setup my SOAPUI or is it I missed something in my project(web service server)
You need commons-lang.jar in your classpath
How do you exactly deploy the web service? For example, if you create an .aar archive, please verify that the corresponding jar (commons-lang.jar?) is available into the lib folder of the archive. For example:
your_service_root
->META-INF
->lib
->commons-lang.jar
-> com
->bla
->bla

XMLBeans - xsi:type stripped using Axis2 and Tomcat?

I’m new to XMLBeans and have been trying to use it to create an XML document as part of an axis2 web service. When I run my code as a standard Java application or as a standard servlet, the XML is correctly generated:
<?xml version="1.0" encoding="UTF-8"?>
<c:BroadsoftDocument protocol="OCI" xmlns:c="C">
<sessionId>000000001</sessionId>
<command xsi:type="AuthenticationRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<userId>admin</userId></command>
</c:BroadsoftDocument>
However, when the exact same code is run under Axis2 & Tomcat in a servlet I get:
<?xml version="1.0" encoding="UTF-8"?>
<c:BroadsoftDocument protocol="OCI" xmlns:c="C">
<sessionId>000000001</sessionId>
<command>
<userId>admin</userId></command>
</c:BroadsoftDocument>
This of course isn’t valid – the xsi:type of the “command” element is stripped when the code is run under Tomcat.
Does anyone have any suggestions of what I could be doing wrong that would cause this type of issue only when running under Axis2? At first I thought it was a Tomcat issue, but after creating a generic servlet and running the exact same code I don't have any issues. I've tried playing with the XMLOptions for XMLBeans, but couldn't seem to resolve the problem. The options I'm currently using are:
xmlOptions = new XmlOptions();
xmlOptions.setCharacterEncoding("UTF-8");
xmlOptions.setUseDefaultNamespace();
xmlOptions.setSaveAggressiveNamespaces();
xmlOptions.setSavePrettyPrint();
It turn out the issue is with the class loader order that Axis2 uses. This was patched and the functionality is described here:
http://marc2.theaimsgroup.com/?l=axis-cvs&m=115946726426905&w=3
Long story short, to resolve this issue you need to edit the "services.xml" for your Axis2 project and add:
<parameter name="ServiceTCCL">composite</parameter>

Categories