Java web service error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog

I had a problem creating and connecting a Java client to a running web service.

I am using 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 also tried with the client created by Apache cxf 2.4 wsdl2java, but got the same result.

(I changed the location of the WSDL and the class name of the service only for this message, in the code I use the original ones.)

But I get an exception when I call the web service deployed on the application server when creating the service using the new Service () command. But: I tested the wsdl location using the SOAP UI and it works fine. In addition, I created the Mock Service using the Soap UI, and my Java client could connect to it, call it, and return the results. The problem occurs when I want to "call a web service running on the application server."

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 

Can anyone help me out?

+7
java wsdl web-services jax-ws wsimport
source share
7 answers

I remember reading that this could be due to the endpoint awaiting the final "/". I'm not sure if this is true, but please try it and post it here if it works.

+2
source share

I had a similar error, and when I checked the server logs - it was connected to an http server that encountered an unsupported http method in the request, it returns an HTTP response that the SOAP client cannot process ... check your web logs server

+1
source share

I had a similar error, and when I checked the server logs - this was due to the http server that encountered an unsupported http method in the request. Because of this, the server returns an HTTP response that the SOAP client cannot handle ... hence the Unexpected EOF in the prologue The following is a snippet of 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 the following client side error

  com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog 

In my case, since I was redefining the protected service as unsecured, and my web.xml had the following random entry, which limited GET and sent it with a security restriction, and I did not send the necessary security settings to 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 restriction to get rid of this error :-)

In your case, this may not be due to a security restriction - but, of course, this is due to the server sending a raw HTTP response. Please check the server / client configuration and make sure that it sends the appropriate HTTP request that the http server likes

+1
source share

I ran into this error and found that this was due to the use of a URL that redirects HTTP 302 directly instead of WSDL.

The URL I used was in the format /Service?wsdl , which redirected to a URL in the format /Service/wsdl/Service.wsdl . Once I used the redirect destination URL directly, everything worked.

0
source share

One of the imports is missing. Check the routes on your xsd.

0
source share

Undoubtedly, this is not due to a character or format problem. Perhaps the server did not return any data, from which Woodstox (wstx) tried to parse XML and could not, which led to this error.

0
source share

I had the same problem. I had to use the full path to the WSDL file to make it work.

0
source share

All Articles