src/share/jaxws_classes/com/sun/xml/internal/ws/api/SOAPVersion.java

Wed, 12 Jun 2013 14:47:09 +0100

author
mkos
date
Wed, 12 Jun 2013 14:47:09 +0100
changeset 384
8f2986ff0235
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
8003542: Improve processing of MTOM attachments
8005432: Update access to JAX-WS
Reviewed-by: mullan

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.api;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.bind.util.Which;
ohair@286 29 import com.sun.xml.internal.ws.api.message.saaj.SAAJFactory;
ohair@286 30 import com.sun.xml.internal.ws.encoding.soap.SOAP12Constants;
ohair@286 31
ohair@286 32 import javax.xml.namespace.QName;
ohair@286 33 import javax.xml.soap.MessageFactory;
ohair@286 34 import javax.xml.soap.SOAPConstants;
ohair@286 35 import javax.xml.soap.SOAPException;
ohair@286 36 import javax.xml.soap.SOAPFactory;
ohair@286 37 import javax.xml.ws.soap.SOAPBinding;
ohair@286 38
alanb@368 39 import com.oracle.webservices.internal.api.EnvelopeStyle;
alanb@368 40 import com.oracle.webservices.internal.api.EnvelopeStyleFeature;
ohair@286 41
ohair@286 42 import java.util.Arrays;
ohair@286 43 import java.util.Collections;
ohair@286 44 import java.util.HashSet;
ohair@286 45 import java.util.Set;
ohair@286 46
ohair@286 47 /**
ohair@286 48 * Version of SOAP (1.1 and 1.2).
ohair@286 49 *
ohair@286 50 * <p>
ohair@286 51 * This class defines various constants for SOAP 1.1 and SOAP 1.2,
ohair@286 52 * and also defines convenience methods to simplify the processing
ohair@286 53 * of multiple SOAP versions.
ohair@286 54 *
ohair@286 55 * <p>
ohair@286 56 * This constant alows you to do:
ohair@286 57 *
ohair@286 58 * <pre>
ohair@286 59 * SOAPVersion version = ...;
ohair@286 60 * version.someOp(...);
ohair@286 61 * </pre>
ohair@286 62 *
ohair@286 63 * As opposed to:
ohair@286 64 *
ohair@286 65 * <pre>
ohair@286 66 * if(binding is SOAP11) {
ohair@286 67 * doSomeOp11(...);
ohair@286 68 * } else {
ohair@286 69 * doSomeOp12(...);
ohair@286 70 * }
ohair@286 71 * </pre>
ohair@286 72 *
ohair@286 73 * @author Kohsuke Kawaguchi
ohair@286 74 */
ohair@286 75 public enum SOAPVersion {
ohair@286 76 SOAP_11(SOAPBinding.SOAP11HTTP_BINDING,
ohair@286 77 com.sun.xml.internal.ws.encoding.soap.SOAPConstants.URI_ENVELOPE,
ohair@286 78 "text/xml",
ohair@286 79 SOAPConstants.URI_SOAP_ACTOR_NEXT, "actor",
ohair@286 80 javax.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL,
ohair@286 81 new QName(com.sun.xml.internal.ws.encoding.soap.SOAPConstants.URI_ENVELOPE, "MustUnderstand"),
ohair@286 82 "Client",
ohair@286 83 "Server",
ohair@286 84 Collections.singleton(SOAPConstants.URI_SOAP_ACTOR_NEXT)),
ohair@286 85
ohair@286 86 SOAP_12(SOAPBinding.SOAP12HTTP_BINDING,
ohair@286 87 SOAP12Constants.URI_ENVELOPE,
ohair@286 88 "application/soap+xml",
ohair@286 89 SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER, "role",
ohair@286 90 javax.xml.soap.SOAPConstants.SOAP_1_2_PROTOCOL,
ohair@286 91 new QName(com.sun.xml.internal.ws.encoding.soap.SOAP12Constants.URI_ENVELOPE, "MustUnderstand"),
ohair@286 92 "Sender",
ohair@286 93 "Receiver",
ohair@286 94 new HashSet<String>(Arrays.asList(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT,SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER)));
ohair@286 95
ohair@286 96 /**
ohair@286 97 * Binding ID for SOAP/HTTP binding of this SOAP version.
ohair@286 98 *
ohair@286 99 * <p>
ohair@286 100 * Either {@link SOAPBinding#SOAP11HTTP_BINDING} or
ohair@286 101 * {@link SOAPBinding#SOAP12HTTP_BINDING}
ohair@286 102 */
ohair@286 103 public final String httpBindingId;
ohair@286 104
ohair@286 105 /**
ohair@286 106 * SOAP envelope namespace URI.
ohair@286 107 */
ohair@286 108 public final String nsUri;
ohair@286 109
ohair@286 110 /**
ohair@286 111 * Content-type. Either "text/xml" or "application/soap+xml".
ohair@286 112 */
ohair@286 113 public final String contentType;
ohair@286 114
ohair@286 115 /**
ohair@286 116 * SOAP MustUnderstand FaultCode for this SOAP version
ohair@286 117 */
ohair@286 118 public final QName faultCodeMustUnderstand;
ohair@286 119
ohair@286 120 /**
ohair@286 121 * SAAJ {@link MessageFactory} for this SOAP version.
ohair@286 122 * @deprecated
ohair@286 123 */
ohair@286 124 public final MessageFactory saajMessageFactory;
ohair@286 125
ohair@286 126 /**
ohair@286 127 * SAAJ {@link SOAPFactory} for this SOAP version.
ohair@286 128 * @deprecated
ohair@286 129 */
ohair@286 130 public final SOAPFactory saajSoapFactory;
ohair@286 131
ohair@286 132 private final String saajFactoryString;
ohair@286 133
ohair@286 134 /**
ohair@286 135 * If the actor/role attribute is absent, this SOAP version assumes this value.
ohair@286 136 */
ohair@286 137 public final String implicitRole;
ohair@286 138
ohair@286 139 /**
ohair@286 140 * Singleton set that contains {@link #implicitRole}.
ohair@286 141 */
ohair@286 142 public final Set<String> implicitRoleSet;
ohair@286 143
ohair@286 144 /**
ohair@286 145 * This represents the roles required to be assumed by SOAP binding implementation.
ohair@286 146 */
ohair@286 147 public final Set<String> requiredRoles;
ohair@286 148
ohair@286 149 /**
ohair@286 150 * "role" (SOAP 1.2) or "actor" (SOAP 1.1)
ohair@286 151 */
ohair@286 152 public final String roleAttributeName;
ohair@286 153
ohair@286 154 /**
ohair@286 155 * "{nsUri}Client" or "{nsUri}Sender"
ohair@286 156 */
ohair@286 157 public final QName faultCodeClient;
ohair@286 158
ohair@286 159 /**
ohair@286 160 * "{nsUri}Server" or "{nsUri}Receiver"
ohair@286 161 */
ohair@286 162 public final QName faultCodeServer;
ohair@286 163
ohair@286 164 private SOAPVersion(String httpBindingId, String nsUri, String contentType, String implicitRole, String roleAttributeName,
ohair@286 165 String saajFactoryString, QName faultCodeMustUnderstand, String faultCodeClientLocalName,
ohair@286 166 String faultCodeServerLocalName,Set<String> requiredRoles) {
ohair@286 167 this.httpBindingId = httpBindingId;
ohair@286 168 this.nsUri = nsUri;
ohair@286 169 this.contentType = contentType;
ohair@286 170 this.implicitRole = implicitRole;
ohair@286 171 this.implicitRoleSet = Collections.singleton(implicitRole);
ohair@286 172 this.roleAttributeName = roleAttributeName;
ohair@286 173 this.saajFactoryString = saajFactoryString;
ohair@286 174 try {
ohair@286 175 saajMessageFactory = MessageFactory.newInstance(saajFactoryString);
ohair@286 176 saajSoapFactory = SOAPFactory.newInstance(saajFactoryString);
ohair@286 177 } catch (SOAPException e) {
ohair@286 178 throw new Error(e);
ohair@286 179 } catch (NoSuchMethodError e) {
ohair@286 180 // SAAJ 1.3 is not in the classpath
ohair@286 181 LinkageError x = new LinkageError("You are loading old SAAJ from "+ Which.which(MessageFactory.class));
ohair@286 182 x.initCause(e);
ohair@286 183 throw x;
ohair@286 184 }
ohair@286 185 this.faultCodeMustUnderstand = faultCodeMustUnderstand;
ohair@286 186 this.requiredRoles = requiredRoles;
ohair@286 187 this.faultCodeClient = new QName(nsUri,faultCodeClientLocalName);
ohair@286 188 this.faultCodeServer = new QName(nsUri,faultCodeServerLocalName);
ohair@286 189 }
ohair@286 190
ohair@286 191 public SOAPFactory getSOAPFactory() {
ohair@286 192 try {
ohair@286 193 return SAAJFactory.getSOAPFactory(saajFactoryString);
ohair@286 194 } catch (SOAPException e) {
ohair@286 195 throw new Error(e);
ohair@286 196 } catch (NoSuchMethodError e) {
ohair@286 197 // SAAJ 1.3 is not in the classpath
ohair@286 198 LinkageError x = new LinkageError("You are loading old SAAJ from "+ Which.which(MessageFactory.class));
ohair@286 199 x.initCause(e);
ohair@286 200 throw x;
ohair@286 201 }
ohair@286 202 }
ohair@286 203
ohair@286 204 public MessageFactory getMessageFactory() {
ohair@286 205 try {
ohair@286 206 return SAAJFactory.getMessageFactory(saajFactoryString);
ohair@286 207 } catch (SOAPException e) {
ohair@286 208 throw new Error(e);
ohair@286 209 } catch (NoSuchMethodError e) {
ohair@286 210 // SAAJ 1.3 is not in the classpath
ohair@286 211 LinkageError x = new LinkageError("You are loading old SAAJ from "+ Which.which(MessageFactory.class));
ohair@286 212 x.initCause(e);
ohair@286 213 throw x;
ohair@286 214 }
ohair@286 215 }
ohair@286 216
ohair@286 217 public String toString() {
ohair@286 218 return httpBindingId;
ohair@286 219 }
ohair@286 220
ohair@286 221 /**
ohair@286 222 * Returns {@link SOAPVersion} whose {@link #httpBindingId} equals to
ohair@286 223 * the given string.
ohair@286 224 *
ohair@286 225 * This method does not perform input string validation.
ohair@286 226 *
ohair@286 227 * @param binding
ohair@286 228 * for historical reason, we treat null as {@link #SOAP_11},
ohair@286 229 * but you really shouldn't be passing null.
ohair@286 230 * @return always non-null.
ohair@286 231 */
ohair@286 232 public static SOAPVersion fromHttpBinding(String binding) {
ohair@286 233 if(binding==null)
ohair@286 234 return SOAP_11;
ohair@286 235
ohair@286 236 if(binding.equals(SOAP_12.httpBindingId))
ohair@286 237 return SOAP_12;
ohair@286 238 else
ohair@286 239 return SOAP_11;
ohair@286 240 }
ohair@286 241
ohair@286 242 /**
ohair@286 243 * Returns {@link SOAPVersion} whose {@link #nsUri} equals to
ohair@286 244 * the given string.
ohair@286 245 *
ohair@286 246 * This method does not perform input string validation.
ohair@286 247 *
ohair@286 248 * @param nsUri
ohair@286 249 * must not be null.
ohair@286 250 * @return always non-null.
ohair@286 251 */
ohair@286 252 public static SOAPVersion fromNsUri(String nsUri) {
ohair@286 253 if(nsUri.equals(SOAP_12.nsUri))
ohair@286 254 return SOAP_12;
ohair@286 255 else
ohair@286 256 return SOAP_11;
ohair@286 257 }
ohair@286 258
ohair@286 259 public static SOAPVersion from(EnvelopeStyleFeature f) {
ohair@286 260 EnvelopeStyle.Style[] style = f.getStyles();
ohair@286 261 if (style.length != 1) throw new IllegalArgumentException ("The EnvelopingFeature must has exactly one Enveloping.Style");
ohair@286 262 return from(style[0]);
ohair@286 263 }
ohair@286 264
ohair@286 265 public static SOAPVersion from(EnvelopeStyle.Style style) {
ohair@286 266 switch (style) {
ohair@286 267 case SOAP11: return SOAP_11;
ohair@286 268 case SOAP12: return SOAP_12;
ohair@286 269 case XML: //ERROR??
ohair@286 270 default: return SOAP_11;
ohair@286 271 }
ohair@286 272 }
ohair@286 273
ohair@286 274 public EnvelopeStyleFeature toFeature() {
ohair@286 275 return SOAP_11.equals(this) ?
ohair@286 276 new EnvelopeStyleFeature(new EnvelopeStyle.Style[]{EnvelopeStyle.Style.SOAP11}) :
ohair@286 277 new EnvelopeStyleFeature(new EnvelopeStyle.Style[]{EnvelopeStyle.Style.SOAP12});
ohair@286 278 }
ohair@286 279 }

mercurial