com.sun.xml.ws.api.message
Interface Header

All Known Implementing Classes:
AbstractHeaderImpl, DOMHeader, EPRHeader, FaultDetailHeader, JAXBHeader, OutboundReferenceParameterHeader, OutboundStreamHeader, ProblemActionHeader, RelatesToHeader, SAAJHeader, StreamHeader, StreamHeader11, StreamHeader12, StringHeader

public interface Header

A SOAP header.

A header is immutable, but unlike body it can be read multiple times. The Header abstraction hides how the header data is represented in memory; instead, it commits to the ability to write itself to XML infoset.

When a message is received from the transport and being processed, the processor needs to "peek" some information of a header, such as the tag name, the mustUnderstand attribute, and so on. Therefore, the Header interface exposes those information as properties, so that they can be checked without replaying the infoset, which is efficiently but still costly.

A Header may belong to more than one HeaderList due to wrapping of Message.

See Also:
HeaderList, Headers

Method Summary
 String getAttribute(QName name)
          Gets the attribute value on the header element.
 String getAttribute(String nsUri, String localName)
          Gets the attribute value on the header element.
 String getLocalPart()
          Gets the local name of this header element.
 String getNamespaceURI()
          Gets the namespace URI of this header element.
 String getRole(SOAPVersion soapVersion)
          Gets the value of the soap:role attribute (or soap:actor for SOAP 1.1).
 String getStringContent()
          Used to obtain value XYZ from a header that looks like "<header>XYZ</header>".
 boolean isIgnorable(SOAPVersion soapVersion, Set<String> roles)
          Checks if this header is ignorable for us (IOW, make sure that this header has a problematic "mustUnderstand" header value that we have to reject.)
 boolean isRelay()
          True if this header is to be relayed if not processed.
 WSEndpointReference readAsEPR(AddressingVersion expected)
          Reads this header as an WSEndpointReference.
<T> T
readAsJAXB(Bridge<T> bridge)
          Reads the header as a JAXB object by using the given unmarshaller.
<T> T
readAsJAXB(Unmarshaller unmarshaller)
          Reads the header as a JAXB object by using the given unmarshaller.
 javax.xml.stream.XMLStreamReader readHeader()
          Reads the header as a XMLStreamReader.
 void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler)
          Writes out the header as SAX events.
 void writeTo(javax.xml.soap.SOAPMessage saaj)
          Writes out the header to the given SOAPMessage.
 void writeTo(javax.xml.stream.XMLStreamWriter w)
          Writes out the header as a fragment.
 

Method Detail

isIgnorable

boolean isIgnorable(@NotNull
                    SOAPVersion soapVersion,
                    @NotNull
                    Set<String> roles)
Checks if this header is ignorable for us (IOW, make sure that this header has a problematic "mustUnderstand" header value that we have to reject.)

This method is used as a part of the mustUnderstanx processing. At the end of the processing, the JAX-WS identifies a list of Headers that were not understood. This method is invoked on those Headers, to verify that we don't need to report an error for it.

specifically, this method has to perform the following tasks:

Parameters:
soapVersion - The caller specifies the SOAP version that the pipeline is working against. Often each Header implementation already knows the SOAP version anyway, but this allows some Headers to avoid keeping it. That's why this redundant parameter is passed in.
roles - The set of role values that the current JAX-WS pipeline is assuming. Note that SOAP 1.1 and SOAP 1.2 use different strings for the same role, and the caller is responsible for supplying a proper value depending on the active SOAP version in use.
Returns:
true if no error needs to be reported. False if an error needs to be raised. See the method javadoc for more discussion.

getRole

@NotNull
String getRole(@NotNull
                       SOAPVersion soapVersion)
Gets the value of the soap:role attribute (or soap:actor for SOAP 1.1).

If the attribute is omitted, the value defaults to SOAPVersion.implicitRole.

Parameters:
soapVersion - The caller specifies the SOAP version that the pipeline is working against. Often each Header implementation already knows the SOAP version anyway, but this allows some Headers to avoid keeping it. That's why this redundant parameter is passed in.
Returns:
never null. This string need not be interned.

isRelay

boolean isRelay()
True if this header is to be relayed if not processed. For SOAP 1.1 messages, this method always return false.

IOW, this method returns true if there's @soap:relay='true' is present.

Implementation Note

The implementation needs to check for both "true" and "1", but because attribute values are normalized, it doesn't have to consider " true", " 1 ", and so on.

