src/share/jaxws_classes/com/sun/xml/internal/ws/addressing/WsaPropertyBag.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.addressing;
27
28 import com.sun.istack.internal.NotNull;
29 import com.sun.xml.internal.ws.api.PropertySet;
30 import com.sun.xml.internal.ws.api.SOAPVersion;
31 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
32 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
33 import com.sun.xml.internal.ws.api.message.Header;
34 import com.sun.xml.internal.ws.api.message.Message;
35 import com.sun.xml.internal.ws.api.message.Packet;
36 import com.sun.xml.internal.ws.developer.JAXWSProperties;
37
38 import javax.xml.namespace.QName;
39 import javax.xml.stream.XMLStreamException;
40
41 /**
42 * Provides access to the Addressing headers.
43 *
44 * @author Kohsuke Kawaguchi
45 * @author Rama Pulavarthi
46 * @since 2.1.3
47 */
48 public class WsaPropertyBag extends PropertySet {
49
50 public static final String WSA_REPLYTO_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.ReplyToFromRequest";
51 public static final String WSA_FAULTTO_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.FaultToFromRequest";
52 public static final String WSA_MSGID_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.MessageIdFromRequest";
53 public static final String WSA_TO = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.To";
54
55 private final @NotNull AddressingVersion addressingVersion;
56 private final @NotNull SOAPVersion soapVersion;
57 /**
58 * We can't store {@link Message} here as those may get replaced as
59 * the packet travels through the pipeline.
60 */
61 private final @NotNull Packet packet;
62
63 public WsaPropertyBag(AddressingVersion addressingVersion, SOAPVersion soapVersion, Packet packet) {
64 this.addressingVersion = addressingVersion;
65 this.soapVersion = soapVersion;
66 this.packet = packet;
67 }
68
69 /**
70 * Gets the <tt>wsa:To</tt> header.
71 *
72 * @return
73 * null if the incoming SOAP message didn't have the header.
74 */
75 @Property(JAXWSProperties.ADDRESSING_TO)
76 public String getTo() throws XMLStreamException {
77 if (packet.getMessage() == null) {
78 return null;
79 }
80 Header h = packet.getMessage().getHeaders().get(addressingVersion.toTag, false);
81 if(h==null) return null;
82 return h.getStringContent();
83 }
84
85 /**
86 * Gets the <tt>wsa:To</tt> header.
87 *
88 * @return
89 * null if the incoming SOAP message didn't have the header.
90 */
91 @Property(WSA_TO)
92 public WSEndpointReference getToAsReference() throws XMLStreamException {
93 if (packet.getMessage() == null) {
94 return null;
95 }
96 Header h = packet.getMessage().getHeaders().get(addressingVersion.toTag, false);
97 if(h==null) return null;
98 return new WSEndpointReference(h.getStringContent(),addressingVersion);
99 }
100
101 /**
102 * Gets the <tt>wsa:From</tt> header.
103 *
104 * @return
105 * null if the incoming SOAP message didn't have the header.
106 */
107 @Property(JAXWSProperties.ADDRESSING_FROM)
108 public WSEndpointReference getFrom() throws XMLStreamException {
109 return getEPR(addressingVersion.fromTag);
110 }
111
112 /**
113 * Gets the <tt>wsa:Action</tt> header content as String.
114 *
115 * @return
116 * null if the incoming SOAP message didn't have the header.
117 */
118 @Property(JAXWSProperties.ADDRESSING_ACTION)
119 public String getAction() {
120 if (packet.getMessage() == null) {
121 return null;
122 }
123 Header h = packet.getMessage().getHeaders().get(addressingVersion.actionTag, false);
124 if(h==null) return null;
125 return h.getStringContent();
126 }
127
128 /**
129 * Gets the <tt>wsa:MessageID</tt> header content as String.
130 *
131 * @return
132 * null if the incoming SOAP message didn't have the header.
133 */
134 // WsaServerTube.REQUEST_MESSAGE_ID is exposed for backward compatibility with 2.1
135 @Property({JAXWSProperties.ADDRESSING_MESSAGEID,WsaServerTube.REQUEST_MESSAGE_ID})
136 public String getMessageID() {
137 if (packet.getMessage() == null) {
138 return null;
139 }
140 return packet.getMessage().getHeaders().getMessageID(addressingVersion,soapVersion);
141 }
142
143 private WSEndpointReference getEPR(QName tag) throws XMLStreamException {
144 if (packet.getMessage() == null) {
145 return null;
146 }
147 Header h = packet.getMessage().getHeaders().get(tag, false);
148 if(h==null) return null;
149 return h.readAsEPR(addressingVersion);
150 }
151
152 protected PropertyMap getPropertyMap() {
153 return model;
154 }
155
156 private static final PropertyMap model;
157 static {
158 model = parse(WsaPropertyBag.class);
159 }
160
161 private WSEndpointReference _replyToFromRequest = null;
162
163 @Property(WSA_REPLYTO_FROM_REQUEST)
164 public WSEndpointReference getReplyToFromRequest() {
165 return _replyToFromRequest;
166 }
167
168 public void setReplyToFromRequest(WSEndpointReference ref) {
169 _replyToFromRequest = ref;
170 }
171
172 private WSEndpointReference _faultToFromRequest = null;
173
174 @Property(WSA_FAULTTO_FROM_REQUEST)
175 public WSEndpointReference getFaultToFromRequest() {
176 return _faultToFromRequest;
177 }
178
179 public void setFaultToFromRequest(WSEndpointReference ref) {
180 _faultToFromRequest = ref;
181 }
182
183 private String _msgIdFromRequest = null;
184
185 @Property(WSA_MSGID_FROM_REQUEST)
186 public String getMessageIdFromRequest() {
187 return _msgIdFromRequest;
188 }
189
190 public void setMessageIdFromRequest(String id) {
191 _msgIdFromRequest = id;
192 }
193 }

mercurial