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.bind.api.Bridge;
325N/Aimport com.sun.xml.internal.ws.api.SOAPVersion;
325N/Aimport com.sun.xml.internal.ws.api.addressing.AddressingVersion;
325N/Aimport com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
325N/Aimport org.xml.sax.ContentHandler;
325N/Aimport org.xml.sax.ErrorHandler;
325N/Aimport org.xml.sax.SAXException;
325N/Aimport org.xml.sax.SAXParseException;
325N/A
325N/Aimport javax.xml.bind.JAXBException;
325N/Aimport javax.xml.bind.Unmarshaller;
325N/Aimport javax.xml.namespace.QName;
325N/Aimport javax.xml.soap.SOAPException;
325N/Aimport javax.xml.soap.SOAPMessage;
325N/Aimport javax.xml.stream.XMLStreamException;
325N/Aimport javax.xml.stream.XMLStreamReader;
325N/Aimport javax.xml.stream.XMLStreamWriter;
325N/Aimport javax.xml.ws.WebServiceException;
325N/Aimport java.util.Set;
325N/A
325N/A
325N/A/**
325N/A * A SOAP header.
325N/A *
325N/A * <p>
325N/A * A header is immutable, but unlike body it can be read
325N/A * multiple times.
325N/A * The {@link Header} abstraction hides how the header
325N/A * data is represented in memory; instead, it commits to
325N/A * the ability to write itself to XML infoset.
325N/A *
325N/A * <p>
325N/A * When a message is received from the transport and
325N/A * being processed, the processor needs to "peek"
325N/A * some information of a header, such as the tag name,
325N/A * the mustUnderstand attribute, and so on. Therefore,
325N/A * the {@link Header} interface exposes those information
325N/A * as properties, so that they can be checked without
325N/A * replaying the infoset, which is efficiently but still
325N/A * costly.
325N/A *
325N/A * <p>
325N/A * A {@link Header} may belong to more than one {@link HeaderList}
325N/A * due to wrapping of {@link Message}.
325N/A *
325N/A * @see HeaderList
325N/A * @see Headers
325N/A */
325N/Apublic interface Header {
325N/A // TODO: Vivek pointed out that the only time we are looking at
325N/A // mustUnderstand and role are when we do the mustUnderstand error check
325N/A // (that is, to find out if there's any header with @mustUnderstand that
325N/A // has appropriate role for us.)
325N/A // if that's the case, it might be better if we define this whole operation
325N/A // as one method, instead of exposing two properties.
325N/A
325N/A /**
325N/A * Checks if this header is ignorable for us (IOW, make sure
325N/A * that this header has a problematic "mustUnderstand" header value
325N/A * that we have to reject.)
325N/A *
325N/A * <p>
325N/A * This method is used as a part of the
325N/A * <a href="HeaderList.html#MU">mustUnderstanx processing</a>.
325N/A * At the end of the processing, the JAX-WS identifies a list of {@link Header}s
325N/A * that were not understood. This method is invoked on those {@link Header}s,
325N/A * to verify that we don't need to report an error for it.
325N/A *
325N/A * <p>
325N/A * specifically, this method has to perform the following tasks:
325N/A *
325N/A * <ul>
325N/A * <li>If this header does not have <tt>mustUnderstand</tt> as "1" nor "true",
325N/A * then this method must return true.
325N/A * <li>Otherwise, check the role attribute (for SOAP 1.2) or the actor attribute (for SOAP 1.1).
325N/A * When those attributes are absent, the default values have to be assumed.
325N/A * See {@link #getRole(SOAPVersion)} for how the values are defaulted.
325N/A * Now, see if the {@code roles} set contains the value.
325N/A * If so, this method must return false (indicating that an error is in order.)
325N/A * <li>Otherwise return true (since we don't play the role this header is intended for.)
325N/A * </ul>
325N/A *
325N/A * @param soapVersion
325N/A * The caller specifies the SOAP version that the pipeline is working against.
325N/A * Often each {@link Header} implementation already knows the SOAP version
325N/A * anyway, but this allows some {@link Header}s to avoid keeping it.
325N/A * That's why this redundant parameter is passed in.
325N/A * @param roles
325N/A * The set of role values that the current JAX-WS pipeline is assuming.
325N/A * Note that SOAP 1.1 and SOAP 1.2 use different strings for the same role,
325N/A * and the caller is responsible for supplying a proper value depending on the
325N/A * active SOAP version in use.
325N/A *
325N/A * @return
325N/A * true if no error needs to be reported. False if an error needs to be raised.
325N/A * See the method javadoc for more discussion.
325N/A */
325N/A public boolean isIgnorable(@NotNull SOAPVersion soapVersion, @NotNull Set<String> roles);
325N/A
325N/A /**
325N/A * Gets the value of the soap:role attribute (or soap:actor for SOAP 1.1).
325N/A *
325N/A * <p>
325N/A * If the attribute is omitted, the value defaults to {@link SOAPVersion#implicitRole}.
325N/A *
325N/A * @param soapVersion
325N/A * The caller specifies the SOAP version that the pipeline is working against.
325N/A * Often each {@link Header} implementation already knows the SOAP version
325N/A * anyway, but this allows some {@link Header}s to avoid keeping it.
325N/A * That's why this redundant parameter is passed in.
325N/A * @return
325N/A * never null. This string need not be interned.
325N/A */
325N/A public @NotNull String getRole(@NotNull SOAPVersion soapVersion);
325N/A
325N/A /**
325N/A * True if this header is to be relayed if not processed.
325N/A * For SOAP 1.1 messages, this method always return false.
325N/A *
325N/A * <p>
325N/A * IOW, this method returns true if there's @soap:relay='true'
325N/A * is present.
325N/A *
325N/A * <h3>Implementation Note</h3>
325N/A * <p>
325N/A * The implementation needs to check for both "true" and "1",
325N/A * but because attribute values are normalized, it doesn't have
325N/A * to consider " true", " 1 ", and so on.
325N/A *
325N/A * @return
325N/A * false.
325N/A */
325N/A public boolean isRelay();
325N/A
325N/A /**
325N/A * Gets the namespace URI of this header element.
325N/A *
325N/A * @return
325N/A * this string must be interned.
325N/A */
325N/A public @NotNull String getNamespaceURI();
325N/A
325N/A /**
325N/A * Gets the local name of this header element.
325N/A *
325N/A * @return
325N/A * this string must be interned.
325N/A */
325N/A public @NotNull String getLocalPart();
325N/A
325N/A /**
325N/A * Gets the attribute value on the header element.
325N/A *
325N/A * @param nsUri
325N/A * The namespace URI of the attribute. Can be empty.
325N/A * @param localName
325N/A * The local name of the attribute.
325N/A *
325N/A * @return
325N/A * if the attribute is found, return the whitespace normalized value.
325N/A * (meaning no leading/trailing space, no consequtive whitespaces in-between.)
325N/A * Otherwise null. Note that the XML parsers are responsible for
325N/A * whitespace-normalizing attributes, so {@link Header} implementation
325N/A * doesn't have to do anything.
325N/A */
325N/A @Nullable String getAttribute(@NotNull String nsUri, @NotNull String localName);
325N/A
325N/A /**
325N/A * Gets the attribute value on the header element.
325N/A *
325N/A * <p>
325N/A * This is a convenience method that calls into {@link #getAttribute(String, String)}
325N/A *
325N/A * @param name
325N/A * Never null.
325N/A *
325N/A * @see #getAttribute(String, String)
325N/A */
325N/A @Nullable String getAttribute(@NotNull QName name);
325N/A
325N/A /**
325N/A * Reads the header as a {@link XMLStreamReader}.
325N/A *
325N/A * <p>
325N/A * The returned parser points at the start element of this header.
325N/A * (IOW, {@link XMLStreamReader#getEventType()} would return
325N/A * {@link XMLStreamReader#START_ELEMENT}.
325N/A *
325N/A * <h3>Performance Expectation</h3>
325N/A * <p>
325N/A * For some {@link Header} implementations, this operation
325N/A * is a non-trivial operation. Therefore, use of this method
325N/A * is discouraged unless the caller is interested in reading
325N/A * the whole header.
325N/A *
325N/A * <p>
325N/A * Similarly, if the caller wants to use this method only to do
325N/A * the API conversion (such as simply firing SAX events from
325N/A * {@link XMLStreamReader}), then the JAX-WS team requests
325N/A * that you talk to us.
325N/A *
325N/A * <p>
325N/A * {@link Message}s that come from tranport usually provides
325N/A * a reasonably efficient implementation of this method.
325N/A *
325N/A * @return
325N/A * must not null.
325N/A */
325N/A public XMLStreamReader readHeader() throws XMLStreamException;
325N/A
325N/A /**
325N/A * Reads the header as a JAXB object by using the given unmarshaller.
325N/A */
325N/A public <T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException;
325N/A
325N/A /**
325N/A * Reads the header as a JAXB object by using the given unmarshaller.
325N/A */
325N/A public <T> T readAsJAXB(Bridge<T> bridge) throws JAXBException;
325N/A
325N/A /**
325N/A * Reads this header as an {@link WSEndpointReference}.
325N/A *
325N/A * @param expected
325N/A * The version of the addressing used to parse the EPR.
325N/A * If the actual infoset and this doesn't agree, then
325N/A * you'll get an {@link WebServiceException} stating that fact.
325N/A *
325N/A * @return
325N/A * On a successful return, this method never returns null.
325N/A */
325N/A public @NotNull WSEndpointReference readAsEPR(AddressingVersion expected) throws XMLStreamException;
325N/A
325N/A /**
325N/A * Writes out the header as a fragment.
325N/A *
325N/A * @throws XMLStreamException
325N/A * if the operation fails for some reason. This leaves the
325N/A * writer to an undefined state.
325N/A */
325N/A public void writeTo(XMLStreamWriter w) throws XMLStreamException;
325N/A
325N/A /**
325N/A * Writes out the header to the given SOAPMessage.
325N/A *
325N/A * <p>
325N/A * Sometimes a {@link Message} needs to produce itself
325N/A * as {@link SOAPMessage}, in which case each header needs
325N/A * to turn itself into a header.
325N/A *
325N/A * @throws SOAPException
325N/A * if the operation fails for some reason. This leaves the
325N/A * writer to an undefined state.
325N/A */
325N/A public void writeTo(SOAPMessage saaj) throws SOAPException;
325N/A
325N/A /**
325N/A * Writes out the header as SAX events.
325N/A *
325N/A * <p>
325N/A * Sometimes a {@link Message} needs to produce SAX events,
325N/A * and this method is necessary for headers to participate to it.
325N/A *
325N/A * <p>
325N/A * A header is responsible for producing the SAX events for its part,
325N/A * including <tt>startPrefixMapping</tt> and <tt>endPrefixMapping</tt>,
325N/A * but not startDocument/endDocument.
325N/A *
325N/A * <p>
325N/A * Note that SAX contract requires that any error that does NOT originate
325N/A * from {@link ContentHandler} (meaning any parsing error and etc) must
325N/A * be first reported to {@link ErrorHandler}. If the SAX event production
325N/A * cannot be continued and the processing needs to abort, the code may
325N/A * then throw the same {@link SAXParseException} reported to {@link ErrorHandler}.
325N/A *
325N/A * @param contentHandler
325N/A * The {@link ContentHandler} that receives SAX events.
325N/A *
325N/A * @param errorHandler
325N/A * The {@link ErrorHandler} that receives parsing errors.
325N/A */
325N/A public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException;
325N/A
325N/A /**
325N/A * Used to obtain value XYZ from a header that looks like
325N/A * "&lt;header&gt;XYZ&lt;/header&gt;". The primary use of this header
325N/A * for now is to access certain Addressing headers quickly.
325N/A *
325N/A * @throws WebServiceException
325N/A * If the structure of the header is more complicated than
325N/A * a simple string header.
325N/A *
325N/A * @return
325N/A * Can be empty but always non-null.
325N/A */
325N/A public @NotNull String getStringContent();
325N/A}