KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > ws > rm > RMPersistenceHandler


1 package org.objectweb.celtix.bus.ws.rm;
2
3 import java.math.BigInteger JavaDoc;
4 import java.util.Set JavaDoc;
5 import java.util.logging.Logger JavaDoc;
6
7 import javax.annotation.Resource;
8 import javax.xml.namespace.QName JavaDoc;
9 import javax.xml.ws.handler.MessageContext;
10 import javax.xml.ws.handler.soap.SOAPHandler;
11 import javax.xml.ws.handler.soap.SOAPMessageContext;
12
13 import org.objectweb.celtix.bindings.AbstractBindingBase;
14 import org.objectweb.celtix.bindings.ClientBinding;
15 import org.objectweb.celtix.bindings.JAXWSConstants;
16 import org.objectweb.celtix.bindings.ServerBinding;
17 import org.objectweb.celtix.bus.ws.addressing.AddressingPropertiesImpl;
18 import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
19 import org.objectweb.celtix.bus.ws.addressing.VersionTransformer;
20 import org.objectweb.celtix.common.logging.LogUtils;
21 import org.objectweb.celtix.ws.rm.Identifier;
22
23
24 public class RMPersistenceHandler implements SOAPHandler<SOAPMessageContext> {
25     
26     private static final Logger JavaDoc LOG = LogUtils.getL7dLogger(RMPersistenceHandler.class);
27     
28     @Resource(name = JAXWSConstants.CLIENT_BINDING_PROPERTY) private ClientBinding clientBinding;
29     @Resource(name = JAXWSConstants.SERVER_BINDING_PROPERTY) private ServerBinding serverBinding;
30     
31     public Set JavaDoc<QName JavaDoc> getHeaders() {
32         return null;
33     }
34
35     public void close(MessageContext arg0) {
36     }
37
38     public boolean handleFault(SOAPMessageContext context) {
39         if (ContextUtils.isOutbound(context)) {
40             handleOutbound(context);
41         }
42         return true;
43     }
44
45     public boolean handleMessage(SOAPMessageContext context) {
46         if (ContextUtils.isOutbound(context)) {
47             handleOutbound(context);
48         }
49         return true;
50     }
51     
52     void handleOutbound(SOAPMessageContext context) {
53         LOG.entering(getClass().getName(), "handleOutbound");
54         // do nothing unless this is an application message
55
if (!isApplicationMessage(context)) {
56             return;
57         }
58         
59         // tell the source to store a copy of the message in the
60
// retransmission queue
61
// and schedule the next retransmission
62

63         RMPropertiesImpl rmpsOut =
64             (RMPropertiesImpl)RMContextUtils.retrieveRMProperties(context, true);
65         // assert null != rmpsOut;
66

67         if (null == rmpsOut) {
68             // handler chain traversal may have been reversed before
69
// reaching RM logical handler - OK to ignore?
70
return;
71         }
72         
73         if (null == rmpsOut.getSequence()) {
74             // cannot be an application message (may be a partial response)
75
return;
76         }
77         
78         BigInteger JavaDoc mn = rmpsOut.getSequence().getMessageNumber();
79         boolean lm = null != rmpsOut.getSequence().getLastMessage();
80         Identifier sid = rmpsOut.getSequence().getIdentifier();
81         
82         // create a new SourceSequence object instead of retrieving the one
83
// maintained by the RM source for the sequence identifier
84
// as the current/last message number properties of the latter may have
85
// changed since
86

87         SourceSequence seq = new SourceSequence(sid, null, null, mn, lm);
88         RMHandler handler = RMHandler.getHandler(getBinding());
89         RMMessageImpl msg = new RMMessageImpl(mn, context);
90
91         handler.getSource().addUnacknowledged(seq, msg);
92     }
93     
94     AbstractBindingBase getBinding() {
95         if (null != clientBinding) {
96             return (AbstractBindingBase)clientBinding;
97         }
98         return (AbstractBindingBase)serverBinding;
99     }
100     
101     private boolean isApplicationMessage(SOAPMessageContext context) {
102         boolean isApplicationMessage = true;
103         AddressingPropertiesImpl maps =
104             ContextUtils.retrieveMAPs(context, false, true);
105         
106         if (null == maps) {
107             return false;
108         }
109       
110         // ensure the appropriate version of WS-Addressing is used
111
maps.exposeAs(VersionTransformer.Names200408.WSA_NAMESPACE_NAME);
112
113         String JavaDoc action = null;
114         if (maps != null && null != maps.getAction()) {
115             action = maps.getAction().getValue();
116         }
117         if (RMUtils.getRMConstants().getCreateSequenceAction().equals(action)
118             || RMUtils.getRMConstants().getCreateSequenceResponseAction().equals(action)
119             || RMUtils.getRMConstants().getTerminateSequenceAction().equals(action)
120             || RMUtils.getRMConstants().getLastMessageAction().equals(action)
121             || RMUtils.getRMConstants().getSequenceAcknowledgmentAction().equals(action)
122             || RMUtils.getRMConstants().getSequenceInfoAction().equals(action)) {
123             isApplicationMessage = false;
124         }
125         return isApplicationMessage;
126     }
127    
128     
129 }
130
Popular Tags