|
1 /* |
|
2 * Copyright (c) 1997, 2013, 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.oracle.webservices.internal.api.message.BasePropertySet; |
|
29 import com.sun.istack.internal.NotNull; |
|
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.AddressingUtils; |
|
34 import com.sun.xml.internal.ws.api.message.Header; |
|
35 import com.sun.xml.internal.ws.api.message.Message; |
|
36 import com.sun.xml.internal.ws.api.message.Packet; |
|
37 import com.sun.xml.internal.ws.developer.JAXWSProperties; |
|
38 |
|
39 import javax.xml.namespace.QName; |
|
40 import javax.xml.stream.XMLStreamException; |
|
41 |
|
42 |
|
43 /** |
|
44 * Provides access to the Addressing headers. |
|
45 * |
|
46 * @author Kohsuke Kawaguchi |
|
47 * @author Rama Pulavarthi |
|
48 * @since 2.1.3 |
|
49 */ |
|
50 public class WsaPropertyBag extends BasePropertySet { |
|
51 |
|
52 public static final String WSA_REPLYTO_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.ReplyToFromRequest"; |
|
53 public static final String WSA_FAULTTO_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.FaultToFromRequest"; |
|
54 public static final String WSA_MSGID_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.MessageIdFromRequest"; |
|
55 public static final String WSA_TO = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.To"; |
|
56 |
|
57 private final @NotNull AddressingVersion addressingVersion; |
|
58 private final @NotNull SOAPVersion soapVersion; |
|
59 /** |
|
60 * We can't store {@link Message} here as those may get replaced as |
|
61 * the packet travels through the pipeline. |
|
62 */ |
|
63 private final @NotNull Packet packet; |
|
64 |
|
65 public WsaPropertyBag(AddressingVersion addressingVersion, SOAPVersion soapVersion, Packet packet) { |
|
66 this.addressingVersion = addressingVersion; |
|
67 this.soapVersion = soapVersion; |
|
68 this.packet = packet; |
|
69 } |
|
70 |
|
71 /** |
|
72 * Gets the <tt>wsa:To</tt> header. |
|
73 * |
|
74 * @return |
|
75 * null if the incoming SOAP message didn't have the header. |
|
76 */ |
|
77 @Property(JAXWSProperties.ADDRESSING_TO) |
|
78 public String getTo() throws XMLStreamException { |
|
79 if (packet.getMessage() == null) { |
|
80 return null; |
|
81 } |
|
82 Header h = packet.getMessage().getHeaders().get(addressingVersion.toTag, false); |
|
83 if(h==null) return null; |
|
84 return h.getStringContent(); |
|
85 } |
|
86 |
|
87 /** |
|
88 * Gets the <tt>wsa:To</tt> header. |
|
89 * |
|
90 * @return |
|
91 * null if the incoming SOAP message didn't have the header. |
|
92 */ |
|
93 @Property(WSA_TO) |
|
94 public WSEndpointReference getToAsReference() throws XMLStreamException { |
|
95 if (packet.getMessage() == null) { |
|
96 return null; |
|
97 } |
|
98 Header h = packet.getMessage().getHeaders().get(addressingVersion.toTag, false); |
|
99 if(h==null) return null; |
|
100 return new WSEndpointReference(h.getStringContent(),addressingVersion); |
|
101 } |
|
102 |
|
103 /** |
|
104 * Gets the <tt>wsa:From</tt> header. |
|
105 * |
|
106 * @return |
|
107 * null if the incoming SOAP message didn't have the header. |
|
108 */ |
|
109 @Property(JAXWSProperties.ADDRESSING_FROM) |
|
110 public WSEndpointReference getFrom() throws XMLStreamException { |
|
111 return getEPR(addressingVersion.fromTag); |
|
112 } |
|
113 |
|
114 /** |
|
115 * Gets the <tt>wsa:Action</tt> header content as String. |
|
116 * |
|
117 * @return |
|
118 * null if the incoming SOAP message didn't have the header. |
|
119 */ |
|
120 @Property(JAXWSProperties.ADDRESSING_ACTION) |
|
121 public String getAction() { |
|
122 if (packet.getMessage() == null) { |
|
123 return null; |
|
124 } |
|
125 Header h = packet.getMessage().getHeaders().get(addressingVersion.actionTag, false); |
|
126 if(h==null) return null; |
|
127 return h.getStringContent(); |
|
128 } |
|
129 |
|
130 /** |
|
131 * Gets the <tt>wsa:MessageID</tt> header content as String. |
|
132 * |
|
133 * @return |
|
134 * null if the incoming SOAP message didn't have the header. |
|
135 */ |
|
136 // WsaServerTube.REQUEST_MESSAGE_ID is exposed for backward compatibility with 2.1 |
|
137 @Property({JAXWSProperties.ADDRESSING_MESSAGEID,WsaServerTube.REQUEST_MESSAGE_ID}) |
|
138 public String getMessageID() { |
|
139 if (packet.getMessage() == null) { |
|
140 return null; |
|
141 } |
|
142 return AddressingUtils.getMessageID(packet.getMessage().getHeaders(), addressingVersion,soapVersion); |
|
143 } |
|
144 |
|
145 private WSEndpointReference getEPR(QName tag) throws XMLStreamException { |
|
146 if (packet.getMessage() == null) { |
|
147 return null; |
|
148 } |
|
149 Header h = packet.getMessage().getHeaders().get(tag, false); |
|
150 if(h==null) return null; |
|
151 return h.readAsEPR(addressingVersion); |
|
152 } |
|
153 |
|
154 protected PropertyMap getPropertyMap() { |
|
155 return model; |
|
156 } |
|
157 |
|
158 private static final PropertyMap model; |
|
159 static { |
|
160 model = parse(WsaPropertyBag.class); |
|
161 } |
|
162 |
|
163 private WSEndpointReference _replyToFromRequest = null; |
|
164 |
|
165 @Property(WSA_REPLYTO_FROM_REQUEST) |
|
166 public WSEndpointReference getReplyToFromRequest() { |
|
167 return _replyToFromRequest; |
|
168 } |
|
169 |
|
170 public void setReplyToFromRequest(WSEndpointReference ref) { |
|
171 _replyToFromRequest = ref; |
|
172 } |
|
173 |
|
174 private WSEndpointReference _faultToFromRequest = null; |
|
175 |
|
176 @Property(WSA_FAULTTO_FROM_REQUEST) |
|
177 public WSEndpointReference getFaultToFromRequest() { |
|
178 return _faultToFromRequest; |
|
179 } |
|
180 |
|
181 public void setFaultToFromRequest(WSEndpointReference ref) { |
|
182 _faultToFromRequest = ref; |
|
183 } |
|
184 |
|
185 private String _msgIdFromRequest = null; |
|
186 |
|
187 @Property(WSA_MSGID_FROM_REQUEST) |
|
188 public String getMessageIdFromRequest() { |
|
189 return _msgIdFromRequest; |
|
190 } |
|
191 |
|
192 public void setMessageIdFromRequest(String id) { |
|
193 _msgIdFromRequest = id; |
|
194 } |
|
195 } |