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