public interface 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
.
HeaderList
,
Headers
Modifier and Type | Method and Description |
---|---|
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(com.sun.xml.bind.api.Bridge<T> bridge)
Deprecated.
|
<T> T |
readAsJAXB(Unmarshaller unmarshaller)
Reads the header as a JAXB object by using the given unmarshaller.
|
<T> T |
readAsJAXB(XMLBridge<T> bridge)
Reads the header as a data-bond object
|
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.
|
boolean isIgnorable(@NotNull SOAPVersion soapVersion, @NotNull Set<String> roles)
This method is used as a part of the
mustUnderstanx processing.
At the end of the processing, the JAX-WS identifies a list of Header
s
that were not understood. This method is invoked on those Header
s,
to verify that we don't need to report an error for it.
specifically, this method has to perform the following tasks:
getRole(SOAPVersion)
for how the values are defaulted.
Now, see if the roles
set contains the value.
If so, this method must return false (indicating that an error is in order.)
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 Header
s 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.@NotNull String getRole(@NotNull SOAPVersion soapVersion)
If the attribute is omitted, the value defaults to SOAPVersion.implicitRole
.
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 Header
s to avoid keeping it.
That's why this redundant parameter is passed in.boolean isRelay()
IOW, this method returns true if there's @soap:relay='true' is present.
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.
@NotNull String getNamespaceURI()
@NotNull String getLocalPart()
@Nullable String getAttribute(@NotNull String nsUri, @NotNull String localName)
nsUri
- The namespace URI of the attribute. Can be empty.localName
- The local name of the attribute.Header
implementation
doesn't have to do anything.@Nullable String getAttribute(@NotNull QName name)
This is a convenience method that calls into getAttribute(String, String)
name
- Never null.getAttribute(String, String)
javax.xml.stream.XMLStreamReader readHeader() throws javax.xml.stream.XMLStreamException
XMLStreamReader
.
The returned parser points at the start element of this header.
(IOW, XMLStreamReader.getEventType()
would return
XMLStreamConstants.START_ELEMENT
.
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.
Message
s that come from tranport usually provides
a reasonably efficient implementation of this method.
javax.xml.stream.XMLStreamException
<T> T readAsJAXB(Unmarshaller unmarshaller) throws JAXBException
JAXBException
<T> T readAsJAXB(com.sun.xml.bind.api.Bridge<T> bridge) throws JAXBException
JAXBException
<T> T readAsJAXB(XMLBridge<T> bridge) throws JAXBException
JAXBException
@NotNull WSEndpointReference readAsEPR(AddressingVersion expected) throws javax.xml.stream.XMLStreamException
WSEndpointReference
.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.javax.xml.stream.XMLStreamException
void writeTo(javax.xml.stream.XMLStreamWriter w) throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
- if the operation fails for some reason. This leaves the
writer to an undefined state.void writeTo(javax.xml.soap.SOAPMessage saaj) throws javax.xml.soap.SOAPException
Sometimes a Message
needs to produce itself
as SOAPMessage
, in which case each header needs
to turn itself into a header.
javax.xml.soap.SOAPException
- if the operation fails for some reason. This leaves the
writer to an undefined state.void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException
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
.
contentHandler
- The ContentHandler
that receives SAX events.errorHandler
- The ErrorHandler
that receives parsing errors.SAXException
@NotNull String getStringContent()
WebServiceException
- If the structure of the header is more complicated than
a simple string header.Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.