325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.binding;
325N/A
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.xml.internal.ws.api.BindingID;
325N/Aimport com.sun.xml.internal.ws.api.SOAPVersion;
325N/Aimport com.sun.xml.internal.ws.api.addressing.AddressingVersion;
325N/Aimport com.sun.xml.internal.ws.api.handler.MessageHandler;
325N/Aimport com.sun.xml.internal.ws.client.HandlerConfiguration;
325N/Aimport com.sun.xml.internal.ws.encoding.soap.streaming.SOAP12NamespaceConstants;
325N/Aimport com.sun.xml.internal.ws.handler.HandlerException;
325N/Aimport com.sun.xml.internal.ws.resources.ClientMessages;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/Aimport javax.xml.soap.MessageFactory;
325N/Aimport javax.xml.soap.SOAPFactory;
325N/Aimport javax.xml.ws.ServiceMode;
325N/Aimport javax.xml.ws.WebServiceException;
325N/Aimport javax.xml.ws.WebServiceFeature;
325N/Aimport javax.xml.ws.handler.Handler;
325N/Aimport javax.xml.ws.handler.LogicalHandler;
325N/Aimport javax.xml.ws.handler.soap.SOAPHandler;
325N/Aimport javax.xml.ws.soap.MTOMFeature;
325N/Aimport javax.xml.ws.soap.SOAPBinding;
325N/Aimport java.util.*;
325N/A
325N/A
325N/A/**
325N/A * @author WS Development Team
325N/A */
325N/Apublic final class SOAPBindingImpl extends BindingImpl implements SOAPBinding {
325N/A
325N/A public static final String X_SOAP12HTTP_BINDING =
325N/A "http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/";
325N/A
325N/A private static final String ROLE_NONE = SOAP12NamespaceConstants.ROLE_NONE;
325N/A //protected boolean enableMtom;
325N/A protected final SOAPVersion soapVersion;
325N/A
325N/A private Set<QName> portKnownHeaders = Collections.emptySet();
325N/A private Set<QName> bindingUnderstoodHeaders = new HashSet<QName>();
325N/A
325N/A /**
325N/A * Use {@link BindingImpl#create(BindingID)} to create this.
325N/A */
325N/A SOAPBindingImpl(BindingID bindingId) {
325N/A this(bindingId,EMPTY_FEATURES);
325N/A }
325N/A
325N/A /**
325N/A * Use {@link BindingImpl#create(BindingID)} to create this.
325N/A *
325N/A * @param features
325N/A * These features have a precedence over
325N/A * {@link BindingID#createBuiltinFeatureList() the implicit features}
325N/A * associated with the {@link BindingID}.
325N/A */
325N/A SOAPBindingImpl(BindingID bindingId, WebServiceFeature... features) {
325N/A super(bindingId);
325N/A this.soapVersion = bindingId.getSOAPVersion();
325N/A //populates with required roles and updates handlerConfig
325N/A setRoles(new HashSet<String>());
325N/A //Is this still required? comment out for now
325N/A //setupSystemHandlerDelegate(serviceName);
325N/A
325N/A setFeatures(features);
325N/A this.features.addAll(bindingId.createBuiltinFeatureList());
325N/A populateBindingUnderstoodHeaders();
325N/A }
325N/A
325N/A /**
325N/A * This method should be called if the binding has SOAPSEIModel
325N/A * The Headers understood by the Port are set, so that they can be used for MU
325N/A * processing.
325N/A *
325N/A * @param headers
325N/A */
325N/A public void setPortKnownHeaders(@NotNull Set<QName> headers) {
325N/A this.portKnownHeaders = headers;
325N/A }
325N/A
325N/A public boolean understandsHeader(QName header) {
325N/A if(serviceMode == javax.xml.ws.Service.Mode.MESSAGE)
325N/A return true;
325N/A if(portKnownHeaders.contains(header))
325N/A return true;
325N/A if(bindingUnderstoodHeaders.contains(header))
325N/A return true;
325N/A
325N/A return false;
325N/A }
325N/A
325N/A /**
325N/A * Understand WS-Addressing headers if WS-Addressing is enabled
325N/A *
325N/A */
325N/A private void populateBindingUnderstoodHeaders() {
325N/A AddressingVersion addressingVersion = getAddressingVersion();
325N/A if (addressingVersion != null) {
325N/A bindingUnderstoodHeaders.add(addressingVersion.actionTag);
325N/A bindingUnderstoodHeaders.add(addressingVersion.faultToTag);
325N/A bindingUnderstoodHeaders.add(addressingVersion.fromTag);
325N/A bindingUnderstoodHeaders.add(addressingVersion.messageIDTag);
325N/A bindingUnderstoodHeaders.add(addressingVersion.relatesToTag);
325N/A bindingUnderstoodHeaders.add(addressingVersion.replyToTag);
325N/A bindingUnderstoodHeaders.add(addressingVersion.toTag);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Sets the handlers on the binding and then sorts the handlers in to logical and protocol handlers.
325N/A * Creates a new HandlerConfiguration object and sets it on the BindingImpl. Also parses Headers understood by
325N/A * Protocol Handlers and sets the HandlerConfiguration.
325N/A */
325N/A public void setHandlerChain(List<Handler> chain) {
325N/A handlerConfig = new HandlerConfiguration(handlerConfig.getRoles(), chain);
325N/A }
325N/A
325N/A protected void addRequiredRoles(Set<String> roles) {
325N/A roles.addAll(soapVersion.requiredRoles);
325N/A }
325N/A
325N/A public Set<String> getRoles() {
325N/A return handlerConfig.getRoles();
325N/A }
325N/A
325N/A /**
325N/A * Adds the next and other roles in case this has
325N/A * been called by a user without them.
325N/A * Creates a new HandlerConfiguration object and sets it on the BindingImpl.
325N/A */
325N/A public void setRoles(Set<String> roles) {
325N/A if (roles == null) {
325N/A roles = new HashSet<String>();
325N/A }
325N/A if (roles.contains(ROLE_NONE)) {
325N/A throw new WebServiceException(ClientMessages.INVALID_SOAP_ROLE_NONE());
325N/A }
325N/A addRequiredRoles(roles);
325N/A handlerConfig = new HandlerConfiguration(roles, getHandlerConfig());
325N/A }
325N/A
325N/A
325N/A /**
325N/A * Used typically by the runtime to enable/disable Mtom optimization
325N/A */
325N/A public boolean isMTOMEnabled() {
325N/A return isFeatureEnabled(MTOMFeature.class);
325N/A }
325N/A
325N/A /**
325N/A * Client application can override if the MTOM optimization should be enabled
325N/A */
325N/A public void setMTOMEnabled(boolean b) {
325N/A setFeatures(new MTOMFeature(b));
325N/A }
325N/A
325N/A public SOAPFactory getSOAPFactory() {
325N/A return soapVersion.saajSoapFactory;
325N/A }
325N/A
325N/A public MessageFactory getMessageFactory() {
325N/A return soapVersion.saajMessageFactory;
325N/A }
325N/A
325N/A private static final WebServiceFeature[] EMPTY_FEATURES = new WebServiceFeature[0];
325N/A}