Returns:
false.

getNamespaceURI

@NotNull
String getNamespaceURI()
Gets the namespace URI of this header element.

Returns:
this string must be interned.

getLocalPart

@NotNull
String getLocalPart()
Gets the local name of this header element.

Returns:
this string must be interned.

getAttribute

@Nullable
String getAttribute(@NotNull
                             String nsUri,
                             @NotNull
                             String localName)
Gets the attribute value on the header element.

Parameters:
nsUri - The namespace URI of the attribute. Can be empty.
localName - The local name of the attribute.
Returns:
if the attribute is found, return the whitespace normalized value. (meaning no leading/trailing space, no consequtive whitespaces in-between.) Otherwise null. Note that the XML parsers are responsible for whitespace-normalizing attributes, so Header implementation doesn't have to do anything.

getAttribute

@Nullable
String getAttribute(@NotNull
                             QName name)
Gets the attribute value on the header element.

This is a convenience method that calls into getAttribute(String, String)

Parameters:
name - Never null.
See Also:
getAttribute(String, String)

readHeader

javax.xml.stream.XMLStreamReader readHeader()
                                            throws javax.xml.stream.XMLStreamException
Reads the header as a XMLStreamReader.

The returned parser points at the start element of this header. (IOW, XMLStreamReader.getEventType() would return XMLStreamConstants.START_ELEMENT.

Performance Expectation

For some Header implementations, this operation is a non-trivial operation. Therefore, use of this method is discouraged unless the caller is interested in reading the whole header.

Similarly, if the caller wants to use this method only to do the API conversion (such as simply firing SAX events from XMLStreamReader), then the JAX-WS team requests that you talk to us.

Messages that come from tranport usually provides a reasonably efficient implementation of this method.

Returns:
must not null.
Throws:
javax.xml.stream.XMLStreamException

readAsJAXB

<T> T readAsJAXB(Unmarshaller unmarshaller)
             throws JAXBException
Reads the header as a JAXB object by using the given unmarshaller.

Throws:
JAXBException

readAsJAXB

<T> T readAsJAXB(Bridge<T> bridge)
             throws JAXBException
Reads the header as a JAXB object by using the given unmarshaller.

Throws:
JAXBException

readAsEPR

@NotNull
WSEndpointReference readAsEPR(AddressingVersion expected)
                              throws javax.xml.stream.XMLStreamException
Reads this header as an WSEndpointReference.

Parameters:
expected - The version of the addressing used to parse the EPR. If the actual infoset and this doesn't agree, then you'll get an WebServiceException stating that fact.
Returns:
On a successful return, this method never returns null.
Throws:
javax.xml.stream.XMLStreamException

writeTo

void writeTo(javax.xml.stream.XMLStreamWriter w)
             throws javax.xml.stream.XMLStreamException
Writes out the header as a fragment.

Throws:
javax.xml.stream.XMLStreamException - if the operation fails for some reason. This leaves the writer to an undefined state.

writeTo

void writeTo(javax.xml.soap.SOAPMessage saaj)
             throws javax.xml.soap.SOAPException
Writes out the header to the given SOAPMessage.

Sometimes a Message needs to produce itself as SOAPMessage, in which case each header needs to turn itself into a header.

Throws:
javax.xml.soap.SOAPException - if the operation fails for some reason. This leaves the writer to an undefined state.

writeTo

void writeTo(ContentHandler contentHandler,
             ErrorHandler errorHandler)
             throws SAXException
Writes out the header as SAX events.

Sometimes a Message needs to produce SAX events, and this method is necessary for headers to participate to it.

A header is responsible for producing the SAX events for its part, including startPrefixMapping and endPrefixMapping, but not startDocument/endDocument.

Note that SAX contract requires that any error that does NOT originate from ContentHandler (meaning any parsing error and etc) must be first reported to ErrorHandler. If the SAX event production cannot be continued and the processing needs to abort, the code may then throw the same SAXParseException reported to ErrorHandler.

Parameters:
contentHandler - The ContentHandler that receives SAX events.
errorHandler - The ErrorHandler that receives parsing errors.
Throws:
SAXException

getStringContent

@NotNull
String getStringContent()
Used to obtain value XYZ from a header that looks like "<header>XYZ</header>". The primary use of this header for now is to access certain Addressing headers quickly.

Returns:
Can be empty but always non-null.
Throws:
javax.xml.ws.WebServiceException - If the structure of the header is more complicated than a simple string header.