強制遵守 JAX-WS Web 服務中的 WSDL 連結

您可以在 WSDL 文件中新增連結延伸,然後利用 Liberty 的 JAX-WS 支援,將這些延伸套用到您的應用程式中。

關於這項作業

Liberty 支援使用 JAX-WS 2.2 規格中所需要的 wsdl:binding 延伸。這個主題說明如何定義 WSDL 延伸,以及如何將它們與 Liberty 中自訂的延伸元素連結起來。

程序

  1. 定義一個延伸元素,將它對映至 WSDL 延伸中所定義的使用者。 下列範例顯示如何與 WSDL 延伸 {http://server.respectbinding.jaxws22/}goodBinding 連結起來。
    @XmlRootElement(name = "goodBinding", namespace = "http://server.respectbinding.jaxws22/")
    public class GoodBindingElement implements ExtensibilityElement, Serializable {
        private String uri;
        private QName elementType = null;
        private Boolean required = null;
        
        @XmlAttribute(name = "uri")
        public String getUri() {
            return this.uri;
        }
    
        @Override
        public QName getElementType() {
            return this.elementType;
        }
    
        @XmlAttribute(name = "required", namespace="http://schemas.xmlsoap.org/wsdl/")
        public Boolean getRequired() {
            return this.required;
        }
            
        public void setUri(String uri){
            this.uri = uri;
        }
    
        @Override
        public void setElementType(QName elementType) {
            this.elementType = elementType;
        }
    
        @Override
        public void setRequired(Boolean required) {
            this.required = required;
        }
    }
  2. 新增 extensions.xml 檔到 Web 或 EJB 應用程式的 /META-INF 目錄中。 這個檔案定義 WSDL 文件中各項延伸的可用位置。 在下列範例中,在 extensions.xml 檔中新增將 javax.wsdl.Binding 內容設為 goodBindingElement 類別之親項類型的項目。 這個項目也意味著 {http://server.respectbinding.jaxws22/}goodBinding 延伸只能新增在 WSDL 文件的 binding 元素之下。
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
    
    <properties>
    	<!-- XML Binding -->
    	<entry key="org.apache.cxf.bindings.xml-1">javax.wsdl.Binding=jaxws22.respectbinding.server.common.GoodBindingElement</entry>
    </properties>
  3. 依照下列方式,在 binding 元素之下新增 {http://server.respectbinding.jaxws22/}goodBinding 延伸:
    ...
      <binding name="EchoPortBinding" type="tns:Echo">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <tns:goodBinding wsdl:required="true" uri="http://good/good" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
        <operation name="echo">
          <soap:operation soapAction=""/>
          <input>
            <soap:body use="literal"/>
          </input>
          <output>
            <soap:body use="literal"/>
          </output>
          <fault name="Exception">
            <soap:fault name="Exception" use="literal"/>
          </fault>
        </operation>
      </binding>
      ...

指示主題類型的圖示 作業主題

檔名:twlp_dep_jaxws_extension.html