Java Webserver 生成格式错误的 services.wsdl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9772857/
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
Webserver generates badly formatted services.wsdl
提问by ubuntudroid
I have a Tomcat 7.0 web server which I use to run a web service on it. The web service framework is CXF 2.5.2.
我有一个 Tomcat 7.0 Web 服务器,用于在其上运行 Web 服务。Web 服务框架是 CXF 2.5.2。
When testing the web service from the Eclipse Web Service Explorer everything works as supposed. However, when generating a Java Client from the WSDL (using Eclipse) and running it, I get the following error when calling super(wsdlLocation, serviceName)
from the Service implementation:
从 Eclipse Web Service Explorer 测试 Web 服务时,一切都按预期工作。但是,当从 WSDL(使用 Eclipse)生成 Java 客户端并运行它时,super(wsdlLocation, serviceName)
从服务实现调用时出现以下错误:
Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:150)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:91)
at javax.xml.ws.Service.<init>(Service.java:77)
at test.Test_Service.<init>(Test_Service.java:43)
at test.Test_TestSOAP_Client.main(Test_TestSOAP_Client.java:47)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:94)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:148)
... 4 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'c' (code 99) in start tag Expected a quote at [row,col,system-id]: [1,208,"http://www.example.com:8081/TestWS/services?wsdl"]
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:240)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:191)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92)
... 6 more
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'c' (code 99) in start tag Expected a quote at [row,col,system-id]: [1,208,"http://www.example.com:8081/TestWS/services?wsdl"]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:639)
at com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java:3005)
at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:2926)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2802)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1050)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1080)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:974)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:901)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:231)
... 8 more
The interesting part should be the Unexpected character 'c' (code 99) in start tag Expected a quote
at [row,col,system-id]: [1,208,"http://www.example.com:8081/TestWS/services?wsdl"]
message. When inspecting the generated services.wsdl, I found, that the problem is in the meta part:
有趣的部分应该是Unexpected character 'c' (code 99) in start tag Expected a quote
at [row,col,system-id]: [1,208,"http://www.example.com:8081/TestWS/services?wsdl"]
消息。在检查生成的 services.wsdl 时,我发现问题出在元部分:
<meta http-equiv=content-type content="text/html; charset=UTF-8">
content-type
should be normally wrapped into quotes. Is this a known bug in one of the used frameworks/servers? What can I do to work around this? And why is there no problem when using the Eclipse Web Services Explorer? Is it more fault-tolerant (as my Firefox seems to be as it also doesn't have any problems to display a graphical representation of the generated wsdl).
content-type
通常应该用引号括起来。这是使用的框架/服务器之一中的已知错误吗?我能做些什么来解决这个问题?为什么在使用 Eclipse Web Services Explorer 时没有问题?它是否更容错(因为我的 Firefox 似乎是因为它也没有任何问题来显示生成的 wsdl 的图形表示)。
采纳答案by ubuntudroid
Found the problem. I accidentally specified the WSDL endpoint as http://www.example.com:8081/TestWS/services
instead of http://www.example.com:8081/TestWS/services/MyTestWS
. So the automatically generated client tried to fetch the WSDL from http://www.example.com:8081/TestWS/services?wsdl
which returns an HTML page, instead of http://www.example.com:8081/TestWS/services/MyTestWS?wsdl
which returns an actual WSDL.
发现问题了。我不小心将 WSDL 端点指定http://www.example.com:8081/TestWS/services
为http://www.example.com:8081/TestWS/services/MyTestWS
. 因此,自动生成的客户端尝试获取http://www.example.com:8081/TestWS/services?wsdl
返回 HTML 页面的 WSDL ,而不是http://www.example.com:8081/TestWS/services/MyTestWS?wsdl
返回实际的 WSDL。
回答by kevinjansz
This looks like an issue/bug with the CXF service listing generation. In org.apache.cxf.transport.servlet.servicelist.FormattedServiceListWriter
source (around line 52):
这看起来像是 CXF 服务列表生成的问题/错误。在org.apache.cxf.transport.servlet.servicelist.FormattedServiceListWriter
源代码中(第 52 行左右):
writer.write("<meta http-equiv=content-type content=\"text/html; charset=UTF-8\">");
i.e. the http-equiv
value is unquoted. So there's no problem with the other tools because they're more "fault-tolerant" - as you guessed.
即该http-equiv
值不带引号。所以其他工具没有问题,因为它们更“容错”——正如你猜的那样。
I'm not sure what the com.ctc.wstx.*
classes are as it looks like this is where the validation is happening and the error is being thrown. If it's something you have control over, a (temporary) work around may be to run HTMLTidy over the service listing page?
我不确定这些com.ctc.wstx.*
类是什么,因为看起来这是验证发生和错误被抛出的地方。如果这是您可以控制的事情,(临时)解决方法可能是在服务列表页面上运行 HTMLTidy?
May be worth mentioning on the CXF mail-list or raising a bug?
可能值得在 CXF 邮件列表中提及或引发错误?
回答by Daniel Kulp
The service list page is an HTML page listing the services and providing links to the appropriate WSDL documentes for those services (or WADL docs for the rest based services). It's not a WSDL document. Parsing it as a WSDL would not work.
服务列表页面是一个 HTML 页面,列出服务并提供指向这些服务的适当 WSDL 文档(或基于其余服务的 WADL 文档)的链接。它不是 WSDL 文档。将其解析为 WSDL 是行不通的。
回答by Sandeep
I had same exception once and it was because in a configuration file at one place I was missing doule quotes.. example destination-name=closeTaskService
我有一次同样的异常,这是因为在一个地方的配置文件中我缺少双引号..示例 destination-name=closeTaskService
fix was destination-name="closeTaskService"
, error was some thing like below
org.jboss.deployment.DeploymentException: Unexpected character 'c' (code 99)
in start tag Expected a quote
修复是destination-name="closeTaskService"
,错误是类似于下面org.jboss.deployment.DeploymentException: Unexpected character 'c' (code 99)
开始标记中的一些内容
需要引用