gpt4 book ai didi

java - 使用 over SSL redirection 使用 Web 服务

转载 作者:太空宇宙 更新时间:2023-11-03 13:43:03 24 4
gpt4 key购买 nike

我已经使用 CXF 部署了一个契约优先的网络服务。

部署它的服务器执行从 http 到 ssl 的 302 次重定向,因此对 http://server/app/ 的任何请求* 返回 HTTP 302 错误代码并重定向到 https://server/app/ *。

在原始的 WSDL 中,有对另一个 namespace 中的 XSD 元素的引用,因此生成的 WSDL(http://server/app/services/MyService?wsdl 提供的)包含一个 <wsdl:import>元素。

如果我尝试通过在字符串中手动构建 SOAP 请求并通过 SSL 套接字发送它来调用 WS,WS 会正确响应。我的 keystore 中有所有必要的证书。

但是,当我尝试使用 CXF 的 wsdl2java 指向 https://server/app/services/MyService?wsdl 构建客户端时,我收到以下错误(下面是完整的堆栈跟踪):

[Fatal Error] MyService?wsdl=MyServicePortType.wsdl:1:50: 
White spaces are required between publicId and systemId.

跟踪是指 <wsdl:import>陈述。它的location属性是 http://server:80/app/services/MyService?wsdl=MyServicePortType.wsdl .我的猜测是由于 302 重定向而引发了错误。应该是https://server/app/services/MyService?wsdl=MyServicePortType.wsdl相反。

原始的 WSDL 是 URL 不可知的,服务的 URL 在 Spring 中定义为相对的 <jaxws:endpoint>元素。它通过 CXF servlet 访问。也就是说,没有 <soap:address>原始 WSDL 中的元素 <wsdl:port> .

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<bean id="myServiceBean" class="mypackage.MyServiceImpl" />
<jaxws:endpoint
id="myServiceEndpoint"
implementor="#myServiceBean"
address="/MyService">
</jaxws:endpoint>

我应该在服务的自动生成类、WSDL 或 Spring 配置中的某处指定该服务将部署在 SSL 上吗?我该怎么做?

编辑:可能相关的链接:

完整的堆栈跟踪:

D:\>wsdl2java -d src -client -impl -verbose -db xmlbeans -autoNameResolution -validate -compile -classdir classes https://server/app/services/MyService?wsdl
Loading FrontEnd jaxws ...
Loading DataBinding xmlbeans ...
wsdl2java -d src -client -impl -verbose -db xmlbeans -autoNameResolution -valida
te -compile -classdir classes https://server/app/services/MyService?wsdl
wsdl2java - Apache CXF 2.3.2

[Fatal Error] MyService?wsdl=MyServicePortType.wsdl:1:50: White spaces are required between publicId and systemId.

WSDLToJava Error: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition from : https://server/app/services/MyService?wsdl
Caused by : WSDLException (at /wsdl:definitions/wsdl:import): faultCode=PARSER_ERROR: Problem parsing 'http://server:80/app/services/MyService?wsdl=MyServicePortType.wsdl'.: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.

org.apache.cxf.tools.common.ToolException: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition from : https://server/app/services/MyService?wsdl
Caused by : WSDLException (at /wsdl:definitions/wsdl:import): faultCode=PARSER_ERROR: Problem parsing 'http://server:80/app/services/MyService?wsdl=MyServicePortType.wsdl'.: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:288)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:184)
Caused by: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition from : https://server/app/services/MyService?wsdl
Caused by : WSDLException (at /wsdl:definitions/wsdl:import): faultCode=PARSER_ERROR: Problem parsing 'http://server:80/app/services/MyService?wsdl=MyServicePortType.wsdl'.: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at org.apache.cxf.wsdl11.WSDLDefinitionBuilder.parseWSDL(WSDLDefinitionBuilder.java:97)
at org.apache.cxf.wsdl11.WSDLDefinitionBuilder.build(WSDLDefinitionBuilder.java:69)
at org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.build(JAXWSDefinitionBuilder.java:84)
at org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.build(JAXWSDefinitionBuilder.java:61)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:170)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:137)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:280)
... 4 more
Caused by: javax.wsdl.WSDLException: WSDLException (at /wsdl:definitions/wsdl:import): faultCode=PARSER_ERROR: Problem parsing 'http://server:80/app/services/MyService?wsdl=MyServicePortType.wsdl'.: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.parseImport(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:237)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:186)
at org.apache.cxf.wsdl11.WSDLDefinitionBuilder.parseWSDL(WSDLDefinitionBuilder.java:78)
... 10 more
Caused by: org.xml.sax.SAXParseExceptionpublicId: http://server:80/app/services/MyService?wsdl=MyServicePortType.wsdl; systemId: http://server:80/app/services/MyService?wsdl=MyServicePortType.wsdl; lineNumber: 1; columnNumber: 50; White spaces are required between publicId and systemId.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
... 18 more

最佳答案

事实证明服务实现mypackage.MyServiceImpl缺少 javax.jws.WebService 注解。

一旦包含在正确的 serviceName 中, portName , targetNamespace , 和 endpointInterface属性,没有 <wsdl:import> 部署的服务.我怀疑这主要与 targetNamespace 有关属性。

但是,外部 XSD 仍然会被 http 地址引用,例如 <xsd:import schemaLocation="http://server:80/app/schema/myschema.xsd"> .我在原始 WSDL 中相对地引用了它们。对我来说,唯一的解决方案是在原始 WSDL 中内联所有 XSD 定义。

关于java - 使用 <wsdl :import> over SSL redirection 使用 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9598058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com