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.transport.tcp.util;
038:
039: import com.sun.xml.ws.transport.tcp.resources.MessagesMessages;
040: import com.sun.xml.ws.transport.tcp.util.TCPSettings.EncodingMode;
041: import com.sun.xml.ws.api.SOAPVersion;
042: import com.sun.xml.ws.api.WSBinding;
043: import java.util.ArrayList;
044: import java.util.Arrays;
045: import java.util.List;
046: import javax.xml.ws.soap.MTOMFeature;
047:
048: /**
049: * @author Alexey Stashok
050: */
051: public final class BindingUtils {
052: private static List<String> SOAP11_PARAMS;
053: private static List<String> SOAP12_PARAMS;
054: private static List<String> MTOM11_PARAMS;
055: private static List<String> MTOM12_PARAMS;
056:
057: private static NegotiatedBindingContent SOAP11_BINDING_CONTENT;
058:
059: private static NegotiatedBindingContent SOAP12_BINDING_CONTENT;
060:
061: private static NegotiatedBindingContent MTOM11_BINDING_CONTENT;
062:
063: private static NegotiatedBindingContent MTOM12_BINDING_CONTENT;
064:
065: static {
066: initiate();
067: }
068:
069: private static void initiate() {
070: // Fill out negotiation mime parameters
071:
072: // Add SOAP parameters
073: SOAP11_PARAMS = Arrays.asList(new String[] {
074: TCPConstants.CHARSET_PROPERTY,
075: TCPConstants.TRANSPORT_SOAP_ACTION_PROPERTY });
076: SOAP12_PARAMS = Arrays.asList(new String[] {
077: TCPConstants.CHARSET_PROPERTY,
078: TCPConstants.SOAP_ACTION_PROPERTY });
079:
080: // Add MTOM parameters
081: MTOM11_PARAMS = new ArrayList<String>(SOAP11_PARAMS);
082: MTOM11_PARAMS.add("boundary");
083: MTOM11_PARAMS.add("start-info");
084: MTOM11_PARAMS.add("type");
085:
086: MTOM12_PARAMS = new ArrayList<String>(SOAP12_PARAMS);
087: MTOM12_PARAMS.add("boundary");
088: MTOM12_PARAMS.add("start-info");
089: MTOM12_PARAMS.add("type");
090:
091: SOAP11_BINDING_CONTENT = new NegotiatedBindingContent(
092: new ArrayList<String>(1), SOAP11_PARAMS);
093:
094: SOAP12_BINDING_CONTENT = new NegotiatedBindingContent(
095: new ArrayList<String>(1), SOAP12_PARAMS);
096:
097: MTOM11_BINDING_CONTENT = new NegotiatedBindingContent(
098: new ArrayList<String>(2), MTOM11_PARAMS);
099:
100: MTOM12_BINDING_CONTENT = new NegotiatedBindingContent(
101: new ArrayList<String>(2), MTOM12_PARAMS);
102:
103: // Fill out negotiation mime types
104:
105: // Add FI stateful if enabled
106: if (TCPSettings.getInstance().getEncodingMode() == EncodingMode.FI_STATEFUL) {
107: SOAP11_BINDING_CONTENT.negotiatedMimeTypes
108: .add(MimeTypeConstants.FAST_INFOSET_STATEFUL_SOAP11);
109: SOAP12_BINDING_CONTENT.negotiatedMimeTypes
110: .add(MimeTypeConstants.FAST_INFOSET_STATEFUL_SOAP12);
111: }
112:
113: // Add FI stateless if enabled
114: if (TCPSettings.getInstance().getEncodingMode() == EncodingMode.FI_STATELESS) {
115: SOAP11_BINDING_CONTENT.negotiatedMimeTypes
116: .add(MimeTypeConstants.FAST_INFOSET_SOAP11);
117: SOAP12_BINDING_CONTENT.negotiatedMimeTypes
118: .add(MimeTypeConstants.FAST_INFOSET_SOAP12);
119: }
120:
121: // Add SOAP mime types
122: SOAP11_BINDING_CONTENT.negotiatedMimeTypes
123: .add(MimeTypeConstants.SOAP11);
124: SOAP12_BINDING_CONTENT.negotiatedMimeTypes
125: .add(MimeTypeConstants.SOAP12);
126:
127: // Add MTOM mime types
128: MTOM11_BINDING_CONTENT.negotiatedMimeTypes
129: .addAll(SOAP11_BINDING_CONTENT.negotiatedMimeTypes);
130: MTOM11_BINDING_CONTENT.negotiatedMimeTypes
131: .add(MimeTypeConstants.MTOM);
132: MTOM12_BINDING_CONTENT.negotiatedMimeTypes
133: .addAll(SOAP12_BINDING_CONTENT.negotiatedMimeTypes);
134: MTOM12_BINDING_CONTENT.negotiatedMimeTypes
135: .add(MimeTypeConstants.MTOM);
136: }
137:
138: public static NegotiatedBindingContent getNegotiatedContentTypesAndParams(
139: final WSBinding binding) {
140: if (binding.getSOAPVersion().equals(SOAPVersion.SOAP_11)) {
141: if (isMTOMEnabled(binding)) {
142: return MTOM11_BINDING_CONTENT;
143: } else {
144: return SOAP11_BINDING_CONTENT;
145: }
146: } else if (binding.getSOAPVersion().equals(SOAPVersion.SOAP_12)) {
147: if (isMTOMEnabled(binding)) {
148: return MTOM12_BINDING_CONTENT;
149: } else {
150: return SOAP12_BINDING_CONTENT;
151: }
152: }
153:
154: throw new AssertionError(MessagesMessages
155: .WSTCP_0009_UNKNOWN_BINDING(binding));
156: }
157:
158: private static boolean isMTOMEnabled(final WSBinding binding) {
159: return binding.isFeatureEnabled(MTOMFeature.class);
160: }
161:
162: public static final class NegotiatedBindingContent {
163: public final List<String> negotiatedMimeTypes;
164: public final List<String> negotiatedParams;
165:
166: public NegotiatedBindingContent(
167: List<String> negotiatedMimeTypes,
168: List<String> negotiatedParams) {
169: this.negotiatedMimeTypes = negotiatedMimeTypes;
170: this.negotiatedParams = negotiatedParams;
171: }
172: }
173: }
|