Unable to parse SOAP response - java

I am using JAX-WS to call a SOAP webservice. While parsing a SOAP response getting below exception. My SOAP client is a JAR which is running inside another web application deployed in Weblogic server.
javax.xml.soap.SOAPException: Error parsing envelope: most likely due to an invalid SOAP message.: Unexpected EOF in prolog
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog at [row,col {unknown-source}]: [1,0]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2139)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2045)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1134)
at oracle.j2ee.ws.saaj.util.ResettableXMLStreamReader.next(ResettableXMLStreamReader.java:218)
at oracle.j2ee.ws.saaj.soap.StaxHandler.moveNext(StaxHandler.java:213)
at oracle.j2ee.ws.saaj.soap.StaxHandler.staxParse(StaxHandler.java:117)
at oracle.j2ee.ws.saaj.soap.StaxHandler.staxParse(StaxHandler.java:105)
at oracle.j2ee.ws.saaj.soap.StaxHandler.staxParse(StaxHandler.java:88)
at oracle.j2ee.ws.saaj.soap.AbstractSOAPImplementation.getStaXParsedEnvelope(AbstractSOAPImplementation.java:235)
at oracle.j2ee.ws.saaj.soap.AbstractSOAPImplementation.createEnvelope(AbstractSOAPImplementation.java:70)
Surprisingly I am able to print the SOAP response in the logs.

Related

Different result/output for same wsdl in Postman, SOAP UI, jdeveloper Http Analyzer

I have a wsdl url which is giving different result when I am testing with Postman, SOAP UI, Jdeveloper Http Analyzer even tough passing same request header and body in all tools.
In Postman, Jdeveloper Http Analyzer it's wsdl returning same 500-Internal server error.
In SOAP UI, it's returning correct result.
I have created Custom Java client application in jdeveloper to consume webservice, in that I am getting below error
The Error
Exception in thread "main" com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: application/xml Supported ones are: [text/xml]
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:220)
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:151)
at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:299)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:268)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:217)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:130)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:95)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:448)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:178)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
at com.sun.proxy.$Proxy36.getService(Unknown Source)
at someClient.SomeClient.main(WaselClient.java:23)
How can i solve this issue?
When I am importing wsdl into SOAPUI request payload is loading without spaces in the header parameter.
for eg., content-type=”text/xml;charset=utf-8”(check there is no gap between xml; and charset),
where as in postman and jdeveloper http analyzer request payload is loading with spaces in the header parameter. content-type=”text/xml; charset=utf-8”(check there is a gap between xml; and charset).
Due to this it was giving different result.

Spring REST Template java.net.SocketException: Unexpected end of file from server

I have a REST Web Service made with Spring MVC 3.2.0 that calls others REST Web Services also with Spring MVC. I'm having the following exception:
25-11-2014 17:49:42-ERROR-ajp-/172.23.111.22:8109-9-pe.com.dummy.BusinessDummyImpl- I/O error on POST request for "http://172.23.111.23/dummy-2/rest/method1":Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://172.23.111.23/dummy-2/rest/method1":Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:499)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:447)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:295)
Caused by: java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:747)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:608)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1334)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:479)
at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
at org.springframework.web.client.DefaultResponseErrorHandler.getHttpStatusCode(DefaultResponseErrorHandler.java:55)
at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:49)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:485)
... 42 more
It happens randomly and when I check the log on dummy-2 WS there is no trace of error.
What can be causing this error?

JAX-WS + SOAP: How to parse HTTP Client Error

I'm using JAX-WS + SOAP to communicate to a webservice. I can handle the SOAP message (handleFault) but i cannot understand how to catch HTTP errors, because they occur under the HTTP Java client layer...
com.sun.xml.ws.client.ClientTransportException: The server sent HTTP status code 412: Precondition Failed
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:203)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:177)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
at com.sun.xml.ws.client.Stub.process(Stub.java:222)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:135)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:109)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
I know the server should include an entity containing an explanation of the error situation (and, in fact, i've been told it's doing just that).
My question is: HOW to reach that "entity"?
Looks like web service is not implemented according to specification. According to W3C Note 08 May 2000 on SOAP 1.1 (same with SOAP 1.2):
In case of a SOAP error while processing the request, the SOAP HTTP server MUST issue an HTTP 500 "Internal Server Error" response and include a SOAP message in the response containing a SOAP Fault element (see section 4.4) indicating the SOAP processing error.
Even if there is some "entity" I don't think you should handle that in your application. It would be definitely a hack. If you need to learn what entity is it only once, just use some sniffer tool like Wireshark.
If you really want to ignore HTTP status code you can switch to CXF as a JAX-WS implementation. There you can disable checking HTTP code:
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(hw);
client.getRequestContext().put("org.apache.cxf.http.no_io_exceptions", "true");

