Tue, 06 Mar 2012 16:09:35 -0800
7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom
ohair@286 | 1 | /* |
ohair@286 | 2 | * Copyright (c) 1997, 2010, 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.ws.addressing.WsaTubeHelper; |
ohair@286 | 31 | import com.sun.xml.internal.ws.api.SOAPVersion; |
ohair@286 | 32 | import com.sun.xml.internal.ws.api.WSBinding; |
ohair@286 | 33 | import com.sun.xml.internal.ws.api.addressing.AddressingVersion; |
ohair@286 | 34 | import com.sun.xml.internal.ws.api.addressing.OneWayFeature; |
ohair@286 | 35 | import com.sun.xml.internal.ws.api.addressing.WSEndpointReference; |
ohair@286 | 36 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation; |
ohair@286 | 37 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
ohair@286 | 38 | import com.sun.xml.internal.ws.api.pipe.Codec; |
ohair@286 | 39 | import com.sun.xml.internal.ws.api.pipe.Pipe; |
ohair@286 | 40 | import com.sun.xml.internal.ws.message.RelatesToHeader; |
ohair@286 | 41 | import com.sun.xml.internal.ws.message.StringHeader; |
ohair@286 | 42 | import com.sun.xml.internal.ws.protocol.soap.ClientMUTube; |
ohair@286 | 43 | import com.sun.xml.internal.ws.protocol.soap.ServerMUTube; |
ohair@286 | 44 | import com.sun.xml.internal.ws.resources.AddressingMessages; |
ohair@286 | 45 | import com.sun.xml.internal.ws.resources.ClientMessages; |
ohair@286 | 46 | |
ohair@286 | 47 | import javax.xml.namespace.QName; |
ohair@286 | 48 | import javax.xml.stream.XMLStreamException; |
ohair@286 | 49 | import javax.xml.ws.WebServiceException; |
ohair@286 | 50 | import javax.xml.ws.soap.SOAPBinding; |
ohair@286 | 51 | import java.util.ArrayList; |
ohair@286 | 52 | import java.util.BitSet; |
ohair@286 | 53 | import java.util.Iterator; |
ohair@286 | 54 | import java.util.NoSuchElementException; |
ohair@286 | 55 | |
ohair@286 | 56 | /** |
ohair@286 | 57 | * A list of {@link Header}s on a {@link Message}. |
ohair@286 | 58 | * |
ohair@286 | 59 | * <p> |
ohair@286 | 60 | * This list can be modified to add headers |
ohair@286 | 61 | * from outside a {@link Message}, this is necessary |
ohair@286 | 62 | * since intermediate processing layers often need to |
ohair@286 | 63 | * put additional headers. |
ohair@286 | 64 | * |
ohair@286 | 65 | * <p> |
ohair@286 | 66 | * Following the SOAP convention, the order among headers |
ohair@286 | 67 | * are not significant. However, {@link Codec}s are |
ohair@286 | 68 | * expected to preserve the order of headers in the input |
ohair@286 | 69 | * message as much as possible. |
ohair@286 | 70 | * |
ohair@286 | 71 | * |
ohair@286 | 72 | * <a name="MU"></a> |
ohair@286 | 73 | * <h3>MustUnderstand Processing</h3> |
ohair@286 | 74 | * <p> |
ohair@286 | 75 | * To perform SOAP mustUnderstang processing correctly, we need to keep |
ohair@286 | 76 | * track of headers that are understood and headers that are not. |
ohair@286 | 77 | * This is a collaborative process among {@link Pipe}s, thus it's something |
ohair@286 | 78 | * a {@link Pipe} author needs to keep in mind. |
ohair@286 | 79 | * |
ohair@286 | 80 | * <p> |
ohair@286 | 81 | * Specifically, when a {@link Pipe} sees a header and processes it |
ohair@286 | 82 | * (that is, if it did enough computing with the header to claim that |
ohair@286 | 83 | * the header is understood), then it should mark the corresponding |
ohair@286 | 84 | * header as "understood". For example, when a pipe that handles JAX-WSA |
ohair@286 | 85 | * examins the <wsa:To> header, it can claim that it understood the header. |
ohair@286 | 86 | * But for example, if a pipe that does the signature verification checks |
ohair@286 | 87 | * <wsa:To> for a signature, that would not be considered as "understood". |
ohair@286 | 88 | * |
ohair@286 | 89 | * <p> |
ohair@286 | 90 | * There are two ways to mark a header as understood: |
ohair@286 | 91 | * |
ohair@286 | 92 | * <ol> |
ohair@286 | 93 | * <li>Use one of the <tt>getXXX</tt> methods that take a |
ohair@286 | 94 | * boolean <tt>markAsUnderstood</tt> parameter. |
ohair@286 | 95 | * Most often, a {@link Pipe} knows it's going to understand a header |
ohair@286 | 96 | * as long as it's present, so this is the easiest and thus the preferred way. |
ohair@286 | 97 | * |
ohair@286 | 98 | * For example, if JAX-WSA looks for <wsa:To>, then it can set |
ohair@286 | 99 | * <tt>markAsUnderstand</tt> to true, to do the obtaining of a header |
ohair@286 | 100 | * and marking at the same time. |
ohair@286 | 101 | * |
ohair@286 | 102 | * <li>Call {@link #understood(int)}. |
ohair@286 | 103 | * If under a rare circumstance, a pipe cannot determine whether |
ohair@286 | 104 | * it can understand it or not when you are fetching a header, then |
ohair@286 | 105 | * you can use this method afterward to mark it as understood. |
ohair@286 | 106 | * </ol> |
ohair@286 | 107 | * |
ohair@286 | 108 | * <p> |
ohair@286 | 109 | * Intuitively speaking, at the end of the day, if a header is not |
ohair@286 | 110 | * understood but {@link Header#isIgnorable(SOAPVersion, java.util.Set)} is false, a bad thing |
ohair@286 | 111 | * will happen. The actual implementation of the checking is more complicated, |
ohair@286 | 112 | * for that see {@link ClientMUTube}/{@link ServerMUTube}. |
ohair@286 | 113 | * |
ohair@286 | 114 | * @see Message#getHeaders() |
ohair@286 | 115 | */ |
ohair@286 | 116 | public class HeaderList extends ArrayList<Header> { |
ohair@286 | 117 | |
ohair@286 | 118 | private static final long serialVersionUID = -6358045781349627237L; |
ohair@286 | 119 | /** |
ohair@286 | 120 | * Bit set to keep track of which headers are understood. |
ohair@286 | 121 | * <p> |
ohair@286 | 122 | * The first 32 headers use this field, and the rest will use |
ohair@286 | 123 | * {@link #moreUnderstoodBits}. The expectation is that |
ohair@286 | 124 | * most of the time a SOAP message will only have up to 32 headers, |
ohair@286 | 125 | * so we can avoid allocating separate objects for {@link BitSet}. |
ohair@286 | 126 | */ |
ohair@286 | 127 | private int understoodBits; |
ohair@286 | 128 | /** |
ohair@286 | 129 | * If there are more than 32 headers, we use this {@link BitSet} |
ohair@286 | 130 | * to keep track of whether those headers are understood. |
ohair@286 | 131 | * Lazily allocated. |
ohair@286 | 132 | */ |
ohair@286 | 133 | private BitSet moreUnderstoodBits = null; |
ohair@286 | 134 | |
ohair@286 | 135 | /** |
ohair@286 | 136 | * Creates an empty {@link HeaderList}. |
ohair@286 | 137 | */ |
ohair@286 | 138 | public HeaderList() { |
ohair@286 | 139 | } |
ohair@286 | 140 | |
ohair@286 | 141 | /** |
ohair@286 | 142 | * Copy constructor. |
ohair@286 | 143 | */ |
ohair@286 | 144 | public HeaderList(HeaderList that) { |
ohair@286 | 145 | super(that); |
ohair@286 | 146 | this.understoodBits = that.understoodBits; |
ohair@286 | 147 | if (that.moreUnderstoodBits != null) { |
ohair@286 | 148 | this.moreUnderstoodBits = (BitSet) that.moreUnderstoodBits.clone(); |
ohair@286 | 149 | } |
ohair@286 | 150 | } |
ohair@286 | 151 | |
ohair@286 | 152 | /** |
ohair@286 | 153 | * The total number of headers. |
ohair@286 | 154 | */ |
ohair@286 | 155 | @Override |
ohair@286 | 156 | public int size() { |
ohair@286 | 157 | return super.size(); |
ohair@286 | 158 | } |
ohair@286 | 159 | |
ohair@286 | 160 | /** |
ohair@286 | 161 | * Adds all the headers. |
ohair@286 | 162 | */ |
ohair@286 | 163 | public void addAll(Header... headers) { |
ohair@286 | 164 | for (Header header : headers) { |
ohair@286 | 165 | add(header); |
ohair@286 | 166 | } |
ohair@286 | 167 | } |
ohair@286 | 168 | |
ohair@286 | 169 | /** |
ohair@286 | 170 | * Gets the {@link Header} at the specified index. |
ohair@286 | 171 | * |
ohair@286 | 172 | * <p> |
ohair@286 | 173 | * This method does not mark the returned {@link Header} as understood. |
ohair@286 | 174 | * |
ohair@286 | 175 | * @see #understood(int) |
ohair@286 | 176 | */ |
ohair@286 | 177 | @Override |
ohair@286 | 178 | public Header get(int index) { |
ohair@286 | 179 | return super.get(index); |
ohair@286 | 180 | } |
ohair@286 | 181 | |
ohair@286 | 182 | /** |
ohair@286 | 183 | * Marks the {@link Header} at the specified index as |
ohair@286 | 184 | * <a href="#MU">"understood"</a>. |
ohair@286 | 185 | */ |
ohair@286 | 186 | public void understood(int index) { |
ohair@286 | 187 | // check that index is in range |
ohair@286 | 188 | if (index >= size()) { |
ohair@286 | 189 | throw new ArrayIndexOutOfBoundsException(index); |
ohair@286 | 190 | } |
ohair@286 | 191 | |
ohair@286 | 192 | if (index < 32) { |
ohair@286 | 193 | understoodBits |= 1 << index; |
ohair@286 | 194 | } else { |
ohair@286 | 195 | if (moreUnderstoodBits == null) { |
ohair@286 | 196 | moreUnderstoodBits = new BitSet(); |
ohair@286 | 197 | } |
ohair@286 | 198 | moreUnderstoodBits.set(index - 32); |
ohair@286 | 199 | } |
ohair@286 | 200 | } |
ohair@286 | 201 | |
ohair@286 | 202 | /** |
ohair@286 | 203 | * Returns true if a {@link Header} at the given index |
ohair@286 | 204 | * was <a href="#MU">"understood"</a>. |
ohair@286 | 205 | */ |
ohair@286 | 206 | public boolean isUnderstood(int index) { |
ohair@286 | 207 | // check that index is in range |
ohair@286 | 208 | if (index >= size()) { |
ohair@286 | 209 | throw new ArrayIndexOutOfBoundsException(index); |
ohair@286 | 210 | } |
ohair@286 | 211 | |
ohair@286 | 212 | if (index < 32) { |
ohair@286 | 213 | return understoodBits == (understoodBits | (1 << index)); |
ohair@286 | 214 | } else { |
ohair@286 | 215 | if (moreUnderstoodBits == null) { |
ohair@286 | 216 | return false; |
ohair@286 | 217 | } |
ohair@286 | 218 | return moreUnderstoodBits.get(index - 32); |
ohair@286 | 219 | } |
ohair@286 | 220 | } |
ohair@286 | 221 | |
ohair@286 | 222 | /** |
ohair@286 | 223 | * Marks the specified {@link Header} as <a href="#MU">"understood"</a>. |
ohair@286 | 224 | * |
ohair@286 | 225 | * @deprecated |
ohair@286 | 226 | * By the definition of {@link ArrayList}, this operation requires |
ohair@286 | 227 | * O(n) search of the array, and thus inherently inefficient. |
ohair@286 | 228 | * |
ohair@286 | 229 | * Because of this, if you are developing a {@link Pipe} for |
ohair@286 | 230 | * a performance sensitive environment, do not use this method. |
ohair@286 | 231 | * |
ohair@286 | 232 | * @throws IllegalArgumentException |
ohair@286 | 233 | * if the given header is not {@link #contains(Object) contained} |
ohair@286 | 234 | * in this header. |
ohair@286 | 235 | */ |
ohair@286 | 236 | public void understood(@NotNull Header header) { |
ohair@286 | 237 | int sz = size(); |
ohair@286 | 238 | for (int i = 0; i < sz; i++) { |
ohair@286 | 239 | if (get(i) == header) { |
ohair@286 | 240 | understood(i); |
ohair@286 | 241 | return; |
ohair@286 | 242 | } |
ohair@286 | 243 | } |
ohair@286 | 244 | throw new IllegalArgumentException(); |
ohair@286 | 245 | } |
ohair@286 | 246 | |
ohair@286 | 247 | /** |
ohair@286 | 248 | * Gets the first {@link Header} of the specified name. |
ohair@286 | 249 | * |
ohair@286 | 250 | * @param markAsUnderstood |
ohair@286 | 251 | * If this parameter is true, the returned header will |
ohair@286 | 252 | * be marked as <a href="#MU">"understood"</a>. |
ohair@286 | 253 | * @return null if not found. |
ohair@286 | 254 | */ |
ohair@286 | 255 | public |
ohair@286 | 256 | @Nullable |
ohair@286 | 257 | Header get(@NotNull String nsUri, @NotNull String localName, boolean markAsUnderstood) { |
ohair@286 | 258 | int len = size(); |
ohair@286 | 259 | for (int i = 0; i < len; i++) { |
ohair@286 | 260 | Header h = get(i); |
ohair@286 | 261 | if (h.getLocalPart().equals(localName) && h.getNamespaceURI().equals(nsUri)) { |
ohair@286 | 262 | if (markAsUnderstood) { |
ohair@286 | 263 | understood(i); |
ohair@286 | 264 | } |
ohair@286 | 265 | return h; |
ohair@286 | 266 | } |
ohair@286 | 267 | } |
ohair@286 | 268 | return null; |
ohair@286 | 269 | } |
ohair@286 | 270 | |
ohair@286 | 271 | /** |
ohair@286 | 272 | * @deprecated |
ohair@286 | 273 | * Use {@link #get(String, String, boolean)} |
ohair@286 | 274 | */ |
ohair@286 | 275 | public Header get(String nsUri, String localName) { |
ohair@286 | 276 | return get(nsUri, localName, true); |
ohair@286 | 277 | } |
ohair@286 | 278 | |
ohair@286 | 279 | /** |
ohair@286 | 280 | * Gets the first {@link Header} of the specified name. |
ohair@286 | 281 | * |
ohair@286 | 282 | * @param markAsUnderstood |
ohair@286 | 283 | * If this parameter is true, the returned header will |
ohair@286 | 284 | * be marked as <a href="#MU">"understood"</a>. |
ohair@286 | 285 | * @return null |
ohair@286 | 286 | * if not found. |
ohair@286 | 287 | */ |
ohair@286 | 288 | public |
ohair@286 | 289 | @Nullable |
ohair@286 | 290 | Header get(@NotNull QName name, boolean markAsUnderstood) { |
ohair@286 | 291 | return get(name.getNamespaceURI(), name.getLocalPart(), markAsUnderstood); |
ohair@286 | 292 | } |
ohair@286 | 293 | |
ohair@286 | 294 | /** |
ohair@286 | 295 | * @deprecated |
ohair@286 | 296 | * Use {@link #get(QName)} |
ohair@286 | 297 | */ |
ohair@286 | 298 | public |
ohair@286 | 299 | @Nullable |
ohair@286 | 300 | Header get(@NotNull QName name) { |
ohair@286 | 301 | return get(name, true); |
ohair@286 | 302 | } |
ohair@286 | 303 | |
ohair@286 | 304 | /** |
ohair@286 | 305 | * @deprecated |
ohair@286 | 306 | * Use {@link #getHeaders(String, String, boolean)} |
ohair@286 | 307 | */ |
ohair@286 | 308 | public Iterator<Header> getHeaders(final String nsUri, final String localName) { |
ohair@286 | 309 | return getHeaders(nsUri, localName, true); |
ohair@286 | 310 | } |
ohair@286 | 311 | |
ohair@286 | 312 | /** |
ohair@286 | 313 | * Gets all the {@link Header}s of the specified name, |
ohair@286 | 314 | * including duplicates (if any.) |
ohair@286 | 315 | * |
ohair@286 | 316 | * @param markAsUnderstood |
ohair@286 | 317 | * If this parameter is true, the returned headers will |
ohair@286 | 318 | * be marked as <a href="#MU">"understood"</a> when they are returned |
ohair@286 | 319 | * from {@link Iterator#next()}. |
ohair@286 | 320 | * @return empty iterator if not found. |
ohair@286 | 321 | */ |
ohair@286 | 322 | public |
ohair@286 | 323 | @NotNull |
ohair@286 | 324 | Iterator<Header> getHeaders(@NotNull final String nsUri, @NotNull final String localName, final boolean markAsUnderstood) { |
ohair@286 | 325 | return new Iterator<Header>() { |
ohair@286 | 326 | |
ohair@286 | 327 | int idx = 0; |
ohair@286 | 328 | Header next; |
ohair@286 | 329 | |
ohair@286 | 330 | public boolean hasNext() { |
ohair@286 | 331 | if (next == null) { |
ohair@286 | 332 | fetch(); |
ohair@286 | 333 | } |
ohair@286 | 334 | return next != null; |
ohair@286 | 335 | } |
ohair@286 | 336 | |
ohair@286 | 337 | public Header next() { |
ohair@286 | 338 | if (next == null) { |
ohair@286 | 339 | fetch(); |
ohair@286 | 340 | if (next == null) { |
ohair@286 | 341 | throw new NoSuchElementException(); |
ohair@286 | 342 | } |
ohair@286 | 343 | } |
ohair@286 | 344 | |
ohair@286 | 345 | if (markAsUnderstood) { |
ohair@286 | 346 | assert get(idx - 1) == next; |
ohair@286 | 347 | understood(idx - 1); |
ohair@286 | 348 | } |
ohair@286 | 349 | |
ohair@286 | 350 | Header r = next; |
ohair@286 | 351 | next = null; |
ohair@286 | 352 | return r; |
ohair@286 | 353 | } |
ohair@286 | 354 | |
ohair@286 | 355 | private void fetch() { |
ohair@286 | 356 | while (idx < size()) { |
ohair@286 | 357 | Header h = get(idx++); |
ohair@286 | 358 | if (h.getLocalPart().equals(localName) && h.getNamespaceURI().equals(nsUri)) { |
ohair@286 | 359 | next = h; |
ohair@286 | 360 | break; |
ohair@286 | 361 | } |
ohair@286 | 362 | } |
ohair@286 | 363 | } |
ohair@286 | 364 | |
ohair@286 | 365 | public void remove() { |
ohair@286 | 366 | throw new UnsupportedOperationException(); |
ohair@286 | 367 | } |
ohair@286 | 368 | }; |
ohair@286 | 369 | } |
ohair@286 | 370 | |
ohair@286 | 371 | /** |
ohair@286 | 372 | * @see #getHeaders(String, String, boolean) |
ohair@286 | 373 | */ |
ohair@286 | 374 | public |
ohair@286 | 375 | @NotNull |
ohair@286 | 376 | Iterator<Header> getHeaders(@NotNull QName headerName, final boolean markAsUnderstood) { |
ohair@286 | 377 | return getHeaders(headerName.getNamespaceURI(), headerName.getLocalPart(), markAsUnderstood); |
ohair@286 | 378 | } |
ohair@286 | 379 | |
ohair@286 | 380 | /** |
ohair@286 | 381 | * @deprecated |
ohair@286 | 382 | * use {@link #getHeaders(String, boolean)}. |
ohair@286 | 383 | */ |
ohair@286 | 384 | public |
ohair@286 | 385 | @NotNull |
ohair@286 | 386 | Iterator<Header> getHeaders(@NotNull final String nsUri) { |
ohair@286 | 387 | return getHeaders(nsUri, true); |
ohair@286 | 388 | } |
ohair@286 | 389 | |
ohair@286 | 390 | /** |
ohair@286 | 391 | * Gets an iteration of headers {@link Header} in the specified namespace, |
ohair@286 | 392 | * including duplicates (if any.) |
ohair@286 | 393 | * |
ohair@286 | 394 | * @param markAsUnderstood |
ohair@286 | 395 | * If this parameter is true, the returned headers will |
ohair@286 | 396 | * be marked as <a href="#MU">"understood"</a> when they are returned |
ohair@286 | 397 | * from {@link Iterator#next()}. |
ohair@286 | 398 | * @return |
ohair@286 | 399 | * empty iterator if not found. |
ohair@286 | 400 | */ |
ohair@286 | 401 | public |
ohair@286 | 402 | @NotNull |
ohair@286 | 403 | Iterator<Header> getHeaders(@NotNull final String nsUri, final boolean markAsUnderstood) { |
ohair@286 | 404 | return new Iterator<Header>() { |
ohair@286 | 405 | |
ohair@286 | 406 | int idx = 0; |
ohair@286 | 407 | Header next; |
ohair@286 | 408 | |
ohair@286 | 409 | public boolean hasNext() { |
ohair@286 | 410 | if (next == null) { |
ohair@286 | 411 | fetch(); |
ohair@286 | 412 | } |
ohair@286 | 413 | return next != null; |
ohair@286 | 414 | } |
ohair@286 | 415 | |
ohair@286 | 416 | public Header next() { |
ohair@286 | 417 | if (next == null) { |
ohair@286 | 418 | fetch(); |
ohair@286 | 419 | if (next == null) { |
ohair@286 | 420 | throw new NoSuchElementException(); |
ohair@286 | 421 | } |
ohair@286 | 422 | } |
ohair@286 | 423 | |
ohair@286 | 424 | if (markAsUnderstood) { |
ohair@286 | 425 | assert get(idx - 1) == next; |
ohair@286 | 426 | understood(idx - 1); |
ohair@286 | 427 | } |
ohair@286 | 428 | |
ohair@286 | 429 | Header r = next; |
ohair@286 | 430 | next = null; |
ohair@286 | 431 | return r; |
ohair@286 | 432 | } |
ohair@286 | 433 | |
ohair@286 | 434 | private void fetch() { |
ohair@286 | 435 | while (idx < size()) { |
ohair@286 | 436 | Header h = get(idx++); |
ohair@286 | 437 | if (h.getNamespaceURI().equals(nsUri)) { |
ohair@286 | 438 | next = h; |
ohair@286 | 439 | break; |
ohair@286 | 440 | } |
ohair@286 | 441 | } |
ohair@286 | 442 | } |
ohair@286 | 443 | |
ohair@286 | 444 | public void remove() { |
ohair@286 | 445 | throw new UnsupportedOperationException(); |
ohair@286 | 446 | } |
ohair@286 | 447 | }; |
ohair@286 | 448 | } |
ohair@286 | 449 | |
ohair@286 | 450 | /** |
ohair@286 | 451 | * Gets the first {@link Header} of the specified name targeted at the |
ohair@286 | 452 | * current implicit role. |
ohair@286 | 453 | * |
ohair@286 | 454 | * @param name name of the header |
ohair@286 | 455 | * @param markUnderstood |
ohair@286 | 456 | * If this parameter is true, the returned headers will |
ohair@286 | 457 | * be marked as <a href="#MU">"understood"</a> when they are returned |
ohair@286 | 458 | * from {@link Iterator#next()}. |
ohair@286 | 459 | * @return null if header not found |
ohair@286 | 460 | */ |
ohair@286 | 461 | private Header getFirstHeader(QName name, boolean markUnderstood, SOAPVersion sv) { |
ohair@286 | 462 | if (sv == null) { |
ohair@286 | 463 | throw new IllegalArgumentException(AddressingMessages.NULL_SOAP_VERSION()); |
ohair@286 | 464 | } |
ohair@286 | 465 | |
ohair@286 | 466 | Iterator<Header> iter = getHeaders(name.getNamespaceURI(), name.getLocalPart(), markUnderstood); |
ohair@286 | 467 | while (iter.hasNext()) { |
ohair@286 | 468 | Header h = iter.next(); |
ohair@286 | 469 | if (h.getRole(sv).equals(sv.implicitRole)) { |
ohair@286 | 470 | return h; |
ohair@286 | 471 | } |
ohair@286 | 472 | } |
ohair@286 | 473 | |
ohair@286 | 474 | return null; |
ohair@286 | 475 | } |
ohair@286 | 476 | |
ohair@286 | 477 | /** |
ohair@286 | 478 | * Returns the value of WS-Addressing <code>To</code> header. The <code>version</code> |
ohair@286 | 479 | * identifies the WS-Addressing version and the header returned is targeted at |
ohair@286 | 480 | * the current implicit role. Caches the value for subsequent invocation. |
ohair@286 | 481 | * Duplicate <code>To</code> headers are detected earlier. |
ohair@286 | 482 | * |
ohair@286 | 483 | * @param av WS-Addressing version |
ohair@286 | 484 | * @param sv SOAP version |
ohair@286 | 485 | * @throws IllegalArgumentException if either <code>av</code> or <code>sv</code> is null. |
ohair@286 | 486 | * @return Value of WS-Addressing To header, anonymous URI if no header is present |
ohair@286 | 487 | */ |
ohair@286 | 488 | public String getTo(AddressingVersion av, SOAPVersion sv) { |
ohair@286 | 489 | if (av == null) { |
ohair@286 | 490 | throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION()); |
ohair@286 | 491 | } |
ohair@286 | 492 | |
ohair@286 | 493 | Header h = getFirstHeader(av.toTag, true, sv); |
ohair@286 | 494 | String to; |
ohair@286 | 495 | if (h != null) { |
ohair@286 | 496 | to = h.getStringContent(); |
ohair@286 | 497 | } else { |
ohair@286 | 498 | to = av.anonymousUri; |
ohair@286 | 499 | } |
ohair@286 | 500 | |
ohair@286 | 501 | return to; |
ohair@286 | 502 | } |
ohair@286 | 503 | |
ohair@286 | 504 | /** |
ohair@286 | 505 | * Returns the value of WS-Addressing <code>Action</code> header. The <code>version</code> |
ohair@286 | 506 | * identifies the WS-Addressing version and the header returned is targeted at |
ohair@286 | 507 | * the current implicit role. Caches the value for subsequent invocation. |
ohair@286 | 508 | * Duplicate <code>Action</code> headers are detected earlier. |
ohair@286 | 509 | * |
ohair@286 | 510 | * @param av WS-Addressing version |
ohair@286 | 511 | * @param sv SOAP version |
ohair@286 | 512 | * @throws IllegalArgumentException if either <code>av</code> or <code>sv</code> is null. |
ohair@286 | 513 | * @return Value of WS-Addressing Action header, null if no header is present |
ohair@286 | 514 | */ |
ohair@286 | 515 | public String getAction(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) { |
ohair@286 | 516 | if (av == null) { |
ohair@286 | 517 | throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION()); |
ohair@286 | 518 | } |
ohair@286 | 519 | |
ohair@286 | 520 | String action = null; |
ohair@286 | 521 | Header h = getFirstHeader(av.actionTag, true, sv); |
ohair@286 | 522 | if (h != null) { |
ohair@286 | 523 | action = h.getStringContent(); |
ohair@286 | 524 | } |
ohair@286 | 525 | |
ohair@286 | 526 | return action; |
ohair@286 | 527 | } |
ohair@286 | 528 | |
ohair@286 | 529 | /** |
ohair@286 | 530 | * Returns the value of WS-Addressing <code>ReplyTo</code> header. The <code>version</code> |
ohair@286 | 531 | * identifies the WS-Addressing version and the header returned is targeted at |
ohair@286 | 532 | * the current implicit role. Caches the value for subsequent invocation. |
ohair@286 | 533 | * Duplicate <code>ReplyTo</code> headers are detected earlier. |
ohair@286 | 534 | * |
ohair@286 | 535 | * @param av WS-Addressing version |
ohair@286 | 536 | * @param sv SOAP version |
ohair@286 | 537 | * @throws IllegalArgumentException if either <code>av</code> or <code>sv</code> is null. |
ohair@286 | 538 | * @return Value of WS-Addressing ReplyTo header, null if no header is present |
ohair@286 | 539 | */ |
ohair@286 | 540 | public WSEndpointReference getReplyTo(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) { |
ohair@286 | 541 | if (av == null) { |
ohair@286 | 542 | throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION()); |
ohair@286 | 543 | } |
ohair@286 | 544 | |
ohair@286 | 545 | Header h = getFirstHeader(av.replyToTag, true, sv); |
ohair@286 | 546 | WSEndpointReference replyTo; |
ohair@286 | 547 | if (h != null) { |
ohair@286 | 548 | try { |
ohair@286 | 549 | replyTo = h.readAsEPR(av); |
ohair@286 | 550 | } catch (XMLStreamException e) { |
ohair@286 | 551 | throw new WebServiceException(AddressingMessages.REPLY_TO_CANNOT_PARSE(), e); |
ohair@286 | 552 | } |
ohair@286 | 553 | } else { |
ohair@286 | 554 | replyTo = av.anonymousEpr; |
ohair@286 | 555 | } |
ohair@286 | 556 | |
ohair@286 | 557 | return replyTo; |
ohair@286 | 558 | } |
ohair@286 | 559 | |
ohair@286 | 560 | /** |
ohair@286 | 561 | * Returns the value of WS-Addressing <code>FaultTo</code> header. The <code>version</code> |
ohair@286 | 562 | * identifies the WS-Addressing version and the header returned is targeted at |
ohair@286 | 563 | * the current implicit role. Caches the value for subsequent invocation. |
ohair@286 | 564 | * Duplicate <code>FaultTo</code> headers are detected earlier. |
ohair@286 | 565 | * |
ohair@286 | 566 | * @param av WS-Addressing version |
ohair@286 | 567 | * @param sv SOAP version |
ohair@286 | 568 | * @throws IllegalArgumentException if either <code>av</code> or <code>sv</code> is null. |
ohair@286 | 569 | * @return Value of WS-Addressing FaultTo header, null if no header is present |
ohair@286 | 570 | */ |
ohair@286 | 571 | public WSEndpointReference getFaultTo(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) { |
ohair@286 | 572 | if (av == null) { |
ohair@286 | 573 | throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION()); |
ohair@286 | 574 | } |
ohair@286 | 575 | |
ohair@286 | 576 | Header h = getFirstHeader(av.faultToTag, true, sv); |
ohair@286 | 577 | WSEndpointReference faultTo = null; |
ohair@286 | 578 | if (h != null) { |
ohair@286 | 579 | try { |
ohair@286 | 580 | faultTo = h.readAsEPR(av); |
ohair@286 | 581 | } catch (XMLStreamException e) { |
ohair@286 | 582 | throw new WebServiceException(AddressingMessages.FAULT_TO_CANNOT_PARSE(), e); |
ohair@286 | 583 | } |
ohair@286 | 584 | } |
ohair@286 | 585 | |
ohair@286 | 586 | return faultTo; |
ohair@286 | 587 | } |
ohair@286 | 588 | |
ohair@286 | 589 | /** |
ohair@286 | 590 | * Returns the value of WS-Addressing <code>MessageID</code> header. The <code>version</code> |
ohair@286 | 591 | * identifies the WS-Addressing version and the header returned is targeted at |
ohair@286 | 592 | * the current implicit role. Caches the value for subsequent invocation. |
ohair@286 | 593 | * Duplicate <code>MessageID</code> headers are detected earlier. |
ohair@286 | 594 | * |
ohair@286 | 595 | * @param av WS-Addressing version |
ohair@286 | 596 | * @param sv SOAP version |
ohair@286 | 597 | * @throws WebServiceException if either <code>av</code> or <code>sv</code> is null. |
ohair@286 | 598 | * @return Value of WS-Addressing MessageID header, null if no header is present |
ohair@286 | 599 | */ |
ohair@286 | 600 | public String getMessageID(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) { |
ohair@286 | 601 | if (av == null) { |
ohair@286 | 602 | throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION()); |
ohair@286 | 603 | } |
ohair@286 | 604 | |
ohair@286 | 605 | Header h = getFirstHeader(av.messageIDTag, true, sv); |
ohair@286 | 606 | String messageId = null; |
ohair@286 | 607 | if (h != null) { |
ohair@286 | 608 | messageId = h.getStringContent(); |
ohair@286 | 609 | } |
ohair@286 | 610 | |
ohair@286 | 611 | return messageId; |
ohair@286 | 612 | } |
ohair@286 | 613 | |
ohair@286 | 614 | /** |
ohair@286 | 615 | * Returns the value of WS-Addressing <code>RelatesTo</code> header. The <code>version</code> |
ohair@286 | 616 | * identifies the WS-Addressing version and the header returned is targeted at |
ohair@286 | 617 | * the current implicit role. Caches the value for subsequent invocation. |
ohair@286 | 618 | * Duplicate <code>RelatesTo</code> headers are detected earlier. |
ohair@286 | 619 | * |
ohair@286 | 620 | * @param av WS-Addressing version |
ohair@286 | 621 | * @param sv SOAP version |
ohair@286 | 622 | * @throws WebServiceException if either <code>av</code> or <code>sv</code> is null. |
ohair@286 | 623 | * @return Value of WS-Addressing RelatesTo header, null if no header is present |
ohair@286 | 624 | */ |
ohair@286 | 625 | public String getRelatesTo(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) { |
ohair@286 | 626 | if (av == null) { |
ohair@286 | 627 | throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION()); |
ohair@286 | 628 | } |
ohair@286 | 629 | |
ohair@286 | 630 | Header h = getFirstHeader(av.relatesToTag, true, sv); |
ohair@286 | 631 | String relatesTo = null; |
ohair@286 | 632 | if (h != null) { |
ohair@286 | 633 | relatesTo = h.getStringContent(); |
ohair@286 | 634 | } |
ohair@286 | 635 | |
ohair@286 | 636 | return relatesTo; |
ohair@286 | 637 | } |
ohair@286 | 638 | |
ohair@286 | 639 | /** |
ohair@286 | 640 | * Creates a set of outbound WS-Addressing headers on the client with the |
ohair@286 | 641 | * specified Action Message Addressing Property value. |
ohair@286 | 642 | * <p><p> |
ohair@286 | 643 | * This method needs to be invoked right after such a Message is |
ohair@286 | 644 | * created which is error prone but so far only MEX, RM and JAX-WS |
ohair@286 | 645 | * creates a request so this ugliness is acceptable. This method is also used |
ohair@286 | 646 | * to create protocol messages that are not associated with any {@link WSBinding} |
ohair@286 | 647 | * and {@link WSDLPort}. |
ohair@286 | 648 | * |
ohair@286 | 649 | * @param packet request packet |
ohair@286 | 650 | * @param av WS-Addressing version |
ohair@286 | 651 | * @param sv SOAP version |
ohair@286 | 652 | * @param oneway Indicates if the message exchange pattern is oneway |
ohair@286 | 653 | * @param action Action Message Addressing Property value |
ohair@286 | 654 | * @param mustUnderstand to indicate if the addressing headers are set with mustUnderstand attribute |
ohair@286 | 655 | */ |
ohair@286 | 656 | public void fillRequestAddressingHeaders(Packet packet, AddressingVersion av, SOAPVersion sv, boolean oneway, String action, boolean mustUnderstand) { |
ohair@286 | 657 | fillCommonAddressingHeaders(packet, av, sv, action, mustUnderstand); |
ohair@286 | 658 | |
ohair@286 | 659 | // wsa:ReplyTo |
ohair@286 | 660 | // null or "true" is equivalent to request/response MEP |
ohair@286 | 661 | if (!oneway) { |
ohair@286 | 662 | WSEndpointReference epr = av.anonymousEpr; |
ohair@286 | 663 | if (get(av.replyToTag, false) == null) { |
ohair@286 | 664 | add(epr.createHeader(av.replyToTag)); |
ohair@286 | 665 | } |
ohair@286 | 666 | |
ohair@286 | 667 | // wsa:FaultTo |
ohair@286 | 668 | if (get(av.faultToTag, false) == null) { |
ohair@286 | 669 | add(epr.createHeader(av.faultToTag)); |
ohair@286 | 670 | } |
ohair@286 | 671 | |
ohair@286 | 672 | // wsa:MessageID |
ohair@286 | 673 | if (packet.getMessage().getHeaders().get(av.messageIDTag, false) == null) { |
ohair@286 | 674 | if (get(av.messageIDTag, false) == null) { |
ohair@286 | 675 | Header h = new StringHeader(av.messageIDTag, Message.generateMessageID()); |
ohair@286 | 676 | add(h); |
ohair@286 | 677 | } |
ohair@286 | 678 | } |
ohair@286 | 679 | } |
ohair@286 | 680 | } |
ohair@286 | 681 | |
ohair@286 | 682 | public void fillRequestAddressingHeaders(Packet packet, AddressingVersion av, SOAPVersion sv, boolean oneway, String action) { |
ohair@286 | 683 | fillRequestAddressingHeaders(packet, av, sv, oneway, action, false); |
ohair@286 | 684 | } |
ohair@286 | 685 | |
ohair@286 | 686 | /** |
ohair@286 | 687 | * Creates a set of outbound WS-Addressing headers on the client with the |
ohair@286 | 688 | * default Action Message Addressing Property value. |
ohair@286 | 689 | * <p><p> |
ohair@286 | 690 | * This method needs to be invoked right after such a Message is |
ohair@286 | 691 | * created which is error prone but so far only MEX, RM and JAX-WS |
ohair@286 | 692 | * creates a request so this ugliness is acceptable. If more components |
ohair@286 | 693 | * are identified using this, then we may revisit this. |
ohair@286 | 694 | * <p><p> |
ohair@286 | 695 | * This method is used if default Action Message Addressing Property is to |
ohair@286 | 696 | * be used. See |
ohair@286 | 697 | * {@link #fillRequestAddressingHeaders(Packet, com.sun.xml.internal.ws.api.addressing.AddressingVersion, com.sun.xml.internal.ws.api.SOAPVersion, boolean, String)} |
ohair@286 | 698 | * if non-default Action is to be used, for example when creating a protocol message not |
ohair@286 | 699 | * associated with {@link WSBinding} and {@link WSDLPort}. |
ohair@286 | 700 | * This method uses SOAPAction as the Action unless set expplicitly in the wsdl. |
ohair@286 | 701 | * @param wsdlPort request WSDL port |
ohair@286 | 702 | * @param binding request WSBinding |
ohair@286 | 703 | * @param packet request packet |
ohair@286 | 704 | */ |
ohair@286 | 705 | public void fillRequestAddressingHeaders(WSDLPort wsdlPort, @NotNull WSBinding binding, Packet packet) { |
ohair@286 | 706 | if (binding == null) { |
ohair@286 | 707 | throw new IllegalArgumentException(AddressingMessages.NULL_BINDING()); |
ohair@286 | 708 | } |
ohair@286 | 709 | |
ohair@286 | 710 | if (binding.isFeatureEnabled(SuppressAutomaticWSARequestHeadersFeature.class)) |
ohair@286 | 711 | return; |
ohair@286 | 712 | |
ohair@286 | 713 | //See if WSA headers are already set by the user. |
ohair@286 | 714 | HeaderList hl = packet.getMessage().getHeaders(); |
ohair@286 | 715 | String action = hl.getAction(binding.getAddressingVersion(), binding.getSOAPVersion()); |
ohair@286 | 716 | if (action != null) { |
ohair@286 | 717 | //assume that all the WSA headers are set by the user |
ohair@286 | 718 | return; |
ohair@286 | 719 | } |
ohair@286 | 720 | AddressingVersion addressingVersion = binding.getAddressingVersion(); |
ohair@286 | 721 | //seiModel is passed as null as it is not needed. |
ohair@286 | 722 | WsaTubeHelper wsaHelper = addressingVersion.getWsaHelper(wsdlPort, null, binding); |
ohair@286 | 723 | |
ohair@286 | 724 | // wsa:Action |
ohair@286 | 725 | String effectiveInputAction = wsaHelper.getEffectiveInputAction(packet); |
ohair@286 | 726 | if (effectiveInputAction == null || effectiveInputAction.equals("") && binding.getSOAPVersion() == SOAPVersion.SOAP_11) { |
ohair@286 | 727 | throw new WebServiceException(ClientMessages.INVALID_SOAP_ACTION()); |
ohair@286 | 728 | } |
ohair@286 | 729 | boolean oneway = !packet.expectReply; |
ohair@286 | 730 | if (wsdlPort != null) { |
ohair@286 | 731 | // if WSDL has <wsaw:Anonymous>prohibited</wsaw:Anonymous>, then throw an error |
ohair@286 | 732 | // as anonymous ReplyTo MUST NOT be added in that case. BindingProvider need to |
ohair@286 | 733 | // disable AddressingFeature and MemberSubmissionAddressingFeature and hand-craft |
ohair@286 | 734 | // the SOAP message with non-anonymous ReplyTo/FaultTo. |
ohair@286 | 735 | if (!oneway && packet.getMessage() != null && packet.getWSDLOperation() != null) { |
ohair@286 | 736 | WSDLBoundOperation wbo = wsdlPort.getBinding().get(packet.getWSDLOperation()); |
ohair@286 | 737 | if (wbo != null && wbo.getAnonymous() == WSDLBoundOperation.ANONYMOUS.prohibited) { |
ohair@286 | 738 | throw new WebServiceException(AddressingMessages.WSAW_ANONYMOUS_PROHIBITED()); |
ohair@286 | 739 | } |
ohair@286 | 740 | } |
ohair@286 | 741 | } |
ohair@286 | 742 | if (!binding.isFeatureEnabled(OneWayFeature.class)) { |
ohair@286 | 743 | // standard oneway |
ohair@286 | 744 | fillRequestAddressingHeaders(packet, addressingVersion, binding.getSOAPVersion(), oneway, effectiveInputAction, addressingVersion.isRequired(binding)); |
ohair@286 | 745 | } else { |
ohair@286 | 746 | // custom oneway |
ohair@286 | 747 | fillRequestAddressingHeaders(packet, addressingVersion, binding.getSOAPVersion(), binding.getFeature(OneWayFeature.class), oneway, effectiveInputAction); |
ohair@286 | 748 | } |
ohair@286 | 749 | } |
ohair@286 | 750 | |
ohair@286 | 751 | private void fillRequestAddressingHeaders(@NotNull Packet packet, @NotNull AddressingVersion av, @NotNull SOAPVersion sv, @NotNull OneWayFeature of, boolean oneway, @NotNull String action) { |
ohair@286 | 752 | if (!oneway&&!of.isUseAsyncWithSyncInvoke() && Boolean.TRUE.equals(packet.isSynchronousMEP)) |
ohair@286 | 753 | fillRequestAddressingHeaders(packet, av, sv, oneway, action); |
ohair@286 | 754 | else { |
ohair@286 | 755 | fillCommonAddressingHeaders(packet, av, sv, action, false); |
ohair@286 | 756 | |
ohair@286 | 757 | // wsa:ReplyTo |
ohair@286 | 758 | // wsa:ReplyTo (add it if it doesn't already exist and OnewayFeature |
ohair@286 | 759 | // requests a specific ReplyTo) |
ohair@286 | 760 | if (get(av.replyToTag, false) == null) { |
ohair@286 | 761 | WSEndpointReference replyToEpr = of.getReplyTo(); |
ohair@286 | 762 | if (replyToEpr != null) { |
ohair@286 | 763 | add(replyToEpr.createHeader(av.replyToTag)); |
ohair@286 | 764 | // add wsa:MessageID only for non-null ReplyTo |
ohair@286 | 765 | if (packet.getMessage().getHeaders().get(av.messageIDTag, false) == null) { |
ohair@286 | 766 | // if header doesn't exist, method getID creates a new random id |
ohair@286 | 767 | String newID = Message.generateMessageID(); |
ohair@286 | 768 | add(new StringHeader(av.messageIDTag, newID)); |
ohair@286 | 769 | } |
ohair@286 | 770 | } |
ohair@286 | 771 | } |
ohair@286 | 772 | |
ohair@286 | 773 | // wsa:FaultTo |
ohair@286 | 774 | // wsa:FaultTo (add it if it doesn't already exist and OnewayFeature |
ohair@286 | 775 | // requests a specific FaultTo) |
ohair@286 | 776 | if (get(av.faultToTag, false) == null) { |
ohair@286 | 777 | WSEndpointReference faultToEpr = of.getFaultTo(); |
ohair@286 | 778 | if (faultToEpr != null) { |
ohair@286 | 779 | add(faultToEpr.createHeader(av.faultToTag)); |
ohair@286 | 780 | // add wsa:MessageID only for non-null FaultTo |
ohair@286 | 781 | if (get(av.messageIDTag, false) == null) { |
ohair@286 | 782 | add(new StringHeader(av.messageIDTag, Message.generateMessageID())); |
ohair@286 | 783 | } |
ohair@286 | 784 | } |
ohair@286 | 785 | } |
ohair@286 | 786 | |
ohair@286 | 787 | // wsa:From |
ohair@286 | 788 | if (of.getFrom() != null) { |
ohair@286 | 789 | addOrReplace(of.getFrom().createHeader(av.fromTag)); |
ohair@286 | 790 | } |
ohair@286 | 791 | |
ohair@286 | 792 | // wsa:RelatesTo |
ohair@286 | 793 | if (of.getRelatesToID() != null) { |
ohair@286 | 794 | addOrReplace(new RelatesToHeader(av.relatesToTag, of.getRelatesToID())); |
ohair@286 | 795 | } |
ohair@286 | 796 | } |
ohair@286 | 797 | } |
ohair@286 | 798 | |
ohair@286 | 799 | /** |
ohair@286 | 800 | * Creates wsa:To, wsa:Action and wsa:MessageID header on the client |
ohair@286 | 801 | * |
ohair@286 | 802 | * @param packet request packet |
ohair@286 | 803 | * @param av WS-Addressing version |
ohair@286 | 804 | * @param sv SOAP version |
ohair@286 | 805 | * @param action Action Message Addressing Property value |
ohair@286 | 806 | * @throws IllegalArgumentException if any of the parameters is null. |
ohair@286 | 807 | */ |
ohair@286 | 808 | private void fillCommonAddressingHeaders(Packet packet, @NotNull AddressingVersion av, @NotNull SOAPVersion sv, @NotNull String action, boolean mustUnderstand) { |
ohair@286 | 809 | if (packet == null) { |
ohair@286 | 810 | throw new IllegalArgumentException(AddressingMessages.NULL_PACKET()); |
ohair@286 | 811 | } |
ohair@286 | 812 | |
ohair@286 | 813 | if (av == null) { |
ohair@286 | 814 | throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION()); |
ohair@286 | 815 | } |
ohair@286 | 816 | |
ohair@286 | 817 | if (sv == null) { |
ohair@286 | 818 | throw new IllegalArgumentException(AddressingMessages.NULL_SOAP_VERSION()); |
ohair@286 | 819 | } |
ohair@286 | 820 | |
ohair@286 | 821 | if (action == null && !sv.httpBindingId.equals(SOAPBinding.SOAP12HTTP_BINDING)) { |
ohair@286 | 822 | throw new IllegalArgumentException(AddressingMessages.NULL_ACTION()); |
ohair@286 | 823 | } |
ohair@286 | 824 | |
ohair@286 | 825 | // wsa:To |
ohair@286 | 826 | if (get(av.toTag, false) == null) { |
ohair@286 | 827 | StringHeader h = new StringHeader(av.toTag, packet.endpointAddress.toString()); |
ohair@286 | 828 | add(h); |
ohair@286 | 829 | } |
ohair@286 | 830 | |
ohair@286 | 831 | // wsa:Action |
ohair@286 | 832 | if (action != null) { |
ohair@286 | 833 | packet.soapAction = action; |
ohair@286 | 834 | if (get(av.actionTag, false) == null) { |
ohair@286 | 835 | //As per WS-I BP 1.2/2.0, if one of the WSA headers is MU, then all WSA headers should be treated as MU., |
ohair@286 | 836 | // so just set MU on action header |
ohair@286 | 837 | StringHeader h = new StringHeader(av.actionTag, action, sv, mustUnderstand); |
ohair@286 | 838 | add(h); |
ohair@286 | 839 | } |
ohair@286 | 840 | } |
ohair@286 | 841 | } |
ohair@286 | 842 | |
ohair@286 | 843 | /** |
ohair@286 | 844 | * Adds a new {@link Header}. |
ohair@286 | 845 | * |
ohair@286 | 846 | * <p> |
ohair@286 | 847 | * Order doesn't matter in headers, so this method |
ohair@286 | 848 | * does not make any guarantee as to where the new header |
ohair@286 | 849 | * is inserted. |
ohair@286 | 850 | * |
ohair@286 | 851 | * @return |
ohair@286 | 852 | * always true. Don't use the return value. |
ohair@286 | 853 | */ |
ohair@286 | 854 | @Override |
ohair@286 | 855 | public boolean add(Header header) { |
ohair@286 | 856 | return super.add(header); |
ohair@286 | 857 | } |
ohair@286 | 858 | |
ohair@286 | 859 | /** |
ohair@286 | 860 | * Removes the first {@link Header} of the specified name. |
ohair@286 | 861 | * @param nsUri namespace URI of the header to remove |
ohair@286 | 862 | * @param localName local part of the FQN of the header to remove |
ohair@286 | 863 | * |
ohair@286 | 864 | * @return null if not found. |
ohair@286 | 865 | */ |
ohair@286 | 866 | public |
ohair@286 | 867 | @Nullable |
ohair@286 | 868 | Header remove(@NotNull String nsUri, @NotNull String localName) { |
ohair@286 | 869 | int len = size(); |
ohair@286 | 870 | for (int i = 0; i < len; i++) { |
ohair@286 | 871 | Header h = get(i); |
ohair@286 | 872 | if (h.getLocalPart().equals(localName) && h.getNamespaceURI().equals(nsUri)) { |
ohair@286 | 873 | return remove(i); |
ohair@286 | 874 | } |
ohair@286 | 875 | } |
ohair@286 | 876 | return null; |
ohair@286 | 877 | } |
ohair@286 | 878 | |
ohair@286 | 879 | /** |
ohair@286 | 880 | * Replaces an existing {@link Header} or adds a new {@link Header}. |
ohair@286 | 881 | * |
ohair@286 | 882 | * <p> |
ohair@286 | 883 | * Order doesn't matter in headers, so this method |
ohair@286 | 884 | * does not make any guarantee as to where the new header |
ohair@286 | 885 | * is inserted. |
ohair@286 | 886 | * |
ohair@286 | 887 | * @return |
ohair@286 | 888 | * always true. Don't use the return value. |
ohair@286 | 889 | */ |
ohair@286 | 890 | public boolean addOrReplace(Header header) { |
ohair@286 | 891 | for (int i=0; i < size(); i++) { |
ohair@286 | 892 | Header hdr = get(i); |
ohair@286 | 893 | if (hdr.getNamespaceURI().equals(header.getNamespaceURI()) && |
ohair@286 | 894 | hdr.getLocalPart().equals(header.getLocalPart())) { |
ohair@286 | 895 | // Put the new header in the old position. Call super versions |
ohair@286 | 896 | // internally to avoid UnsupportedOperationException |
ohair@286 | 897 | removeInternal(i); |
ohair@286 | 898 | addInternal(i, header); |
ohair@286 | 899 | return true; |
ohair@286 | 900 | } |
ohair@286 | 901 | } |
ohair@286 | 902 | return add(header); |
ohair@286 | 903 | } |
ohair@286 | 904 | |
ohair@286 | 905 | protected void addInternal(int index, Header header) { |
ohair@286 | 906 | super.add(index, header); |
ohair@286 | 907 | } |
ohair@286 | 908 | |
ohair@286 | 909 | protected Header removeInternal(int index) { |
ohair@286 | 910 | return super.remove(index); |
ohair@286 | 911 | } |
ohair@286 | 912 | |
ohair@286 | 913 | /** |
ohair@286 | 914 | * Removes the first {@link Header} of the specified name. |
ohair@286 | 915 | * |
ohair@286 | 916 | * @param name fully qualified name of the header to remove |
ohair@286 | 917 | * |
ohair@286 | 918 | * @return null if not found. |
ohair@286 | 919 | */ |
ohair@286 | 920 | public |
ohair@286 | 921 | @Nullable |
ohair@286 | 922 | Header remove(@NotNull QName name) { |
ohair@286 | 923 | return remove(name.getNamespaceURI(), name.getLocalPart()); |
ohair@286 | 924 | } |
ohair@286 | 925 | |
ohair@286 | 926 | /** |
ohair@286 | 927 | * Removes the first {@link Header} of the specified name. |
ohair@286 | 928 | * |
ohair@286 | 929 | * @param index index of the header to remove |
ohair@286 | 930 | * |
ohair@286 | 931 | * @return removed header |
ohair@286 | 932 | */ |
ohair@286 | 933 | @Override |
ohair@286 | 934 | public Header remove(int index) { |
ohair@286 | 935 | removeUnderstoodBit(index); |
ohair@286 | 936 | return super.remove(index); |
ohair@286 | 937 | } |
ohair@286 | 938 | |
ohair@286 | 939 | /** |
ohair@286 | 940 | * Removes the "understood" bit for header on the position specified by {@code index} parameter |
ohair@286 | 941 | * from the set of understood header bits. |
ohair@286 | 942 | * |
ohair@286 | 943 | * @param index position of the bit to remove |
ohair@286 | 944 | */ |
ohair@286 | 945 | private void removeUnderstoodBit(int index) { |
ohair@286 | 946 | assert index < size(); |
ohair@286 | 947 | |
ohair@286 | 948 | if (index < 32) { |
ohair@286 | 949 | /** |
ohair@286 | 950 | * Let |
ohair@286 | 951 | * R be the bit to be removed |
ohair@286 | 952 | * M be a more significant "upper" bit than bit R |
ohair@286 | 953 | * L be a less significant "lower" bit than bit R |
ohair@286 | 954 | * |
ohair@286 | 955 | * Then following 3 lines of code produce these results: |
ohair@286 | 956 | * |
ohair@286 | 957 | * old understoodBits = MMMMMMMMMMMMRLLLLLLLLLLLLLLLLLLL |
ohair@286 | 958 | * |
ohair@286 | 959 | * shiftedUpperBits = 0MMMMMMMMMMMM0000000000000000000 |
ohair@286 | 960 | * |
ohair@286 | 961 | * lowerBits = 0000000000000LLLLLLLLLLLLLLLLLLL |
ohair@286 | 962 | * |
ohair@286 | 963 | * new understoodBits = 0MMMMMMMMMMMMLLLLLLLLLLLLLLLLLLL |
ohair@286 | 964 | * |
ohair@286 | 965 | * The R bit is removed and all the upper bits are shifted right (unsigned) |
ohair@286 | 966 | */ |
ohair@286 | 967 | int shiftedUpperBits = understoodBits >>> -31 + index << index; |
ohair@286 | 968 | int lowerBits = understoodBits << -index >>> 31 - index >>> 1; |
ohair@286 | 969 | understoodBits = shiftedUpperBits | lowerBits; |
ohair@286 | 970 | |
ohair@286 | 971 | if (moreUnderstoodBits != null && moreUnderstoodBits.cardinality() > 0) { |
ohair@286 | 972 | if (moreUnderstoodBits.get(0)) { |
ohair@286 | 973 | understoodBits |= 0x80000000; |
ohair@286 | 974 | } |
ohair@286 | 975 | |
ohair@286 | 976 | moreUnderstoodBits.clear(0); |
ohair@286 | 977 | for (int i = moreUnderstoodBits.nextSetBit(1); i > 0; i = moreUnderstoodBits.nextSetBit(i + 1)) { |
ohair@286 | 978 | moreUnderstoodBits.set(i - 1); |
ohair@286 | 979 | moreUnderstoodBits.clear(i); |
ohair@286 | 980 | } |
ohair@286 | 981 | } |
ohair@286 | 982 | } else if (moreUnderstoodBits != null && moreUnderstoodBits.cardinality() > 0) { |
ohair@286 | 983 | index -= 32; |
ohair@286 | 984 | moreUnderstoodBits.clear(index); |
ohair@286 | 985 | for (int i = moreUnderstoodBits.nextSetBit(index); i >= 1; i = moreUnderstoodBits.nextSetBit(i + 1)) { |
ohair@286 | 986 | moreUnderstoodBits.set(i - 1); |
ohair@286 | 987 | moreUnderstoodBits.clear(i); |
ohair@286 | 988 | } |
ohair@286 | 989 | } |
ohair@286 | 990 | |
ohair@286 | 991 | // remove bit set if the new size will be < 33 => we fit all bits into int |
ohair@286 | 992 | if (size() - 1 <= 33 && moreUnderstoodBits != null) { |
ohair@286 | 993 | moreUnderstoodBits = null; |
ohair@286 | 994 | } |
ohair@286 | 995 | } |
ohair@286 | 996 | |
ohair@286 | 997 | /** |
ohair@286 | 998 | * Removes a single instance of the specified element from this |
ohair@286 | 999 | * header list, if it is present. More formally, |
ohair@286 | 1000 | * removes a header <tt>h</tt> such that <tt>(o==null ? h==null : |
ohair@286 | 1001 | * o.equals(h))</tt>, if the header list contains one or more such |
ohair@286 | 1002 | * headers. Returns <tt>true</tt> if the list contained the |
ohair@286 | 1003 | * specified element (or equivalently, if the list changed as a |
ohair@286 | 1004 | * result of the call).<p> |
ohair@286 | 1005 | * |
ohair@286 | 1006 | * @param o element to be removed from this list, if present. |
ohair@286 | 1007 | * @return <tt>true</tt> if the list contained the specified element. |
ohair@286 | 1008 | * @see #remove(javax.xml.namespace.QName) |
ohair@286 | 1009 | */ |
ohair@286 | 1010 | @Override |
ohair@286 | 1011 | public boolean remove(Object o) { |
ohair@286 | 1012 | if (o != null) { |
ohair@286 | 1013 | for (int index = 0; index < this.size(); index++) |
ohair@286 | 1014 | if (o.equals(this.get(index))) { |
ohair@286 | 1015 | remove(index); |
ohair@286 | 1016 | return true; |
ohair@286 | 1017 | } |
ohair@286 | 1018 | } |
ohair@286 | 1019 | |
ohair@286 | 1020 | return false; |
ohair@286 | 1021 | } |
ohair@286 | 1022 | |
ohair@286 | 1023 | /** |
ohair@286 | 1024 | * Creates a copy. |
ohair@286 | 1025 | * |
ohair@286 | 1026 | * This handles null {@link HeaderList} correctly. |
ohair@286 | 1027 | * |
ohair@286 | 1028 | * @param original |
ohair@286 | 1029 | * Can be null, in which case null will be returned. |
ohair@286 | 1030 | */ |
ohair@286 | 1031 | public static HeaderList copy(HeaderList original) { |
ohair@286 | 1032 | if (original == null) { |
ohair@286 | 1033 | return null; |
ohair@286 | 1034 | } else { |
ohair@286 | 1035 | return new HeaderList(original); |
ohair@286 | 1036 | } |
ohair@286 | 1037 | } |
ohair@286 | 1038 | |
ohair@286 | 1039 | public void readResponseAddressingHeaders(WSDLPort wsdlPort, WSBinding binding) { |
ohair@286 | 1040 | // read Action |
ohair@286 | 1041 | String wsaAction = getAction(binding.getAddressingVersion(), binding.getSOAPVersion()); |
ohair@286 | 1042 | // TODO: validate client-inbound Action |
ohair@286 | 1043 | } |
ohair@286 | 1044 | } |