Wed, 12 Jun 2013 14:47:09 +0100
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, 2012, 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.message; |
ohair@286 | 27 | |
ohair@286 | 28 | import com.sun.istack.internal.NotNull; |
ohair@286 | 29 | import com.sun.istack.internal.Nullable; |
ohair@286 | 30 | import com.sun.xml.internal.bind.api.Bridge; |
ohair@286 | 31 | import com.sun.xml.internal.ws.api.SOAPVersion; |
ohair@286 | 32 | import com.sun.xml.internal.ws.api.addressing.AddressingVersion; |
ohair@286 | 33 | import com.sun.xml.internal.ws.api.addressing.WSEndpointReference; |
ohair@286 | 34 | import com.sun.xml.internal.ws.spi.db.XMLBridge; |
ohair@286 | 35 | |
ohair@286 | 36 | import org.xml.sax.ContentHandler; |
ohair@286 | 37 | import org.xml.sax.ErrorHandler; |
ohair@286 | 38 | import org.xml.sax.SAXException; |
ohair@286 | 39 | import org.xml.sax.SAXParseException; |
ohair@286 | 40 | |
ohair@286 | 41 | import javax.xml.bind.JAXBException; |
ohair@286 | 42 | import javax.xml.bind.Unmarshaller; |
ohair@286 | 43 | import javax.xml.namespace.QName; |
ohair@286 | 44 | import javax.xml.soap.SOAPException; |
ohair@286 | 45 | import javax.xml.soap.SOAPMessage; |
ohair@286 | 46 | import javax.xml.stream.XMLStreamException; |
ohair@286 | 47 | import javax.xml.stream.XMLStreamReader; |
ohair@286 | 48 | import javax.xml.stream.XMLStreamWriter; |
ohair@286 | 49 | import javax.xml.ws.WebServiceException; |
ohair@286 | 50 | import java.util.Set; |
ohair@286 | 51 | |
ohair@286 | 52 | |
ohair@286 | 53 | /** |
ohair@286 | 54 | * A SOAP header. |
ohair@286 | 55 | * |
ohair@286 | 56 | * <p> |
ohair@286 | 57 | * A header is immutable, but unlike body it can be read |
ohair@286 | 58 | * multiple times. |
ohair@286 | 59 | * The {@link Header} abstraction hides how the header |
ohair@286 | 60 | * data is represented in memory; instead, it commits to |
ohair@286 | 61 | * the ability to write itself to XML infoset. |
ohair@286 | 62 | * |
ohair@286 | 63 | * <p> |
ohair@286 | 64 | * When a message is received from the transport and |
ohair@286 | 65 | * being processed, the processor needs to "peek" |
ohair@286 | 66 | * some information of a header, such as the tag name, |
ohair@286 | 67 | * the mustUnderstand attribute, and so on. Therefore, |
ohair@286 | 68 | * the {@link Header} interface exposes those information |
ohair@286 | 69 | * as properties, so that they can be checked without |
ohair@286 | 70 | * replaying the infoset, which is efficiently but still |
ohair@286 | 71 | * costly. |
ohair@286 | 72 | * |
ohair@286 | 73 | * <p> |
ohair@286 | 74 | * A {@link Header} may belong to more than one {@link HeaderList} |
ohair@286 | 75 | * due to wrapping of {@link Message}. |
ohair@286 | 76 | * |
ohair@286 | 77 | * @see HeaderList |
ohair@286 | 78 | * @see Headers |
ohair@286 | 79 | */ |
ohair@286 | 80 | public interface Header { |
ohair@286 | 81 | // TODO: Vivek pointed out that the only time we are looking at |
ohair@286 | 82 | // mustUnderstand and role are when we do the mustUnderstand error check |
ohair@286 | 83 | // (that is, to find out if there's any header with @mustUnderstand that |
ohair@286 | 84 | // has appropriate role for us.) |
ohair@286 | 85 | // if that's the case, it might be better if we define this whole operation |
ohair@286 | 86 | // as one method, instead of exposing two properties. |
ohair@286 | 87 | |
ohair@286 | 88 | /** |
ohair@286 | 89 | * Checks if this header is ignorable for us (IOW, make sure |
ohair@286 | 90 | * that this header has a problematic "mustUnderstand" header value |
ohair@286 | 91 | * that we have to reject.) |
ohair@286 | 92 | * |
ohair@286 | 93 | * <p> |
ohair@286 | 94 | * This method is used as a part of the |
ohair@286 | 95 | * <a href="HeaderList.html#MU">mustUnderstanx processing</a>. |
ohair@286 | 96 | * At the end of the processing, the JAX-WS identifies a list of {@link Header}s |
ohair@286 | 97 | * that were not understood. This method is invoked on those {@link Header}s, |
ohair@286 | 98 | * to verify that we don't need to report an error for it. |
ohair@286 | 99 | * |
ohair@286 | 100 | * <p> |
ohair@286 | 101 | * specifically, this method has to perform the following tasks: |
ohair@286 | 102 | * |
ohair@286 | 103 | * <ul> |
ohair@286 | 104 | * <li>If this header does not have <tt>mustUnderstand</tt> as "1" nor "true", |
ohair@286 | 105 | * then this method must return true. |
ohair@286 | 106 | * <li>Otherwise, check the role attribute (for SOAP 1.2) or the actor attribute (for SOAP 1.1). |
ohair@286 | 107 | * When those attributes are absent, the default values have to be assumed. |
ohair@286 | 108 | * See {@link #getRole(SOAPVersion)} for how the values are defaulted. |
ohair@286 | 109 | * Now, see if the {@code roles} set contains the value. |
ohair@286 | 110 | * If so, this method must return false (indicating that an error is in order.) |
ohair@286 | 111 | * <li>Otherwise return true (since we don't play the role this header is intended for.) |
ohair@286 | 112 | * </ul> |
ohair@286 | 113 | * |
ohair@286 | 114 | * @param soapVersion |
ohair@286 | 115 | * The caller specifies the SOAP version that the pipeline is working against. |
ohair@286 | 116 | * Often each {@link Header} implementation already knows the SOAP version |
ohair@286 | 117 | * anyway, but this allows some {@link Header}s to avoid keeping it. |
ohair@286 | 118 | * That's why this redundant parameter is passed in. |
ohair@286 | 119 | * @param roles |
ohair@286 | 120 | * The set of role values that the current JAX-WS pipeline is assuming. |
ohair@286 | 121 | * Note that SOAP 1.1 and SOAP 1.2 use different strings for the same role, |
ohair@286 | 122 | * and the caller is responsible for supplying a proper value depending on the |
ohair@286 | 123 | * active SOAP version in use. |
ohair@286 | 124 | * |
ohair@286 | 125 | * @return |
ohair@286 | 126 | * true if no error needs to be reported. False if an error needs to be raised. |
ohair@286 | 127 | * See the method javadoc for more discussion. |
ohair@286 | 128 | */ |
ohair@286 | 129 | public boolean isIgnorable(@NotNull SOAPVersion soapVersion, @NotNull Set<String> roles); |
ohair@286 | 130 | |
ohair@286 | 131 | /** |
ohair@286 | 132 | * Gets the value of the soap:role attribute (or soap:actor for SOAP 1.1). |
ohair@286 | 133 | * |
ohair@286 | 134 | * <p> |
ohair@286 | 135 | * If the attribute is omitted, the value defaults to {@link SOAPVersion#implicitRole}. |
ohair@286 | 136 | * |
ohair@286 | 137 | * @param soapVersion |
ohair@286 | 138 | * The caller specifies the SOAP version that the pipeline is working against. |
ohair@286 | 139 | * Often each {@link Header} implementation already knows the SOAP version |
ohair@286 | 140 | * anyway, but this allows some {@link Header}s to avoid keeping it. |
ohair@286 | 141 | * That's why this redundant parameter is passed in. |
ohair@286 | 142 | * @return |
ohair@286 | 143 | * never null. This string need not be interned. |
ohair@286 | 144 | */ |
ohair@286 | 145 | public @NotNull String getRole(@NotNull SOAPVersion soapVersion); |
ohair@286 | 146 | |
ohair@286 | 147 | /** |
ohair@286 | 148 | * True if this header is to be relayed if not processed. |
ohair@286 | 149 | * For SOAP 1.1 messages, this method always return false. |
ohair@286 | 150 | * |
ohair@286 | 151 | * <p> |
ohair@286 | 152 | * IOW, this method returns true if there's @soap:relay='true' |
ohair@286 | 153 | * is present. |
ohair@286 | 154 | * |
ohair@286 | 155 | * <h3>Implementation Note</h3> |
ohair@286 | 156 | * <p> |
ohair@286 | 157 | * The implementation needs to check for both "true" and "1", |
ohair@286 | 158 | * but because attribute values are normalized, it doesn't have |
ohair@286 | 159 | * to consider " true", " 1 ", and so on. |
ohair@286 | 160 | * |
ohair@286 | 161 | * @return |
ohair@286 | 162 | * false. |
ohair@286 | 163 | */ |
ohair@286 | 164 | public boolean isRelay(); |
ohair@286 | 165 | |
ohair@286 | 166 | /** |
ohair@286 | 167 | * Gets the namespace URI of this header element. |
ohair@286 | 168 | * |
ohair@286 | 169 | * @return |
ohair@286 | 170 | * this string must be interned. |
ohair@286 | 171 | */ |
ohair@286 | 172 | public @NotNull String getNamespaceURI(); |
ohair@286 | 173 | |
ohair@286 | 174 | /** |
ohair@286 | 175 | * Gets the local name of this header element. |
ohair@286 | 176 | * |
ohair@286 | 177 | * @return |
ohair@286 | 178 | * this string must be interned. |
ohair@286 | 179 | */ |
ohair@286 | 180 | public @NotNull String getLocalPart(); |
ohair@286 | 181 | |
ohair@286 | 182 | /** |
ohair@286 | 183 | * Gets the attribute value on the header element. |
ohair@286 | 184 | * |
ohair@286 | 185 | * @param nsUri |
ohair@286 | 186 | * The namespace URI of the attribute. Can be empty. |
ohair@286 | 187 | * @param localName |
ohair@286 | 188 | * The local name of the attribute. |
ohair@286 | 189 | * |
ohair@286 | 190 | * @return |
ohair@286 | 191 | * if the attribute is found, return the whitespace normalized value. |
ohair@286 | 192 | * (meaning no leading/trailing space, no consequtive whitespaces in-between.) |
ohair@286 | 193 | * Otherwise null. Note that the XML parsers are responsible for |
ohair@286 | 194 | * whitespace-normalizing attributes, so {@link Header} implementation |
ohair@286 | 195 | * doesn't have to do anything. |
ohair@286 | 196 | */ |
ohair@286 | 197 | @Nullable String getAttribute(@NotNull String nsUri, @NotNull String localName); |
ohair@286 | 198 | |
ohair@286 | 199 | /** |
ohair@286 | 200 | * Gets the attribute value on the header element. |
ohair@286 | 201 | * |
ohair@286 | 202 | * <p> |
ohair@286 | 203 | * This is a convenience method that calls into {@link #getAttribute(String, String)} |
ohair@286 | 204 | * |
ohair@286 | 205 | * @param name |
ohair@286 | 206 | * Never null. |
ohair@286 | 207 | * |
ohair@286 | 208 | * @see #getAttribute(String, String) |
ohair@286 | 209 | */ |
ohair@286 | 210 | @Nullable String getAttribute(@NotNull QName name); |
ohair@286 | 211 | |
ohair@286 | 212 | /** |
ohair@286 | 213 | * Reads the header as a {@link XMLStreamReader}. |
ohair@286 | 214 | * |
ohair@286 | 215 | * <p> |
ohair@286 | 216 | * The returned parser points at the start element of this header. |
ohair@286 | 217 | * (IOW, {@link XMLStreamReader#getEventType()} would return |
ohair@286 | 218 | * {@link XMLStreamReader#START_ELEMENT}. |
ohair@286 | 219 | * |
ohair@286 | 220 | * <h3>Performance Expectation</h3> |
ohair@286 | 221 | * <p> |
ohair@286 | 222 | * For some {@link Header} implementations, this operation |
ohair@286 | 223 | * is a non-trivial operation. Therefore, use of this method |
ohair@286 | 224 | * is discouraged unless the caller is interested in reading |
ohair@286 | 225 | * the whole header. |
ohair@286 | 226 | * |
ohair@286 | 227 | * <p> |
ohair@286 | 228 | * Similarly, if the caller wants to use this method only to do |
ohair@286 | 229 | * the API conversion (such as simply firing SAX events from |
ohair@286 | 230 | * {@link XMLStreamReader}), then the JAX-WS team requests |
ohair@286 | 231 | * that you talk to us. |
ohair@286 | 232 | * |
ohair@286 | 233 | * <p> |
ohair@286 | 234 | * {@link Message}s that come from tranport usually provides |
ohair@286 | 235 | * a reasonably efficient implementation of this method. |
ohair@286 | 236 | * |
ohair@286 | 237 | * @return |
ohair@286 | 238 | * must not null. |
ohair@286 | 239 | */ |
ohair@286 | 240 | public XMLStreamReader readHeader() throws XMLStreamException; |
ohair@286 | 241 | |
ohair@286 | 242 | /** |
ohair@286 | 243 | * Reads the header as a JAXB object by using the given unmarshaller. |
ohair@286 | 244 | */ |
ohair@286 | 245 | public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException; |
ohair@286 | 246 | |
ohair@286 | 247 | /** |
ohair@286 | 248 | * Reads the header as a JAXB object by using the given unmarshaller. |
ohair@286 | 249 | * @deprecated |
ohair@286 | 250 | */ |
ohair@286 | 251 | public <T> T readAsJAXB(Bridge<T> bridge) throws JAXBException; |
ohair@286 | 252 | |
ohair@286 | 253 | /** |
ohair@286 | 254 | * Reads the header as a data-bond object |
ohair@286 | 255 | */ |
ohair@286 | 256 | public <T> T readAsJAXB(XMLBridge<T> bridge) throws JAXBException; |
ohair@286 | 257 | |
ohair@286 | 258 | /** |
ohair@286 | 259 | * Reads this header as an {@link WSEndpointReference}. |
ohair@286 | 260 | * |
ohair@286 | 261 | * @param expected |
ohair@286 | 262 | * The version of the addressing used to parse the EPR. |
ohair@286 | 263 | * If the actual infoset and this doesn't agree, then |
ohair@286 | 264 | * you'll get an {@link WebServiceException} stating that fact. |
ohair@286 | 265 | * |
ohair@286 | 266 | * @return |
ohair@286 | 267 | * On a successful return, this method never returns null. |
ohair@286 | 268 | */ |
ohair@286 | 269 | public @NotNull WSEndpointReference readAsEPR(AddressingVersion expected) throws XMLStreamException; |
ohair@286 | 270 | |
ohair@286 | 271 | /** |
ohair@286 | 272 | * Writes out the header as a fragment. |
ohair@286 | 273 | * |
ohair@286 | 274 | * @throws XMLStreamException |
ohair@286 | 275 | * if the operation fails for some reason. This leaves the |
ohair@286 | 276 | * writer to an undefined state. |
ohair@286 | 277 | */ |
ohair@286 | 278 | public void writeTo(XMLStreamWriter w) throws XMLStreamException; |
ohair@286 | 279 | |
ohair@286 | 280 | /** |
ohair@286 | 281 | * Writes out the header to the given SOAPMessage. |
ohair@286 | 282 | * |
ohair@286 | 283 | * <p> |
ohair@286 | 284 | * Sometimes a {@link Message} needs to produce itself |
ohair@286 | 285 | * as {@link SOAPMessage}, in which case each header needs |
ohair@286 | 286 | * to turn itself into a header. |
ohair@286 | 287 | * |
ohair@286 | 288 | * @throws SOAPException |
ohair@286 | 289 | * if the operation fails for some reason. This leaves the |
ohair@286 | 290 | * writer to an undefined state. |
ohair@286 | 291 | */ |
ohair@286 | 292 | public void writeTo(SOAPMessage saaj) throws SOAPException; |
ohair@286 | 293 | |
ohair@286 | 294 | /** |
ohair@286 | 295 | * Writes out the header as SAX events. |
ohair@286 | 296 | * |
ohair@286 | 297 | * <p> |
ohair@286 | 298 | * Sometimes a {@link Message} needs to produce SAX events, |
ohair@286 | 299 | * and this method is necessary for headers to participate to it. |
ohair@286 | 300 | * |
ohair@286 | 301 | * <p> |
ohair@286 | 302 | * A header is responsible for producing the SAX events for its part, |
ohair@286 | 303 | * including <tt>startPrefixMapping</tt> and <tt>endPrefixMapping</tt>, |
ohair@286 | 304 | * but not startDocument/endDocument. |
ohair@286 | 305 | * |
ohair@286 | 306 | * <p> |
ohair@286 | 307 | * Note that SAX contract requires that any error that does NOT originate |
ohair@286 | 308 | * from {@link ContentHandler} (meaning any parsing error and etc) must |
ohair@286 | 309 | * be first reported to {@link ErrorHandler}. If the SAX event production |
ohair@286 | 310 | * cannot be continued and the processing needs to abort, the code may |
ohair@286 | 311 | * then throw the same {@link SAXParseException} reported to {@link ErrorHandler}. |
ohair@286 | 312 | * |
ohair@286 | 313 | * @param contentHandler |
ohair@286 | 314 | * The {@link ContentHandler} that receives SAX events. |
ohair@286 | 315 | * |
ohair@286 | 316 | * @param errorHandler |
ohair@286 | 317 | * The {@link ErrorHandler} that receives parsing errors. |
ohair@286 | 318 | */ |
ohair@286 | 319 | public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException; |
ohair@286 | 320 | |
ohair@286 | 321 | /** |
ohair@286 | 322 | * Used to obtain value XYZ from a header that looks like |
ohair@286 | 323 | * "<header>XYZ</header>". The primary use of this header |
ohair@286 | 324 | * for now is to access certain Addressing headers quickly. |
ohair@286 | 325 | * |
ohair@286 | 326 | * @throws WebServiceException |
ohair@286 | 327 | * If the structure of the header is more complicated than |
ohair@286 | 328 | * a simple string header. |
ohair@286 | 329 | * |
ohair@286 | 330 | * @return |
ohair@286 | 331 | * Can be empty but always non-null. |
ohair@286 | 332 | */ |
ohair@286 | 333 | public @NotNull String getStringContent(); |
ohair@286 | 334 | } |