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.