通过SSL重定向使用消费web服务
我已经使用CXF部署了合同优先的Web服务。通过SSL重定向使用<wsdl:import>消费web服务
将其部署到的服务器执行302从http到ssl的重定向,因此任何到http://server/app/ *的请求都会返回HTTP 302错误代码并重定向到https://server/app/ *。
在原始WSDL中有对另一个命名空间中的XSD元素的引用,所以生成的WSDL(提供的那个)包含一个<wsdl:import>
元素。
如果我尝试通过手动构建一个字符串中的SOAP请求并通过SSL套接字发送它来调用WS,那么WS响应正确。我已在我的密钥库中获得所有必需的证书。
但是,当我尝试建立利用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元素中相对定义。它通过CXF servlet访问。也就是说,原始WSDL的<wsdl:port>
中没有<soap:address>
元素。
<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?我怎么能这样做?
编辑: 可能相关链接:上markmail
完整的堆栈跟踪:
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定义。