Java Web Service error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog

I have a problem creating and connecting a Java client to a running Web Service.
I use the following code:
Service myService = null;
URL wsdlLocation = new URL("http://myservice?wsdl");
QName serviceName = new QName(wsdlLocation, "MyService");
Service myService = new Service(wsdlLocation, serviceName);
where the Service class was created with the following command:
wsimport -d gen -keep http://myservice?wsdl
I've also tried with a client generated by Apache cxf 2.4's wsdl2java, but got the same result.
(I've changed the WSDL location and Service class name only for this post, in the code I use the original ones.)
But I get an exception when I call the Web Service deployed on the appserver, when creating the service with the new Service() command.
But: I've tested the wsdl location with SOAP UI and it works perfectly.
Also, I've created a Mock Service using Soap UI and my Java client could connect to it, call it and get the results back.
The problem appears when I want' to call the web service running on the appserver.
Stacktrace:
javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:149)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:98)
at javax.xml.ws.Service.<init>(Service.java:76)
at MyService.<init>(MyService.java:42)
at mypackage.createService(AClass.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:100)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:199)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
... 12 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
at [row,col,system-id]: [1,0,"http://myservice?wsdl"]
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:256)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:205)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
... 14 more
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
at [row,col,system-id]: [1,0,"http://myservice?wsdl"]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2139)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2045)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1134)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1248)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1142)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1069)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:247)
... 16 more
Could someone please help me?
I encountered this error and found that it appeared to be due to using a URL that returned an HTTP 302 redirect instead of the WSDL directly.
The URL I was using was in the format /Service?wsdl, which redirected to a URL in the format /Service/wsdl/Service.wsdl. Once I used the redirect target URL directly, everything worked.
I remember reading that it could be related to the endpoint expecting a trailing '/'. I'm not sure if this valid, but please try it and post here it if works.
I had a similar error and when I checked the server logs - it was related to http server having encountered an unsupported http method in request. Due to this teh server returns an HTTP response that the SOAP client cannot handle ... hence Unexpected EOF in prolog
Below is a snippet my web-server log for tomcat "localhost.XXXX.log"
org.apache.tomcat.util.descriptor.web.SecurityConstraint.findUncoveredHttpMethods For security constraints with URL pattern [/services/*] only the HTTP methods [POST GET] are covered. All other methods are uncovered.
This gave following error on client side
com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
In my case since I was downgrading a secured service to unsecured and my web.xml had following stray entry that was restricting GET and post with a security constraint and I wasnt sending needed security parameters in the request..
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted web services</web-resource-name>
<url-pattern>/services/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
I removed this constraint to get rid of this error :-)
In your case it may not related to security constraint - but for sure its related to server sending raw http response - Please check your server/ client configuration and ensure it sends appropriate http request that are liked by http server
I had a similar error and when I checked the server logs - it was related to http server having encountered an unsupported http method in request returns an HTTP response that the SOAP client cannot handle ... check your web-server logs
Surely this isn't due to character or format issue.
It's possible that the server didn't return any data, of which the Woodstox (wstx) was trying to parse into XML and failed, which resulted to this error.
I had similiar issue and i have resolved with debugging.
When i try to download WSDL in runtime i found that i could not get the WSDL because of the proxy.
Please check that you can access the WSDL in runtime like this code:
try {
String wsdl = org.apache.commons.io.IOUtils.toString(new URL("http://YOUR_WSDL_URL"));
System.out.println("WSDL => "+wsdl);
} catch (IOException e) {
e.printStackTrace();
}
One of the imports are missing. Please check routes to your xsd's.
I had the same problem. I had to use the full path to the WSDL file to make it works.
My contribution to this error is this:
I don't get this error when I am in debugging mode.
It seems that when the executor of the Java program that queries the WSDL Service (Java in my case) has the time to perform many requests, like in debugging mode, because of when sometimes the programs stops because I put some breakpoints, in this case I don't get this error.
When I run the program in production mode, yes.
But the requests are the same, the WSDL doesn't change, as well ad the endpoints.
It's like a limitation of the web Server, I think.

java.security.PrivilegedActionException while hitting webservices over https

I am getting the following exception, when i am trying to hit the webservice over https using java client:
com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
SEVERE: SAAJ0009: Message send failed
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Message send failed
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:157)
at
Also if i use the same code for http , it works fine. Webservices are deployed on weblogic server.
Could anyone help me in resolving the issue.
Regards
Gurleen.
The exception says that message cannot be sent.
Is it a firewall problem like for the same question here : http://www.coderanch.com/t/223309/Web-Services/java/Sending-Soap-requests-thru-Https

Categories