001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.binding;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.BindingID;
041: import com.sun.xml.ws.api.SOAPVersion;
042: import com.sun.xml.ws.api.handler.MessageHandler;
043: import com.sun.xml.ws.client.HandlerConfiguration;
044: import com.sun.xml.ws.encoding.soap.streaming.SOAP12NamespaceConstants;
045: import com.sun.xml.ws.handler.HandlerException;
046: import com.sun.xml.ws.resources.ClientMessages;
047:
048: import javax.xml.namespace.QName;
049: import javax.xml.soap.MessageFactory;
050: import javax.xml.soap.SOAPFactory;
051: import javax.xml.ws.WebServiceException;
052: import javax.xml.ws.WebServiceFeature;
053: import javax.xml.ws.handler.Handler;
054: import javax.xml.ws.handler.LogicalHandler;
055: import javax.xml.ws.handler.soap.SOAPHandler;
056: import javax.xml.ws.soap.MTOMFeature;
057: import javax.xml.ws.soap.SOAPBinding;
058: import java.util.*;
059:
060: /**
061: * @author WS Development Team
062: */
063: public final class SOAPBindingImpl extends BindingImpl implements
064: SOAPBinding {
065:
066: public static final String X_SOAP12HTTP_BINDING = "http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/";
067:
068: private static final String ROLE_NONE = SOAP12NamespaceConstants.ROLE_NONE;
069: private Set<String> roles;
070: //protected boolean enableMtom;
071: protected final SOAPVersion soapVersion;
072:
073: private Set<QName> portKnownHeaders = Collections.emptySet();
074:
075: /**
076: * Use {@link BindingImpl#create(BindingID)} to create this.
077: */
078: SOAPBindingImpl(BindingID bindingId) {
079: this (bindingId, EMPTY_FEATURES);
080: }
081:
082: /**
083: * Use {@link BindingImpl#create(BindingID)} to create this.
084: *
085: * @param features
086: * These features have a precedence over
087: * {@link BindingID#createBuiltinFeatureList() the implicit features}
088: * associated with the {@link BindingID}.
089: */
090: SOAPBindingImpl(BindingID bindingId, WebServiceFeature... features) {
091: super (bindingId);
092: this .soapVersion = bindingId.getSOAPVersion();
093: roles = new HashSet<String>();
094: addRequiredRoles();
095: //Is this still required? comment out for now
096: //setupSystemHandlerDelegate(serviceName);
097:
098: setFeatures(features);
099: this .features.addAll(bindingId.createBuiltinFeatureList());
100: }
101:
102: /**
103: * This method should be called if the binding has SOAPSEIModel
104: * The Headers understood by the Port are set, so that they can be used for MU
105: * processing.
106: *
107: * @param headers
108: */
109: public void setPortKnownHeaders(@NotNull
110: Set<QName> headers) {
111: this .portKnownHeaders = headers;
112: // apply this change to HandlerConfiguration
113: setHandlerConfig(createHandlerConfig(getHandlerChain()));
114: }
115:
116: /**
117: * This method separates the logical and protocol handlers.
118: * Also parses Headers understood by SOAPHandlers and
119: * sets the HandlerConfiguration.
120: */
121: protected HandlerConfiguration createHandlerConfig(
122: List<Handler> handlerChain) {
123: List<LogicalHandler> logicalHandlers = new ArrayList<LogicalHandler>();
124: List<SOAPHandler> soapHandlers = new ArrayList<SOAPHandler>();
125: List<MessageHandler> messageHandlers = new ArrayList<MessageHandler>();
126: Set<QName> handlerKnownHeaders = new HashSet<QName>();
127:
128: for (Handler handler : handlerChain) {
129: if (handler instanceof LogicalHandler) {
130: logicalHandlers.add((LogicalHandler) handler);
131: } else if (handler instanceof SOAPHandler) {
132: soapHandlers.add((SOAPHandler) handler);
133: Set<QName> headers = ((SOAPHandler<?>) handler)
134: .getHeaders();
135: if (headers != null) {
136: handlerKnownHeaders.addAll(headers);
137: }
138: } else if (handler instanceof MessageHandler) {
139: messageHandlers.add((MessageHandler) handler);
140: Set<QName> headers = ((MessageHandler<?>) handler)
141: .getHeaders();
142: if (headers != null) {
143: handlerKnownHeaders.addAll(headers);
144: }
145: } else {
146: throw new HandlerException("handler.not.valid.type",
147: handler.getClass());
148: }
149: }
150: return new HandlerConfiguration(roles, portKnownHeaders,
151: handlerChain, logicalHandlers, soapHandlers,
152: messageHandlers, handlerKnownHeaders);
153: }
154:
155: protected void addRequiredRoles() {
156: roles.addAll(soapVersion.requiredRoles);
157: }
158:
159: public Set<String> getRoles() {
160: return roles;
161: }
162:
163: /**
164: * Adds the next and other roles in case this has
165: * been called by a user without them.
166: * Creates a new HandlerConfiguration object and sets it on the BindingImpl.
167: */
168: public void setRoles(Set<String> roles) {
169: if (roles == null) {
170: roles = new HashSet<String>();
171: }
172: if (roles.contains(ROLE_NONE)) {
173: throw new WebServiceException(ClientMessages
174: .INVALID_SOAP_ROLE_NONE());
175: }
176: this .roles = roles;
177: addRequiredRoles();
178: HandlerConfiguration oldConfig = getHandlerConfig();
179: setHandlerConfig(new HandlerConfiguration(this .roles,
180: portKnownHeaders, oldConfig.getHandlerChain(),
181: oldConfig.getLogicalHandlers(), oldConfig
182: .getSoapHandlers(), oldConfig
183: .getMessageHandlers(), oldConfig
184: .getHandlerKnownHeaders()));
185: }
186:
187: /**
188: * Used typically by the runtime to enable/disable Mtom optimization
189: */
190: public boolean isMTOMEnabled() {
191: return isFeatureEnabled(MTOMFeature.class);
192: }
193:
194: /**
195: * Client application can override if the MTOM optimization should be enabled
196: */
197: public void setMTOMEnabled(boolean b) {
198: setFeatures(new MTOMFeature(b));
199: }
200:
201: public SOAPFactory getSOAPFactory() {
202: return soapVersion.saajSoapFactory;
203: }
204:
205: public MessageFactory getMessageFactory() {
206: return soapVersion.saajMessageFactory;
207: }
208:
209: private static final WebServiceFeature[] EMPTY_FEATURES = new WebServiceFeature[0];
210: }
|