325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.api.message;
325N/A
325N/Aimport com.sun.istack.internal.NotNull;
325N/Aimport com.sun.istack.internal.Nullable;
325N/Aimport com.sun.xml.internal.ws.addressing.WsaTubeHelper;
325N/Aimport com.sun.xml.internal.ws.api.SOAPVersion;
325N/Aimport com.sun.xml.internal.ws.api.WSBinding;
325N/Aimport com.sun.xml.internal.ws.api.addressing.AddressingVersion;
325N/Aimport com.sun.xml.internal.ws.api.addressing.OneWayFeature;
325N/Aimport com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
325N/Aimport com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
325N/Aimport com.sun.xml.internal.ws.api.pipe.Pipe;
325N/Aimport com.sun.xml.internal.ws.api.pipe.Codec;
325N/Aimport com.sun.xml.internal.ws.message.RelatesToHeader;
325N/Aimport com.sun.xml.internal.ws.message.StringHeader;
325N/Aimport com.sun.xml.internal.ws.protocol.soap.ClientMUTube;
325N/Aimport com.sun.xml.internal.ws.protocol.soap.ServerMUTube;
325N/Aimport com.sun.xml.internal.ws.resources.AddressingMessages;
325N/Aimport com.sun.xml.internal.ws.resources.ClientMessages;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/Aimport javax.xml.stream.XMLStreamException;
325N/Aimport javax.xml.ws.WebServiceException;
325N/Aimport javax.xml.ws.soap.AddressingFeature;
325N/Aimport java.util.ArrayList;
325N/Aimport java.util.BitSet;
325N/Aimport java.util.Iterator;
325N/Aimport java.util.NoSuchElementException;
325N/A
325N/A/**
325N/A * A list of {@link Header}s on a {@link Message}.
325N/A *
325N/A * <p>
325N/A * This list can be modified to add headers
325N/A * from outside a {@link Message}, this is necessary
325N/A * since intermediate processing layers often need to
325N/A * put additional headers.
325N/A *
325N/A * <p>
325N/A * Following the SOAP convention, the order among headers
325N/A * are not significant. However, {@link Codec}s are
325N/A * expected to preserve the order of headers in the input
325N/A * message as much as possible.
325N/A *
325N/A *
325N/A * <a name="MU"></a>
325N/A * <h3>MustUnderstand Processing</h3>
325N/A * <p>
325N/A * To perform SOAP mustUnderstang processing correctly, we need to keep
325N/A * track of headers that are understood and headers that are not.
325N/A * This is a collaborative process among {@link Pipe}s, thus it's something
325N/A * a {@link Pipe} author needs to keep in mind.
325N/A *
325N/A * <p>
325N/A * Specifically, when a {@link Pipe} sees a header and processes it
325N/A * (that is, if it did enough computing with the header to claim that
325N/A * the header is understood), then it should mark the corresponding
325N/A * header as "understood". For example, when a pipe that handles JAX-WSA
325N/A * examins the &lt;wsa:To> header, it can claim that it understood the header.
325N/A * But for example, if a pipe that does the signature verification checks
325N/A * &lt;wsa:To> for a signature, that would not be considered as "understood".
325N/A *
325N/A * <p>
325N/A * There are two ways to mark a header as understood:
325N/A *
325N/A * <ol>
325N/A * <li>Use one of the <tt>getXXX</tt> methods that take a
325N/A * boolean <tt>markAsUnderstood</tt> parameter.
325N/A * Most often, a {@link Pipe} knows it's going to understand a header
325N/A * as long as it's present, so this is the easiest and thus the preferred way.
325N/A *
325N/A * For example, if JAX-WSA looks for &lt;wsa:To>, then it can set
325N/A * <tt>markAsUnderstand</tt> to true, to do the obtaining of a header
325N/A * and marking at the same time.
325N/A *
325N/A * <li>Call {@link #understood(int)}.
325N/A * If under a rare circumstance, a pipe cannot determine whether
325N/A * it can understand it or not when you are fetching a header, then
325N/A * you can use this method afterward to mark it as understood.
325N/A * </ol>
325N/A *
325N/A * <p>
325N/A * Intuitively speaking, at the end of the day, if a header is not
325N/A * understood but {@link Header#isIgnorable(SOAPVersion, java.util.Set)} is false, a bad thing
325N/A * will happen. The actual implementation of the checking is more complicated,
325N/A * for that see {@link ClientMUTube}/{@link ServerMUTube}.
325N/A *
325N/A * @see Message#getHeaders()
325N/A */
325N/Apublic final class HeaderList extends ArrayList<Header> {
325N/A
325N/A private static final long serialVersionUID = -6358045781349627237L;
325N/A /**
325N/A * Bit set to keep track of which headers are understood.
325N/A * <p>
325N/A * The first 32 headers use this field, and the rest will use
325N/A * {@link #moreUnderstoodBits}. The expectation is that
325N/A * most of the time a SOAP message will only have up to 32 headers,
325N/A * so we can avoid allocating separate objects for {@link BitSet}.
325N/A */
325N/A private int understoodBits;
325N/A /**
325N/A * If there are more than 32 headers, we use this {@link BitSet}
325N/A * to keep track of whether those headers are understood.
325N/A * Lazily allocated.
325N/A */
325N/A private BitSet moreUnderstoodBits = null;
325N/A private String to = null;
325N/A private String action = null;
325N/A private WSEndpointReference replyTo = null;
325N/A private WSEndpointReference faultTo = null;
325N/A private String messageId;
325N/A private String relatesTo;
325N/A
325N/A /**
325N/A * Creates an empty {@link HeaderList}.
325N/A */
325N/A public HeaderList() {
325N/A }
325N/A
325N/A /**
325N/A * Copy constructor.
325N/A */
325N/A public HeaderList(HeaderList that) {
325N/A super(that);
325N/A this.understoodBits = that.understoodBits;
325N/A if (that.moreUnderstoodBits != null) {
325N/A this.moreUnderstoodBits = (BitSet) that.moreUnderstoodBits.clone();
325N/A }
325N/A this.to = that.to;
325N/A this.action = that.action;
325N/A this.replyTo = that.replyTo;
325N/A this.faultTo = that.faultTo;
325N/A this.messageId = that.messageId;
325N/A }
325N/A
325N/A /**
325N/A * The total number of headers.
325N/A */
325N/A @Override
325N/A public int size() {
325N/A return super.size();
325N/A }
325N/A
325N/A /**
325N/A * Adds all the headers.
325N/A */
325N/A public void addAll(Header... headers) {
325N/A for (Header header : headers) {
325N/A add(header);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Gets the {@link Header} at the specified index.
325N/A *
325N/A * <p>
325N/A * This method does not mark the returned {@link Header} as understood.
325N/A *
325N/A * @see #understood(int)
325N/A */
325N/A @Override
325N/A public Header get(int index) {
325N/A return super.get(index);
325N/A }
325N/A
325N/A /**
325N/A * Marks the {@link Header} at the specified index as
325N/A * <a href="#MU">"understood"</a>.
325N/A */
325N/A public void understood(int index) {
325N/A // check that index is in range
325N/A if (index >= size()) {
325N/A throw new ArrayIndexOutOfBoundsException(index);
325N/A }
325N/A
325N/A if (index < 32) {
325N/A understoodBits |= 1 << index;
325N/A } else {
325N/A if (moreUnderstoodBits == null) {
325N/A moreUnderstoodBits = new BitSet();
325N/A }
325N/A moreUnderstoodBits.set(index - 32);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Returns true if a {@link Header} at the given index
325N/A * was <a href="#MU">"understood"</a>.
325N/A */
325N/A public boolean isUnderstood(int index) {
325N/A // check that index is in range
325N/A if (index >= size()) {
325N/A throw new ArrayIndexOutOfBoundsException(index);
325N/A }
325N/A
325N/A if (index < 32) {
325N/A return understoodBits == (understoodBits | (1 << index));
325N/A } else {
325N/A if (moreUnderstoodBits == null) {
325N/A return false;
325N/A }
325N/A return moreUnderstoodBits.get(index - 32);
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Marks the specified {@link Header} as <a href="#MU">"understood"</a>.
325N/A *
325N/A * @deprecated
325N/A * By the definition of {@link ArrayList}, this operation requires
325N/A * O(n) search of the array, and thus inherently inefficient.
325N/A *
325N/A * Because of this, if you are developing a {@link Pipe} for
325N/A * a performance sensitive environment, do not use this method.
325N/A *
325N/A * @throws IllegalArgumentException
325N/A * if the given header is not {@link #contains(Object) contained}
325N/A * in this header.
325N/A */
325N/A public void understood(@NotNull Header header) {
325N/A int sz = size();
325N/A for (int i = 0; i < sz; i++) {
325N/A if (get(i) == header) {
325N/A understood(i);
325N/A return;
325N/A }
325N/A }
325N/A throw new IllegalArgumentException();
325N/A }
325N/A
325N/A /**
325N/A * Gets the first {@link Header} of the specified name.
325N/A *
325N/A * @param markAsUnderstood
325N/A * If this parameter is true, the returned header will
325N/A * be marked as <a href="#MU">"understood"</a>.
325N/A * @return null if not found.
325N/A */
325N/A public
325N/A @Nullable
325N/A Header get(@NotNull String nsUri, @NotNull String localName, boolean markAsUnderstood) {
325N/A int len = size();
325N/A for (int i = 0; i < len; i++) {
325N/A Header h = get(i);
325N/A if (h.getLocalPart().equals(localName) && h.getNamespaceURI().equals(nsUri)) {
325N/A if (markAsUnderstood) {
325N/A understood(i);
325N/A }
325N/A return h;
325N/A }
325N/A }
325N/A return null;
325N/A }
325N/A
325N/A /**
325N/A * @deprecated
325N/A * Use {@link #get(String, String, boolean)}
325N/A */
325N/A public Header get(String nsUri, String localName) {
325N/A return get(nsUri, localName, true);
325N/A }
325N/A
325N/A /**
325N/A * Gets the first {@link Header} of the specified name.
325N/A *
325N/A * @param markAsUnderstood
325N/A * If this parameter is true, the returned header will
325N/A * be marked as <a href="#MU">"understood"</a>.
325N/A * @return null
325N/A * if not found.
325N/A */
325N/A public
325N/A @Nullable
325N/A Header get(@NotNull QName name, boolean markAsUnderstood) {
325N/A return get(name.getNamespaceURI(), name.getLocalPart(), markAsUnderstood);
325N/A }
325N/A
325N/A /**
325N/A * @deprecated
325N/A * Use {@link #get(QName)}
325N/A */
325N/A public
325N/A @Nullable
325N/A Header get(@NotNull QName name) {
325N/A return get(name, true);
325N/A }
325N/A
325N/A /**
325N/A * @deprecated
325N/A * Use {@link #getHeaders(String, String, boolean)}
325N/A */
325N/A public Iterator<Header> getHeaders(final String nsUri, final String localName) {
325N/A return getHeaders(nsUri, localName, true);
325N/A }
325N/A
325N/A /**
325N/A * Gets all the {@link Header}s of the specified name,
325N/A * including duplicates (if any.)
325N/A *
325N/A * @param markAsUnderstood
325N/A * If this parameter is true, the returned headers will
325N/A * be marked as <a href="#MU">"understood"</a> when they are returned
325N/A * from {@link Iterator#next()}.
325N/A * @return empty iterator if not found.
325N/A */
325N/A public
325N/A @NotNull
325N/A Iterator<Header> getHeaders(@NotNull final String nsUri, @NotNull final String localName, final boolean markAsUnderstood) {
325N/A return new Iterator<Header>() {
325N/A
325N/A int idx = 0;
325N/A Header next;
325N/A
325N/A public boolean hasNext() {
325N/A if (next == null) {
325N/A fetch();
325N/A }
325N/A return next != null;
325N/A }
325N/A
325N/A public Header next() {
325N/A if (next == null) {
325N/A fetch();
325N/A if (next == null) {
325N/A throw new NoSuchElementException();
325N/A }
325N/A }
325N/A
325N/A if (markAsUnderstood) {
325N/A assert get(idx - 1) == next;
325N/A understood(idx - 1);
325N/A }
325N/A
325N/A Header r = next;
325N/A next = null;
325N/A return r;
325N/A }
325N/A
325N/A private void fetch() {
325N/A while (idx < size()) {
325N/A Header h = get(idx++);
325N/A if (h.getLocalPart().equals(localName) && h.getNamespaceURI().equals(nsUri)) {
325N/A next = h;
325N/A break;
325N/A }
325N/A }
325N/A }
325N/A
325N/A public void remove() {
325N/A throw new UnsupportedOperationException();
325N/A }
325N/A };
325N/A }
325N/A
325N/A /**
325N/A * @see #getHeaders(String, String, boolean)
325N/A */
325N/A public
325N/A @NotNull
325N/A Iterator<Header> getHeaders(@NotNull QName headerName, final boolean markAsUnderstood) {
325N/A return getHeaders(headerName.getNamespaceURI(), headerName.getLocalPart(), markAsUnderstood);
325N/A }
325N/A
325N/A /**
325N/A * @deprecated
325N/A * use {@link #getHeaders(String, boolean)}.
325N/A */
325N/A public
325N/A @NotNull
325N/A Iterator<Header> getHeaders(@NotNull final String nsUri) {
325N/A return getHeaders(nsUri, true);
325N/A }
325N/A
325N/A /**
325N/A * Gets an iteration of headers {@link Header} in the specified namespace,
325N/A * including duplicates (if any.)
325N/A *
325N/A * @param markAsUnderstood
325N/A * If this parameter is true, the returned headers will
325N/A * be marked as <a href="#MU">"understood"</a> when they are returned
325N/A * from {@link Iterator#next()}.
325N/A * @return
325N/A * empty iterator if not found.
325N/A */
325N/A public
325N/A @NotNull
325N/A Iterator<Header> getHeaders(@NotNull final String nsUri, final boolean markAsUnderstood) {
325N/A return new Iterator<Header>() {
325N/A
325N/A int idx = 0;
325N/A Header next;
325N/A
325N/A public boolean hasNext() {
325N/A if (next == null) {
325N/A fetch();
325N/A }
325N/A return next != null;
325N/A }
325N/A
325N/A public Header next() {
325N/A if (next == null) {
325N/A fetch();
325N/A if (next == null) {
325N/A throw new NoSuchElementException();
325N/A }
325N/A }
325N/A
325N/A if (markAsUnderstood) {
325N/A assert get(idx - 1) == next;
325N/A understood(idx - 1);
325N/A }
325N/A
325N/A Header r = next;
325N/A next = null;
325N/A return r;
325N/A }
325N/A
325N/A private void fetch() {
325N/A while (idx < size()) {
325N/A Header h = get(idx++);
325N/A if (h.getNamespaceURI().equals(nsUri)) {
325N/A next = h;
325N/A break;
325N/A }
325N/A }
325N/A }
325N/A
325N/A public void remove() {
325N/A throw new UnsupportedOperationException();
325N/A }
325N/A };
325N/A }
325N/A
325N/A /**
325N/A * Gets the first {@link Header} of the specified name targeted at the
325N/A * current implicit role.
325N/A *
325N/A * @param name name of the header
325N/A * @param markUnderstood
325N/A * If this parameter is true, the returned headers will
325N/A * be marked as <a href="#MU">"understood"</a> when they are returned
325N/A * from {@link Iterator#next()}.
325N/A * @return null if header not found
325N/A */
325N/A private Header getFirstHeader(QName name, boolean markUnderstood, SOAPVersion sv) {
325N/A if (sv == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_SOAP_VERSION());
325N/A }
325N/A
325N/A Iterator<Header> iter = getHeaders(name.getNamespaceURI(), name.getLocalPart(), markUnderstood);
325N/A while (iter.hasNext()) {
325N/A Header h = iter.next();
325N/A if (h.getRole(sv).equals(sv.implicitRole)) {
325N/A return h;
325N/A }
325N/A }
325N/A
325N/A return null;
325N/A }
325N/A
325N/A /**
325N/A * Returns the value of WS-Addressing <code>To</code> header. The <code>version</code>
325N/A * identifies the WS-Addressing version and the header returned is targeted at
325N/A * the current implicit role. Caches the value for subsequent invocation.
325N/A * Duplicate <code>To</code> headers are detected earlier.
325N/A *
325N/A * @param av WS-Addressing version
325N/A * @param sv SOAP version
325N/A * @throws IllegalArgumentException if either <code>av</code> or <code>sv</code> is null.
325N/A * @return Value of WS-Addressing To header, anonymous URI if no header is present
325N/A */
325N/A public String getTo(AddressingVersion av, SOAPVersion sv) {
325N/A if (to != null) {
325N/A return to;
325N/A }
325N/A if (av == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
325N/A }
325N/A
325N/A Header h = getFirstHeader(av.toTag, true, sv);
325N/A if (h != null) {
325N/A to = h.getStringContent();
325N/A } else {
325N/A to = av.anonymousUri;
325N/A }
325N/A
325N/A return to;
325N/A }
325N/A
325N/A /**
325N/A * Returns the value of WS-Addressing <code>Action</code> header. The <code>version</code>
325N/A * identifies the WS-Addressing version and the header returned is targeted at
325N/A * the current implicit role. Caches the value for subsequent invocation.
325N/A * Duplicate <code>Action</code> headers are detected earlier.
325N/A *
325N/A * @param av WS-Addressing version
325N/A * @param sv SOAP version
325N/A * @throws IllegalArgumentException if either <code>av</code> or <code>sv</code> is null.
325N/A * @return Value of WS-Addressing Action header, null if no header is present
325N/A */
325N/A public String getAction(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) {
325N/A if (action != null) {
325N/A return action;
325N/A }
325N/A if (av == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
325N/A }
325N/A
325N/A Header h = getFirstHeader(av.actionTag, true, sv);
325N/A if (h != null) {
325N/A action = h.getStringContent();
325N/A }
325N/A
325N/A return action;
325N/A }
325N/A
325N/A /**
325N/A * Returns the value of WS-Addressing <code>ReplyTo</code> header. The <code>version</code>
325N/A * identifies the WS-Addressing version and the header returned is targeted at
325N/A * the current implicit role. Caches the value for subsequent invocation.
325N/A * Duplicate <code>ReplyTo</code> headers are detected earlier.
325N/A *
325N/A * @param av WS-Addressing version
325N/A * @param sv SOAP version
325N/A * @throws IllegalArgumentException if either <code>av</code> or <code>sv</code> is null.
325N/A * @return Value of WS-Addressing ReplyTo header, null if no header is present
325N/A */
325N/A public WSEndpointReference getReplyTo(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) {
325N/A if (replyTo != null) {
325N/A return replyTo;
325N/A }
325N/A if (av == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
325N/A }
325N/A
325N/A Header h = getFirstHeader(av.replyToTag, true, sv);
325N/A if (h != null) {
325N/A try {
325N/A replyTo = h.readAsEPR(av);
325N/A } catch (XMLStreamException e) {
325N/A throw new WebServiceException(AddressingMessages.REPLY_TO_CANNOT_PARSE(), e);
325N/A }
325N/A } else {
325N/A replyTo = av.anonymousEpr;
325N/A }
325N/A
325N/A return replyTo;
325N/A }
325N/A
325N/A /**
325N/A * Returns the value of WS-Addressing <code>FaultTo</code> header. The <code>version</code>
325N/A * identifies the WS-Addressing version and the header returned is targeted at
325N/A * the current implicit role. Caches the value for subsequent invocation.
325N/A * Duplicate <code>FaultTo</code> headers are detected earlier.
325N/A *
325N/A * @param av WS-Addressing version
325N/A * @param sv SOAP version
325N/A * @throws IllegalArgumentException if either <code>av</code> or <code>sv</code> is null.
325N/A * @return Value of WS-Addressing FaultTo header, null if no header is present
325N/A */
325N/A public WSEndpointReference getFaultTo(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) {
325N/A if (faultTo != null) {
325N/A return faultTo;
325N/A }
325N/A
325N/A if (av == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
325N/A }
325N/A
325N/A Header h = getFirstHeader(av.faultToTag, true, sv);
325N/A if (h != null) {
325N/A try {
325N/A faultTo = h.readAsEPR(av);
325N/A } catch (XMLStreamException e) {
325N/A throw new WebServiceException(AddressingMessages.FAULT_TO_CANNOT_PARSE(), e);
325N/A }
325N/A }
325N/A
325N/A return faultTo;
325N/A }
325N/A
325N/A /**
325N/A * Returns the value of WS-Addressing <code>MessageID</code> header. The <code>version</code>
325N/A * identifies the WS-Addressing version and the header returned is targeted at
325N/A * the current implicit role. Caches the value for subsequent invocation.
325N/A * Duplicate <code>MessageID</code> headers are detected earlier.
325N/A *
325N/A * @param av WS-Addressing version
325N/A * @param sv SOAP version
325N/A * @throws WebServiceException if either <code>av</code> or <code>sv</code> is null.
325N/A * @return Value of WS-Addressing MessageID header, null if no header is present
325N/A */
325N/A public String getMessageID(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) {
325N/A if (messageId != null) {
325N/A return messageId;
325N/A }
325N/A
325N/A if (av == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
325N/A }
325N/A
325N/A Header h = getFirstHeader(av.messageIDTag, true, sv);
325N/A if (h != null) {
325N/A messageId = h.getStringContent();
325N/A }
325N/A
325N/A return messageId;
325N/A }
325N/A
325N/A /**
325N/A * Returns the value of WS-Addressing <code>RelatesTo</code> header. The <code>version</code>
325N/A * identifies the WS-Addressing version and the header returned is targeted at
325N/A * the current implicit role. Caches the value for subsequent invocation.
325N/A * Duplicate <code>RelatesTo</code> headers are detected earlier.
325N/A *
325N/A * @param av WS-Addressing version
325N/A * @param sv SOAP version
325N/A * @throws WebServiceException if either <code>av</code> or <code>sv</code> is null.
325N/A * @return Value of WS-Addressing RelatesTo header, null if no header is present
325N/A */
325N/A public String getRelatesTo(@NotNull AddressingVersion av, @NotNull SOAPVersion sv) {
325N/A if (relatesTo != null) {
325N/A return relatesTo;
325N/A }
325N/A
325N/A if (av == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
325N/A }
325N/A
325N/A Header h = getFirstHeader(av.relatesToTag, true, sv);
325N/A if (h != null) {
325N/A relatesTo = h.getStringContent();
325N/A }
325N/A
325N/A return relatesTo;
325N/A }
325N/A
325N/A /**
325N/A * Creates a set of outbound WS-Addressing headers on the client with the
325N/A * specified Action Message Addressing Property value.
325N/A * <p><p>
325N/A * This method needs to be invoked right after such a Message is
325N/A * created which is error prone but so far only MEX, RM and JAX-WS
325N/A * creates a request so this ugliness is acceptable. This method is also used
325N/A * to create protocol messages that are not associated with any {@link WSBinding}
325N/A * and {@link WSDLPort}.
325N/A *
325N/A * @param packet request packet
325N/A * @param av WS-Addressing version
325N/A * @param sv SOAP version
325N/A * @param oneway Indicates if the message exchange pattern is oneway
325N/A * @param action Action Message Addressing Property value
325N/A * @param mustUnderstand to indicate if the addressing headers are set with mustUnderstand attribute
325N/A */
325N/A public void fillRequestAddressingHeaders(Packet packet, AddressingVersion av, SOAPVersion sv, boolean oneway, String action, boolean mustUnderstand) {
325N/A fillCommonAddressingHeaders(packet, av, sv, action, mustUnderstand);
325N/A
325N/A // wsa:ReplyTo
325N/A // null or "true" is equivalent to request/response MEP
325N/A if (!oneway) {
325N/A WSEndpointReference epr = av.anonymousEpr;
325N/A add(epr.createHeader(av.replyToTag));
325N/A
325N/A // wsa:MessageID
325N/A Header h = new StringHeader(av.messageIDTag, packet.getMessage().getID(av, sv));
325N/A add(h);
325N/A }
325N/A }
325N/A
325N/A public void fillRequestAddressingHeaders(Packet packet, AddressingVersion av, SOAPVersion sv, boolean oneway, String action) {
325N/A fillRequestAddressingHeaders(packet,av,sv,oneway,action,false);
325N/A }
325N/A
325N/A /**
325N/A * Creates a set of outbound WS-Addressing headers on the client with the
325N/A * default Action Message Addressing Property value.
325N/A * <p><p>
325N/A * This method needs to be invoked right after such a Message is
325N/A * created which is error prone but so far only MEX, RM and JAX-WS
325N/A * creates a request so this ugliness is acceptable. If more components
325N/A * are identified using this, then we may revisit this.
325N/A * <p><p>
325N/A * This method is used if default Action Message Addressing Property is to
325N/A * be used. See
325N/A * {@link #fillRequestAddressingHeaders(Packet, com.sun.xml.internal.ws.api.addressing.AddressingVersion, com.sun.xml.internal.ws.api.SOAPVersion, boolean, String)}
325N/A * if non-default Action is to be used, for example when creating a protocol message not
325N/A * associated with {@link WSBinding} and {@link WSDLPort}.
325N/A * This method uses SOAPAction as the Action unless set expplicitly in the wsdl.
325N/A * @param wsdlPort request WSDL port
325N/A * @param binding request WSBinding
325N/A * @param packet request packet
325N/A */
325N/A public void fillRequestAddressingHeaders(WSDLPort wsdlPort, @NotNull WSBinding binding, Packet packet) {
325N/A if (binding == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_BINDING());
325N/A }
325N/A //See if WSA headers are already set by the user.
325N/A HeaderList hl = packet.getMessage().getHeaders();
325N/A String action = hl.getAction(binding.getAddressingVersion(), binding.getSOAPVersion());
325N/A if(action != null) {
325N/A //assume that all the WSA headers are set by the user
325N/A return;
325N/A }
325N/A AddressingVersion addressingVersion = binding.getAddressingVersion();
325N/A //seiModel is passed as null as it is not needed.
325N/A WsaTubeHelper wsaHelper = addressingVersion.getWsaHelper(wsdlPort, null, binding);
325N/A
325N/A // wsa:Action
325N/A String effectiveInputAction = wsaHelper.getEffectiveInputAction(packet);
325N/A if (effectiveInputAction == null || effectiveInputAction.equals("")) {
325N/A throw new WebServiceException(ClientMessages.INVALID_SOAP_ACTION());
325N/A }
325N/A boolean oneway = !packet.expectReply;
325N/A if (wsdlPort != null) {
325N/A // if WSDL has <wsaw:Anonymous>prohibited</wsaw:Anonymous>, then throw an error
325N/A // as anonymous ReplyTo MUST NOT be added in that case. BindingProvider need to
325N/A // disable AddressingFeature and MemberSubmissionAddressingFeature and hand-craft
325N/A // the SOAP message with non-anonymous ReplyTo/FaultTo.
325N/A if (!oneway && packet.getMessage() != null)
325N/A {
325N/A WSDLBoundOperation wbo = wsdlPort.getBinding().get(packet.getWSDLOperation());
325N/A if (wbo != null && wbo.getAnonymous() == WSDLBoundOperation.ANONYMOUS.prohibited) {
325N/A throw new WebServiceException(AddressingMessages.WSAW_ANONYMOUS_PROHIBITED());
325N/A }
325N/A }
325N/A }
325N/A if (!binding.isFeatureEnabled(OneWayFeature.class)) {
325N/A // standard oneway
325N/A fillRequestAddressingHeaders(packet, addressingVersion, binding.getSOAPVersion(), oneway, effectiveInputAction,addressingVersion.isRequired(binding));
325N/A } else {
325N/A // custom oneway
325N/A fillRequestAddressingHeaders(packet, addressingVersion, binding.getSOAPVersion(), binding.getFeature(OneWayFeature.class), effectiveInputAction);
325N/A }
325N/A }
325N/A
325N/A private void fillRequestAddressingHeaders(@NotNull Packet packet, @NotNull AddressingVersion av, @NotNull SOAPVersion sv, @NotNull OneWayFeature of, @NotNull String action) {
325N/A fillCommonAddressingHeaders(packet, av, sv, action, false);
325N/A
325N/A // wsa:ReplyTo
325N/A if (of.getReplyTo() != null) {
325N/A add(of.getReplyTo().createHeader(av.replyToTag));
325N/A
325N/A // add wsa:MessageID only for non-null ReplyTo
325N/A Header h = new StringHeader(av.messageIDTag, packet.getMessage().getID(av, sv));
325N/A add(h);
325N/A }
325N/A
325N/A // wsa:From
325N/A if (of.getFrom() != null) {
325N/A add(of.getFrom().createHeader(av.fromTag));
325N/A }
325N/A
325N/A // wsa:RelatesTo
325N/A if (of.getRelatesToID() != null) {
325N/A add(new RelatesToHeader(av.relatesToTag, of.getRelatesToID()));
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Creates wsa:To, wsa:Action and wsa:MessageID header on the client
325N/A *
325N/A * @param packet request packet
325N/A * @param av WS-Addressing version
325N/A * @param sv SOAP version
325N/A * @param action Action Message Addressing Property value
325N/A * @throws IllegalArgumentException if any of the parameters is null.
325N/A */
325N/A private void fillCommonAddressingHeaders(Packet packet, @NotNull AddressingVersion av, @NotNull SOAPVersion sv, @NotNull String action, boolean mustUnderstand) {
325N/A if (packet == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_PACKET());
325N/A }
325N/A
325N/A if (av == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_ADDRESSING_VERSION());
325N/A }
325N/A
325N/A if (sv == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_SOAP_VERSION());
325N/A }
325N/A
325N/A if (action == null) {
325N/A throw new IllegalArgumentException(AddressingMessages.NULL_ACTION());
325N/A }
325N/A
325N/A // wsa:To
325N/A StringHeader h = new StringHeader(av.toTag, packet.endpointAddress.toString());
325N/A add(h);
325N/A
325N/A // wsa:Action
325N/A packet.soapAction = action;
325N/A //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.,
325N/A // so just set MU on action header
325N/A h = new StringHeader(av.actionTag, action, sv, mustUnderstand);
325N/A add(h);
325N/A }
325N/A
325N/A /**
325N/A * Adds a new {@link Header}.
325N/A *
325N/A * <p>
325N/A * Order doesn't matter in headers, so this method
325N/A * does not make any guarantee as to where the new header
325N/A * is inserted.
325N/A *
325N/A * @return
325N/A * always true. Don't use the return value.
325N/A */
325N/A @Override
325N/A public boolean add(Header header) {
325N/A return super.add(header);
325N/A }
325N/A
325N/A /**
325N/A * Removes the first {@link Header} of the specified name.
325N/A *
325N/A * @param nsUri namespace URI of the header to remove
325N/A * @param localName local part of the FQN of the header to remove
325N/A *
325N/A * @return null if not found.
325N/A */
325N/A public
325N/A @Nullable
325N/A Header remove(@NotNull String nsUri, @NotNull String localName) {
325N/A int len = size();
325N/A for (int i = 0; i < len; i++) {
325N/A Header h = get(i);
325N/A if (h.getLocalPart().equals(localName) && h.getNamespaceURI().equals(nsUri)) {
325N/A return remove(i);
325N/A }
325N/A }
325N/A return null;
325N/A }
325N/A
325N/A /**
325N/A * Removes the first {@link Header} of the specified name.
325N/A *
325N/A * @param name fully qualified name of the header to remove
325N/A *
325N/A * @return null if not found.
325N/A */
325N/A public
325N/A @Nullable
325N/A Header remove(@NotNull QName name) {
325N/A return remove(name.getNamespaceURI(), name.getLocalPart());
325N/A }
325N/A
325N/A /**
325N/A * Removes the first {@link Header} of the specified name.
325N/A *
325N/A * @param index index of the header to remove
325N/A *
325N/A * @return removed header
325N/A */
325N/A @Override
325N/A public Header remove(int index) {
325N/A removeUnderstoodBit(index);
325N/A return super.remove(index);
325N/A }
325N/A
325N/A /**
325N/A * Removes the "understood" bit for header on the position specified by {@code index} parameter
325N/A * from the set of understood header bits.
325N/A *
325N/A * @param index position of the bit to remove
325N/A */
325N/A private void removeUnderstoodBit(int index) {
325N/A assert index < size();
325N/A
325N/A if (index < 32) {
325N/A /**
325N/A * Let
325N/A * R be the bit to be removed
325N/A * M be a more significant "upper" bit than bit R
325N/A * L be a less significant "lower" bit than bit R
325N/A *
325N/A * Then following 3 lines of code produce these results:
325N/A *
325N/A * old understoodBits = MMMMMMMMMMMMRLLLLLLLLLLLLLLLLLLL
325N/A *
325N/A * shiftedUpperBits = 0MMMMMMMMMMMM0000000000000000000
325N/A *
325N/A * lowerBits = 0000000000000LLLLLLLLLLLLLLLLLLL
325N/A *
325N/A * new understoodBits = 0MMMMMMMMMMMMLLLLLLLLLLLLLLLLLLL
325N/A *
325N/A * The R bit is removed and all the upper bits are shifted right (unsigned)
325N/A */
325N/A int shiftedUpperBits = understoodBits >>> -31 + index << index;
325N/A int lowerBits = understoodBits << -index >>> 31 - index >>> 1;
325N/A understoodBits = shiftedUpperBits | lowerBits;
325N/A
325N/A if (moreUnderstoodBits != null && moreUnderstoodBits.cardinality() > 0) {
325N/A if (moreUnderstoodBits.get(0)) {
325N/A understoodBits |= 0x80000000;
325N/A }
325N/A
325N/A moreUnderstoodBits.clear(0);
325N/A for (int i = moreUnderstoodBits.nextSetBit(1); i > 0; i = moreUnderstoodBits.nextSetBit(i + 1)) {
325N/A moreUnderstoodBits.set(i - 1);
325N/A moreUnderstoodBits.clear(i);
325N/A }
325N/A }
325N/A } else if (moreUnderstoodBits != null && moreUnderstoodBits.cardinality() > 0) {
325N/A index -= 32;
325N/A moreUnderstoodBits.clear(index);
325N/A for (int i = moreUnderstoodBits.nextSetBit(index); i >= 1; i = moreUnderstoodBits.nextSetBit(i + 1)) {
325N/A moreUnderstoodBits.set(i - 1);
325N/A moreUnderstoodBits.clear(i);
325N/A }
325N/A }
325N/A
325N/A // remove bit set if the new size will be < 33 => we fit all bits into int
325N/A if (size() - 1 <= 33 && moreUnderstoodBits != null) {
325N/A moreUnderstoodBits = null;
325N/A }
325N/A }
325N/A
325N/A /**
325N/A * Removes a single instance of the specified element from this
325N/A * header list, if it is present. More formally,
325N/A * removes a header <tt>h</tt> such that <tt>(o==null ? h==null :
325N/A * o.equals(h))</tt>, if the header list contains one or more such
325N/A * headers. Returns <tt>true</tt> if the list contained the
325N/A * specified element (or equivalently, if the list changed as a
325N/A * result of the call).<p>
325N/A *
325N/A * @param o element to be removed from this list, if present.
325N/A * @return <tt>true</tt> if the list contained the specified element.
325N/A * @see #remove(javax.xml.namespace.QName)
325N/A */
325N/A @Override
325N/A public boolean remove(Object o) {
325N/A if (o != null) {
325N/A for (int index = 0; index < this.size(); index++)
325N/A if (o.equals(this.get(index))) {
325N/A remove(index);
325N/A return true;
325N/A }
325N/A }
325N/A
325N/A return false;
325N/A }
325N/A
325N/A /**
325N/A * Creates a copy.
325N/A *
325N/A * This handles null {@link HeaderList} correctly.
325N/A *
325N/A * @param original
325N/A * Can be null, in which case null will be returned.
325N/A */
325N/A public static HeaderList copy(HeaderList original) {
325N/A if (original == null) {
325N/A return null;
325N/A } else {
325N/A return new HeaderList(original);
325N/A }
325N/A }
325N/A
325N/A public void readResponseAddressingHeaders(WSDLPort wsdlPort, WSBinding binding) {
325N/A // read Action
325N/A String wsaAction = getAction(binding.getAddressingVersion(), binding.getSOAPVersion());
325N/A // TODO: validate client-inbound Action
325N/A }
325N/A}