1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.sandesha;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.MessageContext;
21 import org.apache.axis.components.logger.LogFactory;
22 import org.apache.axis.message.addressing.AddressingHeaders;
23 import org.apache.commons.logging.Log;
24 import org.apache.sandesha.util.PolicyLoader;
25 import org.apache.sandesha.ws.rm.RMHeaders;
26
27 import java.util.ArrayList;
28 import java.util.Iterator;
29
30 /***
31 * RMMessageContext is used as the message context for Sandesha. It will carry all the required
32 * paramerters through the processing logics including the MessageContext handed over by the
33 * axis engine.
34 *
35 * @author Jaliya Ekanayake
36 * @author Chamikara Jayalath
37 */
38 public class RMMessageContext {
39 private static final Log log = LogFactory.getLog(RMMessageContext.class.getName());
40
41 private MessageContext msgContext;
42 private String sequenceID;
43 private String messageID;
44 private AddressingHeaders addressingHeaders;
45 private RMHeaders rmHeaders;
46 private String outGoingAddress;
47 private int messageType;
48 private long reTransmissionCount;
49 private long lastPrecessedTime;
50 private long fristProcessedTime;
51 private long retransmissionTime;
52
53 private boolean locked;
54
55 private long lastSentTime;
56 private boolean sync;
57 private boolean hasResponse;
58 private boolean lastMessage;
59 private long msgNumber;
60 private String sourceURL;
61 private String action;
62 private String from;
63 private String replyTo;
64
65 private boolean ackReceived;
66 private String faultTo;
67 private String acksTo;
68 private String to;
69
70 public SandeshaContext getCtx() {
71 return ctx;
72 }
73
74 public void setCtx(SandeshaContext ctx) {
75 this.ctx = ctx;
76 }
77
78 private SandeshaContext ctx;
79
80 public boolean isLocked() {
81 return locked;
82 }
83
84 public void setLocked(boolean locked) {
85 this.locked = locked;
86 }
87
88 public long getFristProcessedTime() {
89 return fristProcessedTime;
90 }
91
92 public void setFristProcessedTime(long fristProcessedTime) {
93 this.fristProcessedTime = fristProcessedTime;
94 }
95
96 public long getRetransmissionTime() {
97 return retransmissionTime;
98 }
99
100 public void setRetransmissionTime(long retransmissionTime) {
101 this.retransmissionTime = retransmissionTime;
102 }
103
104 public RMMessageContext() {
105 retransmissionTime = PolicyLoader.getInstance().getBaseRetransmissionInterval();
106 fristProcessedTime = 0;
107 }
108
109 public boolean isSendOffer() {
110 return sendOffer;
111 }
112
113 public void setSendOffer(boolean sendOffer) {
114 this.sendOffer = sendOffer;
115 }
116
117 private boolean sendOffer;
118
119
120 private ArrayList msgIdList = new ArrayList();
121
122 public void addToMsgIdList(String msgId) {
123 msgIdList.add(msgId);
124 }
125
126 public ArrayList getMessageIdList() {
127 return msgIdList;
128 }
129
130 public String getTo() {
131 return to;
132 }
133
134 public void setTo(String to) {
135 this.to = to;
136 }
137
138 public String getAcksTo() {
139 return acksTo;
140 }
141
142 public void setAcksTo(String acksTo) {
143 this.acksTo = acksTo;
144 }
145
146
147 public String getFrom() {
148 return from;
149 }
150
151 public void setFrom(String from) {
152 this.from = from;
153 }
154
155 public String getReplyTo() {
156 return replyTo;
157 }
158
159 public void setReplyTo(String replyTo) {
160 this.replyTo = replyTo;
161 }
162
163 public String getAction() {
164 return action;
165 }
166
167 public void setAction(String action) {
168 this.action = action;
169 }
170
171 private String oldSequenceID;
172
173
174 public boolean isHasResponse() {
175 return hasResponse;
176 }
177
178 public void setHasResponse(boolean hasResponse) {
179 this.hasResponse = hasResponse;
180 }
181
182 public boolean isLastMessage() {
183 return lastMessage;
184 }
185
186 public void setLastMessage(boolean lastMessage) {
187 this.lastMessage = lastMessage;
188 }
189
190 public String getSourceURL() {
191 return sourceURL;
192 }
193
194 public void setSourceURL(String sourceURL) {
195 this.sourceURL = sourceURL;
196 }
197
198 public long getMsgNumber() {
199 return msgNumber;
200 }
201
202
203 public void setMsgNumber(long msgNumber) {
204 this.msgNumber = msgNumber;
205 }
206
207 public String getOldSequenceID() {
208 return oldSequenceID;
209 }
210
211 public void setOldSequenceID(String oldSequenceID) {
212 this.oldSequenceID = oldSequenceID;
213 }
214
215 public boolean isAckReceived() {
216 return ackReceived;
217 }
218
219 public void setAckReceived(boolean ackReceived) {
220 this.ackReceived = ackReceived;
221 }
222
223 public MessageContext getMsgContext() {
224 return msgContext;
225 }
226
227 public String getSequenceID() {
228 return sequenceID;
229 }
230
231 public void setMsgContext(MessageContext msgContext) {
232 this.msgContext = msgContext;
233 }
234
235 public void setSequenceID(String sequenceID) {
236 this.sequenceID = sequenceID;
237 }
238
239 public String getMessageID() {
240 return messageID;
241 }
242
243 public void setMessageID(String string) {
244 messageID = string;
245 }
246
247 public AddressingHeaders getAddressingHeaders() {
248 return addressingHeaders;
249 }
250
251 public RMHeaders getRMHeaders() {
252 return rmHeaders;
253 }
254
255 public void setAddressingHeaders(AddressingHeaders addressingHeaders) {
256 this.addressingHeaders = addressingHeaders;
257 }
258
259 public void setRMHeaders(RMHeaders rmHeaders) {
260 this.rmHeaders = rmHeaders;
261 }
262
263 public String getOutGoingAddress() {
264 return outGoingAddress;
265 }
266
267 public void setOutGoingAddress(String outGoingAddress) {
268 this.outGoingAddress = outGoingAddress;
269 }
270
271
272 public int getMessageType() {
273 return messageType;
274 }
275
276
277 public void setMessageType(int messageType) {
278 this.messageType = messageType;
279 }
280
281 public void copyContents(RMMessageContext rmMsgContext) {
282 if (addressingHeaders != null)
283 rmMsgContext.setAddressingHeaders(addressingHeaders);
284 if (messageID != null)
285 rmMsgContext.setMessageID(messageID);
286 if (rmHeaders != null)
287 rmMsgContext.setRMHeaders(rmHeaders);
288 if (sequenceID != null)
289 rmMsgContext.setSequenceID(sequenceID);
290 if (outGoingAddress != null)
291 rmMsgContext.setOutGoingAddress(outGoingAddress);
292 if (msgContext != null)
293 rmMsgContext.setMsgContext(msgContext);
294 if (acksTo != null)
295 rmMsgContext.setAcksTo(acksTo);
296 if (to != null)
297 rmMsgContext.setTo(to);
298
299 rmMsgContext.setReTransmissionCount(reTransmissionCount);
300 rmMsgContext.setLastPrecessedTime(lastPrecessedTime);
301 rmMsgContext.setLastMessage(isLastMessage());
302
303 }
304
305 public long getLastPrecessedTime() {
306 return lastPrecessedTime;
307 }
308
309
310 public long getReTransmissionCount() {
311 return reTransmissionCount;
312 }
313
314 public void setLastPrecessedTime(long lastPrecessedTime) {
315 this.lastPrecessedTime = lastPrecessedTime;
316 }
317
318 public void setReTransmissionCount(long reTransmissionCount) {
319 this.reTransmissionCount = reTransmissionCount;
320 }
321
322 /***
323 * This method will copy the contents of one MessageContext to another.
324 *
325 * @param msgContext1
326 * @param msgContext2
327 */
328 public static void copyMessageContext(MessageContext msgContext1, MessageContext msgContext2) {
329
330 try {
331 if (msgContext1.getClassLoader() != null)
332 msgContext2.setClassLoader(msgContext1.getClassLoader());
333
334 if (msgContext1.getEncodingStyle() != null)
335 msgContext2.setEncodingStyle(msgContext1.getEncodingStyle());
336
337 if (msgContext1.getPassword() != null)
338 msgContext2.setPassword(msgContext1.getPassword());
339
340 if (msgContext1.getRoles() != null)
341 msgContext2.setRoles(msgContext1.getRoles());
342
343 if (msgContext1.getSchemaVersion() != null)
344 msgContext2.setSchemaVersion(msgContext1.getSchemaVersion());
345
346 if (msgContext1.getSession() != null)
347 msgContext2.setSession(msgContext1.getSession());
348
349 if (msgContext1.getSession() != null)
350 msgContext2.setSession(msgContext1.getSession());
351
352 if (msgContext1.getSOAPActionURI() != null)
353 msgContext2.setSOAPActionURI(msgContext1.getSOAPActionURI());
354
355 if (msgContext1.getSOAPConstants() != null)
356 msgContext2.setSOAPConstants(msgContext1.getSOAPConstants());
357
358 if (msgContext1.getTargetService() != null)
359 msgContext2.setTargetService(msgContext1.getTargetService());
360
361 if (msgContext1.getTransportName() != null)
362 msgContext2.setTransportName(msgContext1.getTransportName());
363
364 if (msgContext1.getTypeMappingRegistry() != null)
365 msgContext2.setTypeMappingRegistry(msgContext1.getTypeMappingRegistry());
366
367 if (msgContext1.getUsername() != null)
368 msgContext2.setUsername(msgContext1.getUsername());
369
370 if (msgContext1.getAllPropertyNames() != null) {
371 Iterator ite = msgContext1.getAllPropertyNames();
372 while (ite.hasNext()) {
373 String str = (String) ite.next();
374 msgContext2.setProperty(str, msgContext1.getProperty(str));
375 }
376 }
377
378 msgContext2.setTimeout(msgContext1.getTimeout());
379 msgContext2.setUseSOAPAction(msgContext1.useSOAPAction());
380 msgContext2.setPastPivot(msgContext1.getPastPivot());
381 msgContext2.setHighFidelity(msgContext1.isHighFidelity());
382 msgContext2.setMaintainSession(msgContext1.getMaintainSession());
383
384 } catch (AxisFault e) {
385 RMMessageContext.log.error(e);
386 }
387
388 }
389
390 public long getLastSentTime() {
391 return lastSentTime;
392 }
393
394 public void setLastSentTime(long l) {
395 lastSentTime = l;
396 }
397
398
399 public void setSync(boolean sync) {
400 this.sync = sync;
401
402 }
403
404 public boolean getSync() {
405
406 return sync;
407 }
408
409 public void setFaultTo(String faultTo) {
410 this.faultTo = faultTo;
411 }
412
413 public String getFaultTo() {
414 return faultTo;
415 }
416 }