ohair@286: /*
alanb@368: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286: *
ohair@286: * This code is free software; you can redistribute it and/or modify it
ohair@286: * under the terms of the GNU General Public License version 2 only, as
ohair@286: * published by the Free Software Foundation. Oracle designates this
ohair@286: * particular file as subject to the "Classpath" exception as provided
ohair@286: * by Oracle in the LICENSE file that accompanied this code.
ohair@286: *
ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286: * version 2 for more details (a copy is included in the LICENSE file that
ohair@286: * accompanied this code).
ohair@286: *
ohair@286: * You should have received a copy of the GNU General Public License version
ohair@286: * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286: *
ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286: * or visit www.oracle.com if you need additional information or have any
ohair@286: * questions.
ohair@286: */
ohair@286:
ohair@286: package com.sun.xml.internal.ws.addressing;
ohair@286:
alanb@368: import com.oracle.webservices.internal.api.message.BasePropertySet;
ohair@286: import com.sun.istack.internal.NotNull;
ohair@286: import com.sun.xml.internal.ws.api.SOAPVersion;
ohair@286: import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
ohair@286: import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
alanb@368: import com.sun.xml.internal.ws.api.message.AddressingUtils;
ohair@286: import com.sun.xml.internal.ws.api.message.Header;
ohair@286: import com.sun.xml.internal.ws.api.message.Message;
ohair@286: import com.sun.xml.internal.ws.api.message.Packet;
ohair@286: import com.sun.xml.internal.ws.developer.JAXWSProperties;
ohair@286:
ohair@286: import javax.xml.namespace.QName;
ohair@286: import javax.xml.stream.XMLStreamException;
ohair@286:
alanb@368:
ohair@286: /**
ohair@286: * Provides access to the Addressing headers.
ohair@286: *
ohair@286: * @author Kohsuke Kawaguchi
ohair@286: * @author Rama Pulavarthi
ohair@286: * @since 2.1.3
ohair@286: */
alanb@368: public class WsaPropertyBag extends BasePropertySet {
ohair@286:
ohair@286: public static final String WSA_REPLYTO_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.ReplyToFromRequest";
ohair@286: public static final String WSA_FAULTTO_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.FaultToFromRequest";
ohair@286: public static final String WSA_MSGID_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.MessageIdFromRequest";
ohair@286: public static final String WSA_TO = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.To";
ohair@286:
ohair@286: private final @NotNull AddressingVersion addressingVersion;
ohair@286: private final @NotNull SOAPVersion soapVersion;
ohair@286: /**
ohair@286: * We can't store {@link Message} here as those may get replaced as
ohair@286: * the packet travels through the pipeline.
ohair@286: */
ohair@286: private final @NotNull Packet packet;
ohair@286:
ohair@286: public WsaPropertyBag(AddressingVersion addressingVersion, SOAPVersion soapVersion, Packet packet) {
ohair@286: this.addressingVersion = addressingVersion;
ohair@286: this.soapVersion = soapVersion;
ohair@286: this.packet = packet;
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Gets the wsa:To header.
ohair@286: *
ohair@286: * @return
ohair@286: * null if the incoming SOAP message didn't have the header.
ohair@286: */
ohair@286: @Property(JAXWSProperties.ADDRESSING_TO)
ohair@286: public String getTo() throws XMLStreamException {
ohair@286: if (packet.getMessage() == null) {
ohair@286: return null;
ohair@286: }
ohair@286: Header h = packet.getMessage().getHeaders().get(addressingVersion.toTag, false);
ohair@286: if(h==null) return null;
ohair@286: return h.getStringContent();
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Gets the wsa:To header.
ohair@286: *
ohair@286: * @return
ohair@286: * null if the incoming SOAP message didn't have the header.
ohair@286: */
ohair@286: @Property(WSA_TO)
ohair@286: public WSEndpointReference getToAsReference() throws XMLStreamException {
ohair@286: if (packet.getMessage() == null) {
ohair@286: return null;
ohair@286: }
ohair@286: Header h = packet.getMessage().getHeaders().get(addressingVersion.toTag, false);
ohair@286: if(h==null) return null;
ohair@286: return new WSEndpointReference(h.getStringContent(),addressingVersion);
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Gets the wsa:From header.
ohair@286: *
ohair@286: * @return
ohair@286: * null if the incoming SOAP message didn't have the header.
ohair@286: */
ohair@286: @Property(JAXWSProperties.ADDRESSING_FROM)
ohair@286: public WSEndpointReference getFrom() throws XMLStreamException {
ohair@286: return getEPR(addressingVersion.fromTag);
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Gets the wsa:Action header content as String.
ohair@286: *
ohair@286: * @return
ohair@286: * null if the incoming SOAP message didn't have the header.
ohair@286: */
ohair@286: @Property(JAXWSProperties.ADDRESSING_ACTION)
ohair@286: public String getAction() {
ohair@286: if (packet.getMessage() == null) {
ohair@286: return null;
ohair@286: }
ohair@286: Header h = packet.getMessage().getHeaders().get(addressingVersion.actionTag, false);
ohair@286: if(h==null) return null;
ohair@286: return h.getStringContent();
ohair@286: }
ohair@286:
ohair@286: /**
ohair@286: * Gets the wsa:MessageID header content as String.
ohair@286: *
ohair@286: * @return
ohair@286: * null if the incoming SOAP message didn't have the header.
ohair@286: */
ohair@286: // WsaServerTube.REQUEST_MESSAGE_ID is exposed for backward compatibility with 2.1
ohair@286: @Property({JAXWSProperties.ADDRESSING_MESSAGEID,WsaServerTube.REQUEST_MESSAGE_ID})
ohair@286: public String getMessageID() {
ohair@286: if (packet.getMessage() == null) {
ohair@286: return null;
ohair@286: }
alanb@368: return AddressingUtils.getMessageID(packet.getMessage().getHeaders(), addressingVersion,soapVersion);
ohair@286: }
ohair@286:
ohair@286: private WSEndpointReference getEPR(QName tag) throws XMLStreamException {
ohair@286: if (packet.getMessage() == null) {
ohair@286: return null;
ohair@286: }
ohair@286: Header h = packet.getMessage().getHeaders().get(tag, false);
ohair@286: if(h==null) return null;
ohair@286: return h.readAsEPR(addressingVersion);
ohair@286: }
ohair@286:
ohair@286: protected PropertyMap getPropertyMap() {
ohair@286: return model;
ohair@286: }
ohair@286:
ohair@286: private static final PropertyMap model;
ohair@286: static {
ohair@286: model = parse(WsaPropertyBag.class);
ohair@286: }
ohair@286:
ohair@286: private WSEndpointReference _replyToFromRequest = null;
ohair@286:
ohair@286: @Property(WSA_REPLYTO_FROM_REQUEST)
ohair@286: public WSEndpointReference getReplyToFromRequest() {
ohair@286: return _replyToFromRequest;
ohair@286: }
ohair@286:
ohair@286: public void setReplyToFromRequest(WSEndpointReference ref) {
ohair@286: _replyToFromRequest = ref;
ohair@286: }
ohair@286:
ohair@286: private WSEndpointReference _faultToFromRequest = null;
ohair@286:
ohair@286: @Property(WSA_FAULTTO_FROM_REQUEST)
ohair@286: public WSEndpointReference getFaultToFromRequest() {
ohair@286: return _faultToFromRequest;
ohair@286: }
ohair@286:
ohair@286: public void setFaultToFromRequest(WSEndpointReference ref) {
ohair@286: _faultToFromRequest = ref;
ohair@286: }
ohair@286:
ohair@286: private String _msgIdFromRequest = null;
ohair@286:
ohair@286: @Property(WSA_MSGID_FROM_REQUEST)
ohair@286: public String getMessageIdFromRequest() {
ohair@286: return _msgIdFromRequest;
ohair@286: }
ohair@286:
ohair@286: public void setMessageIdFromRequest(String id) {
ohair@286: _msgIdFromRequest = id;
ohair@286: }
ohair@286: }