Class JAXBMessage
- java.lang.Object
-
- com.sun.xml.ws.api.message.Message
-
- com.sun.xml.ws.message.AbstractMessageImpl
-
- com.sun.xml.ws.message.jaxb.JAXBMessage
-
- All Implemented Interfaces:
StreamingSOAP
public final class JAXBMessage extends AbstractMessageImpl implements StreamingSOAP
Messagebacked by a JAXB bean.- Author:
- Kohsuke Kawaguchi
-
-
Field Summary
-
Fields inherited from class com.sun.xml.ws.message.AbstractMessageImpl
bodyTag, DEFAULT_TAGS, EMPTY_ATTS, envelopeTag, headerTag, NULL_LOCATOR, soapVersion
-
Fields inherited from class com.sun.xml.ws.api.message.Message
attachmentSet
-
-
Constructor Summary
Constructors Constructor Description JAXBMessage(JAXBMessage that)Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Messagecopy()Creates a copy of aMessage.static Messagecreate(BindingContext context, Object jaxbObject, SOAPVersion soapVersion)Creates aMessagebacked by a JAXB bean.static Messagecreate(BindingContext context, Object jaxbObject, SOAPVersion soapVersion, MessageHeaders headers, AttachmentSet attachments)static Messagecreate(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer)Creates aMessagebacked by a JAXB bean.static Messagecreate(jakarta.xml.bind.JAXBContext context, Object jaxbObject, SOAPVersion soapVersion)Deprecated.static MessagecreateRaw(jakarta.xml.bind.JAXBContext context, Object jaxbObject, SOAPVersion soapVersion)Deprecated.For use when creating a Dispatch object with an unknown JAXB implementation for he JAXBContext parameter.MessageHeadersgetHeaders()Gets all the headers of this message.StringgetPayloadLocalPart()Gets the local name of the payload element.StringgetPayloadNamespaceURI()Gets the namespace URI of the payload element.QNamegetPayloadQName()booleanhasHeaders()Returns true if headers are present in the message.booleanhasPayload()Returns true if aMessagehas a payload.booleanisPayloadStreamReader()XMLStreamReaderreadEnvelope()XMLStreamReaderreadPayload()Reads the payload as aXMLStreamReaderThis consumes the message.<T> TreadPayloadAsJAXB(jakarta.xml.bind.Unmarshaller unmarshaller)Reads the payload as a JAXB object by using the given unmarshaller.SourcereadPayloadAsSource()Returns the payload as aSourceobject.XMLStreamReaderreadToBodyStarTag()voidwritePayloadTo(XMLStreamWriter sw)Writes the payload to StAX.protected voidwritePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment)Writes the payload as SAX events.-
Methods inherited from class com.sun.xml.ws.message.AbstractMessageImpl
getSOAPVersion, readAsSOAPMessage, readAsSOAPMessage, readEnvelopeAsSource, readPayloadAsJAXB, readPayloadAsJAXB, toSAAJ, writeTo, writeTo, writeToBodyStart
-
Methods inherited from class com.sun.xml.ws.api.message.Message
addSOAPMimeHeaders, assertOneWay, consume, copyFrom, generateMessageID, getAttachments, getFirstDetailEntryName, getID, getID, getMethod, getOperation, getOperation, getTransportHeaders, getTransportHeaders, hasAttachments, isFault, isOneWay, setMessageMedadata
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.sun.xml.ws.api.message.StreamingSOAP
writeToBodyStart
-
-
-
-
Constructor Detail
-
JAXBMessage
public JAXBMessage(JAXBMessage that)
Copy constructor.
-
-
Method Detail
-
create
public static Message create(BindingContext context, Object jaxbObject, SOAPVersion soapVersion, MessageHeaders headers, AttachmentSet attachments)
-
create
public static Message create(BindingContext context, Object jaxbObject, SOAPVersion soapVersion)
Creates aMessagebacked by a JAXB bean.- Parameters:
context- The JAXBContext to be used for marshalling.jaxbObject- The JAXB object that represents the payload. must not be null. This object must be bound to an element (which means it either is aJAXBElementor an instanceof a class withXmlRootElement).soapVersion- The SOAP version of the message. Must not be null.
-
create
public static Message create(jakarta.xml.bind.JAXBContext context, Object jaxbObject, SOAPVersion soapVersion)
Deprecated.
-
createRaw
public static Message createRaw(jakarta.xml.bind.JAXBContext context, Object jaxbObject, SOAPVersion soapVersion)
Deprecated.For use when creating a Dispatch object with an unknown JAXB implementation for he JAXBContext parameter.
-
create
public static Message create(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer)
Creates aMessagebacked by a JAXB bean.- Parameters:
bridge- Specify the payload tag name and howjaxbObjectis bound.jaxbObject-
-
hasHeaders
public boolean hasHeaders()
Description copied from class:MessageReturns true if headers are present in the message.- Specified by:
hasHeadersin classMessage- Returns:
- true if headers are present.
-
getHeaders
public MessageHeaders getHeaders()
Description copied from class:MessageGets all the headers of this message.Implementation Note
Messageimplementation is allowed to defer the construction ofMessageHeadersobject. So if you only want to check for the existence of any header element, useMessage.hasHeaders().- Specified by:
getHeadersin classMessage- Returns:
- always return the same non-null object.
-
getPayloadLocalPart
public String getPayloadLocalPart()
Description copied from class:MessageGets the local name of the payload element.- Specified by:
getPayloadLocalPartin classMessage- Returns:
- null if a
Messagedoesn't have any payload.
-
getPayloadNamespaceURI
public String getPayloadNamespaceURI()
Description copied from class:MessageGets the namespace URI of the payload element.- Specified by:
getPayloadNamespaceURIin classMessage- Returns:
- null if a
Messagedoesn't have any payload.
-
hasPayload
public boolean hasPayload()
Description copied from class:MessageReturns true if aMessagehas a payload.A message without a payload is a SOAP message that looks like:
<S:Envelope> <S:Header> ... </S:Header> <S:Body /> </S:Envelope>- Specified by:
hasPayloadin classMessage
-
readPayloadAsSource
public Source readPayloadAsSource()
Description copied from class:MessageReturns the payload as aSourceobject. This consumes the message.- Specified by:
readPayloadAsSourcein classMessage- Returns:
- if there's no payload, this method returns null.
-
readPayloadAsJAXB
public <T> T readPayloadAsJAXB(jakarta.xml.bind.Unmarshaller unmarshaller) throws jakarta.xml.bind.JAXBExceptionDescription copied from class:MessageReads the payload as a JAXB object by using the given unmarshaller. This consumes the message.- Overrides:
readPayloadAsJAXBin classAbstractMessageImpl- Throws:
jakarta.xml.bind.JAXBException- If JAXB reports an error during the processing.
-
readPayload
public XMLStreamReader readPayload() throws XMLStreamException
Description copied from class:MessageReads the payload as aXMLStreamReaderThis consumes the message. The caller is encouraged to callXMLStreamReaderFactory.recycle(XMLStreamReader)when finished using the instance.- Specified by:
readPayloadin interfaceStreamingSOAP- Specified by:
readPayloadin classMessage- Returns:
- If there's no payload, this method returns null.
Otherwise always non-null valid
XMLStreamReaderthat points to the payload tag name. - Throws:
XMLStreamException
-
writePayloadTo
protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException
Writes the payload as SAX events.- Specified by:
writePayloadToin classAbstractMessageImplfragment- if true, this method will fire SAX events without start/endDocument events, suitable for embedding this into a bigger SAX event sequence. if false, this method generaets a completely SAX event sequence on its own.- Throws:
SAXException
-
writePayloadTo
public void writePayloadTo(XMLStreamWriter sw) throws XMLStreamException
Description copied from class:MessageWrites the payload to StAX. This method writes just the payload of the message to the writer. This consumes the message. The implementation will not writeXMLStreamWriter.writeStartDocument()norXMLStreamWriter.writeEndDocument()If there's no payload, this method is no-op.
- Specified by:
writePayloadToin interfaceStreamingSOAP- Specified by:
writePayloadToin classMessage- Throws:
XMLStreamException- If theXMLStreamWriterreports an error, or some other errors happen during the processing.
-
copy
public Message copy()
Description copied from class:MessageCreates a copy of aMessage.This method creates a new
Messagewhose header/payload/attachments/properties are identical to thisMessage. Once created, the createdMessageand the originalMessagebehaves independently --- adding header/ attachment to oneMessagedoesn't affect anotherMessageat all.This method does NOT consume a message.
To enable efficient copy operations, there's a few restrictions on how copied message can be used.
- The original and the copy may not be
used concurrently by two threads (this allows two
Messages to share some internal resources, such as JAXB marshallers.) Note that it's OK for the original and the copy to be processed by two threads, as long as they are not concurrent. - The copy has the same 'life scope'
as the original (this allows shallower copy, such as
JAXB beans wrapped in
JAXBMessage.)
A 'life scope' of a message created during a message processing in a pipeline is until a pipeline processes the next message. A message cannot be kept beyond its life scope. (This experimental design is to allow message objects to be reused --- feedback appreciated.)
Design Rationale
Since a
Messagebody is read-once, sometimes (such as when you do fail-over, or WS-RM) you need to create an idential copy of aMessage.The actual copy operation depends on the layout of the data in memory, hence it's best to be done by the
Messageimplementation itself.The restrictions placed on the use of copied
Messagecan be relaxed if necessary, but it will make the copy method more expensive.IMPORTANT
WHEN YOU IMPLEMENT OR CHANGE A {@link .copy()} METHOD, YOU MUST USE THE
Message.copyFrom(com.sun.xml.ws.api.message.Message)METHOD IN THE IMPLEMENTATION. - The original and the copy may not be
used concurrently by two threads (this allows two
-
readEnvelope
public XMLStreamReader readEnvelope()
- Specified by:
readEnvelopein interfaceStreamingSOAP
-
isPayloadStreamReader
public boolean isPayloadStreamReader()
- Specified by:
isPayloadStreamReaderin interfaceStreamingSOAP
-
getPayloadQName
public QName getPayloadQName()
- Specified by:
getPayloadQNamein interfaceStreamingSOAP
-
readToBodyStarTag
public XMLStreamReader readToBodyStarTag()
- Specified by:
readToBodyStarTagin interfaceStreamingSOAP
-
-