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

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/binding/SOAPBindingImpl.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,171 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.binding;
    1.30 +
    1.31 +import com.sun.istack.internal.NotNull;
    1.32 +import com.sun.xml.internal.ws.api.BindingID;
    1.33 +import com.sun.xml.internal.ws.api.SOAPVersion;
    1.34 +import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
    1.35 +import com.sun.xml.internal.ws.client.HandlerConfiguration;
    1.36 +import com.sun.xml.internal.ws.encoding.soap.streaming.SOAP12NamespaceConstants;
    1.37 +import com.sun.xml.internal.ws.resources.ClientMessages;
    1.38 +
    1.39 +import javax.xml.namespace.QName;
    1.40 +import javax.xml.soap.MessageFactory;
    1.41 +import javax.xml.soap.SOAPFactory;
    1.42 +
    1.43 +import javax.xml.ws.WebServiceException;
    1.44 +import javax.xml.ws.WebServiceFeature;
    1.45 +import javax.xml.ws.handler.Handler;
    1.46 +import javax.xml.ws.soap.MTOMFeature;
    1.47 +import javax.xml.ws.soap.SOAPBinding;
    1.48 +import java.util.*;
    1.49 +
    1.50 +
    1.51 +/**
    1.52 + * @author WS Development Team
    1.53 + */
    1.54 +public final class SOAPBindingImpl extends BindingImpl implements SOAPBinding {
    1.55 +
    1.56 +    public static final String X_SOAP12HTTP_BINDING =
    1.57 +        "http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/";
    1.58 +
    1.59 +    private static final String ROLE_NONE = SOAP12NamespaceConstants.ROLE_NONE;
    1.60 +    //protected boolean enableMtom;
    1.61 +    protected final SOAPVersion soapVersion;
    1.62 +
    1.63 +    private Set<QName> portKnownHeaders = Collections.emptySet();
    1.64 +    private Set<QName> bindingUnderstoodHeaders = new HashSet<QName>();
    1.65 +
    1.66 +    /**
    1.67 +     * Use {@link BindingImpl#create(BindingID)} to create this.
    1.68 +     *
    1.69 +     * @param bindingId SOAP binding ID
    1.70 +     */
    1.71 +    SOAPBindingImpl(BindingID bindingId) {
    1.72 +        this(bindingId,EMPTY_FEATURES);
    1.73 +    }
    1.74 +
    1.75 +    /**
    1.76 +     * Use {@link BindingImpl#create(BindingID)} to create this.
    1.77 +     *
    1.78 +     * @param bindingId binding id
    1.79 +     * @param features
    1.80 +     *      These features have a precedence over
    1.81 +     *      {@link BindingID#createBuiltinFeatureList() the implicit features}
    1.82 +     *      associated with the {@link BindingID}.
    1.83 +     */
    1.84 +    SOAPBindingImpl(BindingID bindingId, WebServiceFeature... features) {
    1.85 +        super(bindingId, features);
    1.86 +        this.soapVersion = bindingId.getSOAPVersion();
    1.87 +        //populates with required roles and updates handlerConfig
    1.88 +        setRoles(new HashSet<String>());
    1.89 +        //Is this still required? comment out for now
    1.90 +        //setupSystemHandlerDelegate(serviceName);
    1.91 +
    1.92 +        this.features.addAll(bindingId.createBuiltinFeatureList());
    1.93 +    }
    1.94 +
    1.95 +    /**
    1.96 +     *  This method should be called if the binding has SOAPSEIModel
    1.97 +     *  The Headers understood by the Port are set, so that they can be used for MU
    1.98 +     *  processing.
    1.99 +     *
   1.100 +     * @param headers SOAP header names
   1.101 +     */
   1.102 +    public void setPortKnownHeaders(@NotNull Set<QName> headers) {
   1.103 +        this.portKnownHeaders = headers;
   1.104 +    }
   1.105 +
   1.106 +    /**
   1.107 +     * TODO A feature should be created to configure processing of MU headers.
   1.108 +     * @param header
   1.109 +     * @return
   1.110 +     */
   1.111 +    public boolean understandsHeader(QName header) {
   1.112 +        return serviceMode == javax.xml.ws.Service.Mode.MESSAGE
   1.113 +                || portKnownHeaders.contains(header)
   1.114 +                || bindingUnderstoodHeaders.contains(header);
   1.115 +
   1.116 +    }
   1.117 +
   1.118 +    /**
   1.119 +     * Sets the handlers on the binding and then sorts the handlers in to logical and protocol handlers.
   1.120 +     * Creates a new HandlerConfiguration object and sets it on the BindingImpl. Also parses Headers understood by
   1.121 +     * Protocol Handlers and sets the HandlerConfiguration.
   1.122 +     */
   1.123 +    public void setHandlerChain(List<Handler> chain) {
   1.124 +        handlerConfig = new HandlerConfiguration(handlerConfig.getRoles(), chain);
   1.125 +    }
   1.126 +
   1.127 +    protected void addRequiredRoles(Set<String> roles) {
   1.128 +        roles.addAll(soapVersion.requiredRoles);
   1.129 +    }
   1.130 +
   1.131 +    public Set<String> getRoles() {
   1.132 +        return handlerConfig.getRoles();
   1.133 +    }
   1.134 +
   1.135 +    /**
   1.136 +     * Adds the next and other roles in case this has
   1.137 +     * been called by a user without them.
   1.138 +     * Creates a new HandlerConfiguration object and sets it on the BindingImpl.
   1.139 +     */
   1.140 +    public void setRoles(Set<String> roles) {
   1.141 +        if (roles == null) {
   1.142 +            roles = new HashSet<String>();
   1.143 +        }
   1.144 +        if (roles.contains(ROLE_NONE)) {
   1.145 +            throw new WebServiceException(ClientMessages.INVALID_SOAP_ROLE_NONE());
   1.146 +        }
   1.147 +        addRequiredRoles(roles);
   1.148 +        handlerConfig = new HandlerConfiguration(roles, getHandlerConfig());
   1.149 +    }
   1.150 +
   1.151 +
   1.152 +    /**
   1.153 +     * Used typically by the runtime to enable/disable Mtom optimization
   1.154 +     */
   1.155 +    public boolean isMTOMEnabled() {
   1.156 +        return isFeatureEnabled(MTOMFeature.class);
   1.157 +    }
   1.158 +
   1.159 +    /**
   1.160 +     * Client application can override if the MTOM optimization should be enabled
   1.161 +     */
   1.162 +    public void setMTOMEnabled(boolean b) {
   1.163 +        features.setMTOMEnabled(b);
   1.164 +    }
   1.165 +
   1.166 +    public SOAPFactory getSOAPFactory() {
   1.167 +        return soapVersion.getSOAPFactory();
   1.168 +    }
   1.169 +
   1.170 +    public MessageFactory getMessageFactory() {
   1.171 +        return soapVersion.getMessageFactory();
   1.172 +    }
   1.173 +
   1.174 +}

mercurial