使用JAX-WS进行应用程序身份验证

时间:2015-08-06 11:36:54

标签: web-services wsdl cxf wsimport webservices-client

使用wsimport工具(使用jaxws-maven-plugin:wsimport目标)为JAX-WS Web服务创建客户端API。生成的API工作得很好。现在,当引入安全性并且在更新的WSDL文件上再次运行wsimport时,我收到了一个错误:

[INFO] jaxws:wsimport args: [-s, C:\projects\EDMS2.0.0\docmgmt\docmgmt-client\src\main\java, -d, C:\projects\EDMS2.0.0\docmgmt\docmgmt-client\target\classes, -verbose, -p, com.abc.technology.retrieve.document.client.v1, C:\projects\EDMS\docmgmt\docmgmt-client\src\wsdl\RetrieveDocument\Technology-RetrieveDocument.wsdl]
parsing WSDL...


[ERROR] unknown required extensibility element "wsp:PolicyReference" (in namespace "http://www.w3.org/ns/ws-policy")
  line 65 of file:/C:/projects/EDMS/docmgmt/docmgmt-client/src/wsdl/RetrieveDocument/Technology-RetrieveDocument.wsdl

    Failed to parse the WSDL.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------`

WSDL文件:

<?xml version='1.0' encoding='UTF-8'?>
<wsdl11:definitions xmlns:wsdl11="http://schemas.xmlsoap.org/wsdl/" xmlns:soap11="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:whttp="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http:/schemas.xmlsoap.org/wsdl/mime/"
   xmlns:tns="http://services.abc.com/Technology/RetrieveDocument/service/v1"
   xmlns:wsp="http://www.w3.org/ns/ws-policy" targetNamespace="http://services.abc.com/Technology/RetrieveDocument/service/v1"
   xmlns:exceptions="http://services.abc.com/exceptions" xmlns:abc="http://services.abc.com/framework/abcHeader/v2"
   xmlns:contract="http://services.abc.com/Technology/RetrieveDocument/contract/v1">  <!--BEGIN ABSTRACT DESCRIPTION-->
  <wsdl11:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:contract="http://services.abc.com/Technology/RetrieveDocument/contract/v1"
       targetNamespace="http://services.abc.com/Technology/RetrieveDocument/contract/v1">
      <xsd:include schemaLocation="RetrieveDocument_v1.xsd"/>
    </xsd:schema>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:exceptions="http://services.abc.com/exceptions"
       targetNamespace="http://services.abc.com/exceptions">
      <xsd:include schemaLocation="CnaExceptions.xsd"/>
    </xsd:schema>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:abc="http://services.abc.com/framework/abcHeader/v2"
       targetNamespace="http://services.abc.com/framework/abcHeader/v2">
      <xsd:include schemaLocation="CnaHeader_v2.xsd"/>
    </xsd:schema>
  </wsdl11:types>
  <wsdl11:message name="retrieveDocument-inputHeader">
    <wsdl11:part name="To" element="abc:To"/>
    <wsdl11:part name="HeaderMetadata" element="abc:HeaderMetadata"/>
    <wsdl11:part name="ConsumerInfo" element="abc:ConsumerInfo"/>
  </wsdl11:message>
  <wsdl11:message name="retrieveDocument">
    <wsdl11:part name="body" element="contract:RetrieveDocument"/>
  </wsdl11:message>
  <wsdl11:message name="retrieveDocument-outputHeader">
    <wsdl11:part name="To" element="abc:To"/>
    <wsdl11:part name="HeaderMetadata" element="abc:HeaderMetadata"/>
    <wsdl11:part name="ConsumerInfo" element="abc:ConsumerInfo"/>
  </wsdl11:message>
  <wsdl11:message name="retrieveDocumentResponse">
    <wsdl11:part name="body" element="contract:RetrieveDocumentResponse"/>
  </wsdl11:message>
  <wsdl11:message name="abcInvalidMessageException">
    <wsdl11:part name="body" element="exceptions:CfInvalidMessageException"/>
  </wsdl11:message>
  <wsdl11:message name="abcServiceException">
    <wsdl11:part name="body" element="exceptions:CfServiceException"/>
  </wsdl11:message>
  <wsdl11:message name="abcProducerApplicationException">
    <wsdl11:part name="body" element="exceptions:CfProducerApplicationException"/>
  </wsdl11:message>
  <wsdl11:portType name="RetrieveDocument">
    <wsdl11:operation name="retrieveDocument">
      <wsdl11:input message="tns:retrieveDocument"/>
      <wsdl11:output message="tns:retrieveDocumentResponse"/>
      <wsdl11:fault message="tns:abcInvalidMessageException" name="abcInvalidMessageException"/>
      <wsdl11:fault message="tns:abcServiceException" name="abcServiceException"/>
      <wsdl11:fault message="tns:abcProducerApplicationException" name="abcProducerApplicationException"/>
    </wsdl11:operation>
  </wsdl11:portType>
  <!--END ABSTRACT DESCRIPTION-->
  <!--BEGIN BINDING DESCRIPTION-->
  <wsdl11:binding name="RetrieveDocumentSOAPBinding" type="tns:RetrieveDocument">
    <soap11:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl11:operation name="retrieveDocument">
      <soap11:operation soapAction="http://services.abc.com/Technology/RetrieveDocument/service/v1/soap11/RetrieveDocument./retrieveDocument"
           wsdl11:required="true" style="document"/>
      <wsdl11:input>
      <wsp:PolicyReference URI="abc-username-secure" wsdl11:required="true"/>
        <soap11:header use="literal" message="tns:retrieveDocument-inputHeader"
           part="To"/>
        <soap11:header use="literal" message="tns:retrieveDocument-inputHeader"
           part="HeaderMetadata"/>
        <soap11:header use="literal" message="tns:retrieveDocument-inputHeader"
           part="ConsumerInfo"/>
        <soap11:body use="literal"/>
      </wsdl11:input>
      <wsdl11:output>
        <soap11:header use="literal" message="tns:retrieveDocument-outputHeader"
           part="To"/>
        <soap11:header use="literal" message="tns:retrieveDocument-outputHeader"
           part="HeaderMetadata"/>
        <soap11:header use="literal" message="tns:retrieveDocument-outputHeader"
           part="ConsumerInfo"/>
        <soap11:body use="literal"/>
      </wsdl11:output>
      <wsdl11:fault name="abcInvalidMessageException">
        <soap11:fault name="abcInvalidMessageException" use="literal"/>
      </wsdl11:fault>
      <wsdl11:fault name="abcServiceException">
        <soap11:fault name="abcServiceException" use="literal"/>
      </wsdl11:fault>
      <wsdl11:fault name="abcProducerApplicationException">
        <soap11:fault name="abcProducerApplicationException" use="literal"/>
      </wsdl11:fault>
    </wsdl11:operation>
  </wsdl11:binding>
  <!--END BINDING DESCRIPTION-->

  <!--BEGIN SERVICE DESCRIPTION-->
  <wsdl11:service name="RetrieveDocument">
    <wsdl11:port name="RetrieveDocument" binding="tns:RetrieveDocumentSOAPBinding">
      <soap11:address location="dummy.url"/>
    </wsdl11:port>
  </wsdl11:service>

  <!--END SERVICE DESCRIPTION-->

  <wsp:Policy wsu:Id="abc-username-secure" xmlns:wsu=
     "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
      xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
      xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
    <wsp:ExactlyOne>
      <wsp:All>
        <!-- Empty <TransportBinding/> element required due to bug in CXF 2.2.6 -->
        <sp:TransportBinding/>
        <sp:SupportingTokens>
          <wsp:Policy>
            <sp:UsernameToken sp:IncludeToken=".../IncludeToken/AlwaysToRecipient"/>
          </wsp:Policy>
        </sp:SupportingTokens>
      </wsp:All>
    </wsp:ExactlyOne>
  </wsp:Policy>


</wsdl11:definitions>

我做了一些研究并尝试在wsimport中启用extension开关。在此之后,API成功生成。但在我认为wsimport之后,此身份验证部分被忽略了。

请说明在需要Web Service安全性时正确生成客户端API的正确步骤是什么?

0 个答案:

没有答案