1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ws.addressing.handler;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.StringTokenizer;
22
23 import javax.xml.namespace.QName;
24 import javax.xml.rpc.JAXRPCException;
25 import javax.xml.rpc.handler.GenericHandler;
26 import javax.xml.rpc.handler.HandlerInfo;
27 import javax.xml.rpc.handler.MessageContext;
28
29 import org.apache.axis.message.addressing.Constants;
30 import org.apache.axis.message.addressing.MessageID;
31 import org.apache.axis.types.URI;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.apache.ws.addressing.uuid.UUIdGeneratorFactory;
35
36
37
38
39
40
41
42
43
44 public abstract class AbstractAddressingHandler extends GenericHandler {
45
46
47
48
49 public static final String CONFIG_PROP_ACTOR = "actor";
50
51
52
53
54 public static final String CONFIG_PROP_REFERENCE_PROPERTY_NAMES
55 = "referencePropertyNames";
56
57
58
59
60 public static final String CONFIG_PROP_REMOVE_HEADERS = "removeHeaders";
61
62
63
64
65 static final String UUID_URI_SCHEME = "uuid";
66
67
68
69
70 private static final QName[] UNDERSTOOD_HEADERS = new QName[] {
71 new QName(Constants.NS_URI_ADDRESSING_2003_03, Constants.ACTION),
72 new QName(Constants.NS_URI_ADDRESSING_2003_03, Constants.FAULT_TO),
73 new QName(Constants.NS_URI_ADDRESSING_2003_03, Constants.FROM),
74 new QName(Constants.NS_URI_ADDRESSING_2003_03, Constants.MESSAGE_ID),
75 new QName(Constants.NS_URI_ADDRESSING_2003_03, Constants.RECIPIENT),
76 new QName(Constants.NS_URI_ADDRESSING_2003_03, Constants.RELATES_TO),
77 new QName(Constants.NS_URI_ADDRESSING_2003_03, Constants.REPLY_TO),
78 new QName(Constants.NS_URI_ADDRESSING_2003_03, Constants.TO),
79 new QName(Constants.NS_URI_ADDRESSING_2004_03, Constants.ACTION),
80 new QName(Constants.NS_URI_ADDRESSING_2004_03, Constants.FAULT_TO),
81 new QName(Constants.NS_URI_ADDRESSING_2004_03, Constants.FROM),
82 new QName(Constants.NS_URI_ADDRESSING_2004_03, Constants.MESSAGE_ID),
83 new QName(Constants.NS_URI_ADDRESSING_2004_03, Constants.RECIPIENT),
84 new QName(Constants.NS_URI_ADDRESSING_2004_03, Constants.RELATES_TO),
85 new QName(Constants.NS_URI_ADDRESSING_2004_03, Constants.REPLY_TO),
86 new QName(Constants.NS_URI_ADDRESSING_2004_03, Constants.TO),
87 new QName(Constants.NS_URI_ADDRESSING_2004_08, Constants.ACTION),
88 new QName(Constants.NS_URI_ADDRESSING_2004_08, Constants.FAULT_TO),
89 new QName(Constants.NS_URI_ADDRESSING_2004_08, Constants.FROM),
90 new QName(Constants.NS_URI_ADDRESSING_2004_08, Constants.MESSAGE_ID),
91 new QName(Constants.NS_URI_ADDRESSING_2004_08, Constants.RECIPIENT),
92 new QName(Constants.NS_URI_ADDRESSING_2004_08, Constants.RELATES_TO),
93 new QName(Constants.NS_URI_ADDRESSING_2004_08, Constants.REPLY_TO),
94 new QName(Constants.NS_URI_ADDRESSING_2004_08, Constants.TO)
95 };
96
97
98
99
100 protected static final boolean CONTINUE_HANDLER_CHAIN_PROCESSING = true;
101
102
103
104
105 private static final Log LOG = LogFactory.getLog(AbstractAddressingHandler.class);
106
107
108
109
110 private Map<String, String> handlerConfigProps;
111
112
113
114
115 private List<QName> refPropQNames;
116
117
118
119
120
121
122 public QName[] getHeaders() {
123 return UNDERSTOOD_HEADERS.clone();
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 @SuppressWarnings("unchecked")
144 @Override
145 public void init(HandlerInfo handlerInfo) {
146 super.init(handlerInfo);
147 LOG.info("Initializing JAX-RPC handler " + this.getClass().getName() + "...");
148 handlerConfigProps = handlerInfo.getHandlerConfig();
149 initReferencePropertyQNames();
150 }
151
152
153
154
155
156
157 protected Map<String, String> getHandlerConfigProperties() {
158 return handlerConfigProps;
159 }
160
161
162
163
164
165
166
167
168
169 protected String getHandlerConfigProperty(String propName) {
170 return (String) getHandlerConfigProperties().get(propName);
171 }
172
173
174
175
176
177
178
179
180
181
182
183 protected boolean isHandlerConfigPropertyTrue(String propName) {
184 return Boolean.TRUE.toString().equalsIgnoreCase(getHandlerConfigProperty(propName));
185 }
186
187
188
189
190
191
192
193
194 protected String generateUUId() {
195 try {
196 return UUIdGeneratorFactory.getGenerator().generateUUId();
197 } catch (RuntimeException re) {
198 throw new JAXRPCException("Failed to generate UUId using default UUId generator",
199 re);
200 }
201 }
202
203
204
205
206
207
208
209 protected boolean isMustUnderstandEnabled(MessageContext msgContext) {
210 return isPropertyTrue(msgContext, Constants.ENV_ADDRESSING_SET_MUST_UNDERSTAND);
211 }
212
213
214
215
216
217
218
219
220 protected boolean isPropertyTrue(MessageContext msgContext, String propName) {
221 return Boolean.TRUE.toString().equals(msgContext.getProperty(propName));
222 }
223
224
225
226
227
228
229
230 protected MessageID createMessageID() throws URI.MalformedURIException {
231 return new MessageID(new URI(UUID_URI_SCHEME + ":" + generateUUId()));
232 }
233
234
235
236
237
238
239 protected List<QName> getReferencePropertyQNames() {
240 return refPropQNames;
241 }
242
243
244
245
246
247
248 protected String getActor() {
249 return getHandlerConfigProperty(CONFIG_PROP_ACTOR);
250 }
251
252
253
254
255
256
257 protected boolean isRemoveHeadersEnabled() {
258 return isHandlerConfigPropertyTrue(CONFIG_PROP_REMOVE_HEADERS);
259 }
260
261
262
263
264
265
266 protected void initReferencePropertyQNames() {
267 String refPropNamesConfigPropValue
268 = getHandlerConfigProperty(CONFIG_PROP_REFERENCE_PROPERTY_NAMES);
269
270 if (refPropNamesConfigPropValue == null) {
271 LOG.debug("No reference properties will be processed.");
272 refPropQNames = new ArrayList<QName>();
273 } else if (refPropNamesConfigPropValue.equals("*")) {
274 LOG.debug("All reference properties will be processed.");
275 refPropQNames = null;
276 } else {
277 refPropQNames = new ArrayList<QName>();
278 StringTokenizer tokenizer = new StringTokenizer(refPropNamesConfigPropValue, ",");
279 while (tokenizer.hasMoreTokens()) {
280 String qnameString = tokenizer.nextToken().trim();
281 try {
282 QName qname = QName.valueOf(qnameString);
283 LOG.debug("Reference properties with QName '" + qnameString
284 + "' will be processed.");
285 refPropQNames.add(qname);
286 } catch (IllegalArgumentException iae) {
287 LOG.warn("Invalid QName '" + qnameString + "' specified in handler config.");
288 }
289 }
290 }
291 }
292
293 }