src/share/jaxws_classes/com/sun/xml/internal/ws/binding/SOAPBindingImpl.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.binding;
    28 import com.sun.istack.internal.NotNull;
    29 import com.sun.xml.internal.ws.api.BindingID;
    30 import com.sun.xml.internal.ws.api.SOAPVersion;
    31 import com.sun.xml.internal.ws.client.HandlerConfiguration;
    32 import com.sun.xml.internal.ws.encoding.soap.streaming.SOAP12NamespaceConstants;
    33 import com.sun.xml.internal.ws.resources.ClientMessages;
    35 import javax.xml.namespace.QName;
    36 import javax.xml.soap.MessageFactory;
    37 import javax.xml.soap.SOAPFactory;
    39 import javax.xml.ws.WebServiceException;
    40 import javax.xml.ws.WebServiceFeature;
    41 import javax.xml.ws.handler.Handler;
    42 import javax.xml.ws.soap.MTOMFeature;
    43 import javax.xml.ws.soap.SOAPBinding;
    44 import java.util.*;
    46 /**
    47  * @author WS Development Team
    48  */
    49 public final class SOAPBindingImpl extends BindingImpl implements SOAPBinding {
    51     public static final String X_SOAP12HTTP_BINDING =
    52         "http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/";
    54     private static final String ROLE_NONE = SOAP12NamespaceConstants.ROLE_NONE;
    55     //protected boolean enableMtom;
    56     protected final SOAPVersion soapVersion;
    58     private Set<QName> portKnownHeaders = Collections.emptySet();
    59     private Set<QName> bindingUnderstoodHeaders = new HashSet<QName>();
    61     /**
    62      * Use {@link BindingImpl#create(BindingID)} to create this.
    63      *
    64      * @param bindingId SOAP binding ID
    65      */
    66     SOAPBindingImpl(BindingID bindingId) {
    67         this(bindingId,EMPTY_FEATURES);
    68     }
    70     /**
    71      * Use {@link BindingImpl#create(BindingID)} to create this.
    72      *
    73      * @param bindingId binding id
    74      * @param features
    75      *      These features have a precedence over
    76      *      {@link BindingID#createBuiltinFeatureList() the implicit features}
    77      *      associated with the {@link BindingID}.
    78      */
    79     SOAPBindingImpl(BindingID bindingId, WebServiceFeature... features) {
    80         super(bindingId, features);
    81         this.soapVersion = bindingId.getSOAPVersion();
    82         //populates with required roles and updates handlerConfig
    83         setRoles(new HashSet<String>());
    84         //Is this still required? comment out for now
    85         //setupSystemHandlerDelegate(serviceName);
    87         this.features.addAll(bindingId.createBuiltinFeatureList());
    88     }
    90     /**
    91      *  This method should be called if the binding has SOAPSEIModel
    92      *  The Headers understood by the Port are set, so that they can be used for MU
    93      *  processing.
    94      *
    95      * @param headers SOAP header names
    96      */
    97     public void setPortKnownHeaders(@NotNull Set<QName> headers) {
    98         this.portKnownHeaders = headers;
    99     }
   101     /**
   102      * TODO A feature should be created to configure processing of MU headers.
   103      * @param header
   104      * @return
   105      */
   106     public boolean understandsHeader(QName header) {
   107         return serviceMode == javax.xml.ws.Service.Mode.MESSAGE
   108                 || portKnownHeaders.contains(header)
   109                 || bindingUnderstoodHeaders.contains(header);
   111     }
   113     /**
   114      * Sets the handlers on the binding and then sorts the handlers in to logical and protocol handlers.
   115      * Creates a new HandlerConfiguration object and sets it on the BindingImpl. Also parses Headers understood by
   116      * Protocol Handlers and sets the HandlerConfiguration.
   117      */
   118     public void setHandlerChain(List<Handler> chain) {
   119         setHandlerConfig(new HandlerConfiguration(getHandlerConfig().getRoles(), chain));
   120     }
   122     protected void addRequiredRoles(Set<String> roles) {
   123         roles.addAll(soapVersion.requiredRoles);
   124     }
   126     public Set<String> getRoles() {
   127         return getHandlerConfig().getRoles();
   128     }
   130     /**
   131      * Adds the next and other roles in case this has
   132      * been called by a user without them.
   133      * Creates a new HandlerConfiguration object and sets it on the BindingImpl.
   134      */
   135     public void setRoles(Set<String> roles) {
   136         if (roles == null) {
   137             roles = new HashSet<String>();
   138         }
   139         if (roles.contains(ROLE_NONE)) {
   140             throw new WebServiceException(ClientMessages.INVALID_SOAP_ROLE_NONE());
   141         }
   142         addRequiredRoles(roles);
   143         setHandlerConfig(new HandlerConfiguration(roles, getHandlerConfig()));
   144     }
   147     /**
   148      * Used typically by the runtime to enable/disable Mtom optimization
   149      */
   150     public boolean isMTOMEnabled() {
   151         return isFeatureEnabled(MTOMFeature.class);
   152     }
   154     /**
   155      * Client application can override if the MTOM optimization should be enabled
   156      */
   157     public void setMTOMEnabled(boolean b) {
   158         features.setMTOMEnabled(b);
   159     }
   161     public SOAPFactory getSOAPFactory() {
   162         return soapVersion.getSOAPFactory();
   163     }
   165     public MessageFactory getMessageFactory() {
   166         return soapVersion.getMessageFactory();
   167     }
   169 }

mercurial