001: package com.sun.xml.ws.addressing;
002:
003: import com.sun.istack.NotNull;
004: import com.sun.xml.ws.api.PropertySet;
005: import com.sun.xml.ws.api.SOAPVersion;
006: import com.sun.xml.ws.api.addressing.AddressingVersion;
007: import com.sun.xml.ws.api.addressing.WSEndpointReference;
008: import com.sun.xml.ws.api.message.Header;
009: import com.sun.xml.ws.api.message.Message;
010: import com.sun.xml.ws.api.message.Packet;
011: import com.sun.xml.ws.developer.JAXWSProperties;
012:
013: import javax.xml.namespace.QName;
014: import javax.xml.stream.XMLStreamException;
015:
016: /**
017: * Provides access to the Addressing headers.
018: *
019: * @author Kohsuke Kawaguchi
020: * @since 2.1.3
021: */
022: public class WsaPropertyBag extends PropertySet {
023: private final @NotNull
024: AddressingVersion addressingVersion;
025: private final @NotNull
026: SOAPVersion soapVersion;
027: /**
028: * We can't store {@link Message} here as those may get replaced as
029: * the packet travels through the pipeline.
030: */
031: private final @NotNull
032: Packet packet;
033:
034: WsaPropertyBag(AddressingVersion addressingVersion,
035: SOAPVersion soapVersion, Packet packet) {
036: this .addressingVersion = addressingVersion;
037: this .soapVersion = soapVersion;
038: this .packet = packet;
039: }
040:
041: /**
042: * Gets the <tt>wsa:To</tt> header.
043: *
044: * @return
045: * null if the incoming SOAP message didn't have the header.
046: */
047: @Property(JAXWSProperties.ADDRESSING_TO)
048: public WSEndpointReference getTo() throws XMLStreamException {
049: return getEPR(addressingVersion.toTag);
050: }
051:
052: /**
053: * Gets the <tt>wsa:From</tt> header.
054: *
055: * @return
056: * null if the incoming SOAP message didn't have the header.
057: */
058: @Property(JAXWSProperties.ADDRESSING_FROM)
059: public WSEndpointReference getFrom() throws XMLStreamException {
060: return getEPR(addressingVersion.fromTag);
061: }
062:
063: /**
064: * Gets the <tt>wsa:Action</tt> header content as String.
065: *
066: * @return
067: * null if the incoming SOAP message didn't have the header.
068: */
069: @Property(JAXWSProperties.ADDRESSING_ACTION)
070: public String getAction() {
071: Header h = packet.getMessage().getHeaders().get(
072: addressingVersion.actionTag, false);
073: if (h == null)
074: return null;
075: return h.getStringContent();
076: }
077:
078: /**
079: * Gets the <tt>wsa:MessageID</tt> header content as String.
080: *
081: * @return
082: * null if the incoming SOAP message didn't have the header.
083: */
084: // WsaServerTube.REQUEST_MESSAGE_ID is exposed for backward compatibility with 2.1
085: @Property({JAXWSProperties.ADDRESSING_MESSAGEID,WsaServerTube.REQUEST_MESSAGE_ID})
086: public String getMessageID() {
087: return packet.getMessage().getHeaders().getMessageID(
088: addressingVersion, soapVersion);
089: }
090:
091: private WSEndpointReference getEPR(QName tag)
092: throws XMLStreamException {
093: Header h = packet.getMessage().getHeaders().get(tag, false);
094: if (h == null)
095: return null;
096: return h.readAsEPR(addressingVersion);
097: }
098:
099: protected PropertyMap getPropertyMap() {
100: return model;
101: }
102:
103: private static final PropertyMap model;
104: static {
105: model = parse(WsaPropertyBag.class);
106: }
107: }
|