Java Web 服务错误:com.ctc.wstx.exc.WstxEOFException:序言中出现意外的 EOF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18761597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Web Service error: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
提问by Kumite
I have a problem creating and connecting a Java client to a running Web Service.
我在创建 Java 客户端并将其连接到正在运行的 Web 服务时遇到问题。
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:
其中 Service 类是使用以下命令创建的:
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.
我也尝试过使用由 Apache cxf 2.4 的 wsdl2java 生成的客户端,但得到了相同的结果。
(I've changed the WSDL location and Service class name only for this post, in the code I use the original ones.)
(我只为这篇文章更改了 WSDL 位置和服务类名称,在代码中我使用了原始的。)
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.
但是,当我使用 new Service() 命令创建服务时调用部署在应用程序服务器上的 Web 服务时出现异常。但是:我已经使用 SOAP UI 测试了 wsdl 位置并且它运行良好。此外,我使用 Soap UI 创建了一个模拟服务,我的 Java 客户端可以连接到它,调用它并返回结果。当我想调用在应用程序服务器上运行的 Web 服务时会出现问题。
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?
有人可以帮助我吗?
采纳答案by Michael R
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.
我遇到了这个错误,发现它似乎是由于使用了返回 HTTP 302 重定向而不是直接返回 WSDL 的 URL。
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.
我使用的 URL 是格式/Service?wsdl
,它重定向到格式的 URL /Service/wsdl/Service.wsdl
。一旦我直接使用重定向目标 URL,一切正常。
回答by Somaiah Kumbera
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.
我记得读过它可能与期望尾随 '/' 的端点有关。我不确定这是否有效,但请尝试并在此处发布如果有效。
回答by Somaiah Kumbera
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
我有一个类似的错误,当我检查服务器日志时 - 它与 http 服务器在请求中遇到不受支持的 http 方法有关,返回一个 SOAP 客户端无法处理的 HTTP 响应......检查您的网络服务器日志
回答by Yogesh Devi
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"
我有一个类似的错误,当我检查服务器日志时 - 它与 http 服务器在请求中遇到不受支持的 http 方法有关。由于这个服务器返回一个 SOAP 客户端无法处理的 HTTP 响应......因此在序言中出现意外的 EOF 下面是一个片段我的网络服务器日志的 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..
在我的情况下,因为我将安全服务降级为不安全,并且我的 web.xml 有以下杂散条目,该条目限制了 GET 并使用安全约束发布,并且我没有在请求中发送所需的安全参数..
<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
在您的情况下,它可能与安全约束无关-但肯定与服务器发送原始 http 响应有关-请检查您的服务器/客户端配置并确保它发送 http 服务器喜欢的适当 http 请求
回答by Gonzalo Aguilar Delgado
One of the imports are missing. Please check routes to your xsd's.
其中一件进口货不见了。请检查您的 xsd 的路线。
回答by Julio D
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.
这当然不是由于字符或格式问题。可能是服务器没有返回任何数据,Woodstox (wstx) 试图将其中的数据解析为 XML 并失败,从而导致此错误。
回答by Daryl Le
I had the same problem. I had to use the full path to the WSDL file to make it works.
我有同样的问题。我必须使用 WSDL 文件的完整路径才能使其工作。
回答by kkurt
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:
我有类似的问题,我已经通过调试解决了。当我尝试在运行时下载 WSDL 时,我发现由于代理而无法获取 WSDL。请检查您是否可以像以下代码一样在运行时访问 WSDL:
try {
String wsdl = IOUtils.toString(new URL("http://YOUR_WSDL_URL"));
System.out.println("WSDL => "+wsdl);
} catch (IOException e) {
e.printStackTrace();
}
回答by RobyB
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.
似乎当查询 WSDL 服务的 Java 程序的执行程序(在我的情况下为 Java)有时间执行许多请求时,例如在调试模式下,因为有时程序会因为我放置一些断点而停止,在这种情况下我没有收到这个错误。
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.
但是请求是相同的,WSDL 没有改变,端点也一样。
It's like a limitation of the web Server, I think.
我认为这就像网络服务器的限制。