1 17 package org.apache.sandesha.ws.rm.providers; 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.handlers.soap.SOAPService; 23 import org.apache.axis.message.SOAPEnvelope; 24 import org.apache.axis.message.addressing.Action; 25 import org.apache.axis.message.addressing.AddressingHeaders; 26 import org.apache.axis.providers.java.RPCProvider; 27 import org.apache.commons.logging.Log; 28 import org.apache.sandesha.Constants; 29 import org.apache.sandesha.IStorageManager; 30 import org.apache.sandesha.RMMessageContext; 31 import org.apache.sandesha.SandeshaContext; 32 import org.apache.sandesha.server.MessageValidator; 33 import org.apache.sandesha.server.RMMessageProcessorIdentifier; 34 import org.apache.sandesha.server.msgprocessors.FaultProcessor; 35 import org.apache.sandesha.server.msgprocessors.IRMMessageProcessor; 36 import org.apache.sandesha.storage.Callback; 37 import org.apache.sandesha.storage.CallbackData; 38 import org.apache.sandesha.ws.rm.RMHeaders; 39 40 import java.util.ArrayList ; 41 import java.util.Hashtable ; 42 import java.util.Iterator ; 43 import java.util.List ; 44 45 52 53 public class RMProvider extends RPCProvider { 54 55 private boolean client; 56 private static final Log log = LogFactory.getLog(RMProvider.class.getName()); 57 private static Callback callback = null; 58 59 public static void setCallback(Callback cb) { 60 callback = cb; 61 } 62 63 public static void removeCallback() { 64 callback = null; 65 } 66 67 public void processMessage(MessageContext msgContext, SOAPEnvelope reqEnv, SOAPEnvelope resEnv, 68 Object obj) throws Exception { 69 if (log.isDebugEnabled()) 70 RMProvider.log.debug(Constants.InfomationMessage.PROVIDER_RECEIVED_MSG); 71 75 76 if (isIgnorableMessage(msgContext)) { 77 RPCProvider rpcProvider = new RPCProvider(); 78 rpcProvider.invoke(msgContext); 79 } else { 80 IStorageManager storageManager = SandeshaContext.init(client); 81 storageManager.init(); 82 83 RMMessageContext rmMessageContext = new RMMessageContext(); 84 rmMessageContext.setMsgContext(msgContext); 85 try { 86 MessageValidator.validate(rmMessageContext, client); 87 } catch (AxisFault af) { 88 FaultProcessor faultProcessor = new FaultProcessor(storageManager, af); 89 if (!faultProcessor.sendFault(rmMessageContext)) { 90 msgContext.setPastPivot(true); 91 msgContext.setResponseMessage(null); 92 return; 93 } 94 return; 95 } 96 RMHeaders rmHeaders = rmMessageContext.getRMHeaders(); 97 AddressingHeaders addrHeaders = rmMessageContext.getAddressingHeaders(); 98 99 if (null != rmHeaders.getSequence()) { 100 rmMessageContext.setSequenceID(rmHeaders.getSequence().getIdentifier().toString()); 101 if (null != rmHeaders.getSequence().getLastMessage()) { 102 rmMessageContext.setLastMessage(true); 103 } 104 } 105 106 if (addrHeaders.getMessageID() == null) { 107 rmMessageContext.setMessageID((new Long (System.currentTimeMillis())).toString()); 108 } else { 109 rmMessageContext.setMessageID(addrHeaders.getMessageID().toString()); 110 } 111 112 IRMMessageProcessor rmMessageProcessor = RMMessageProcessorIdentifier.getMessageProcessor(rmMessageContext, storageManager); 113 114 if (callback != null) { 115 CallbackData cbData = getCallbackData(rmMessageContext); 116 callback.onIncomingMessage(cbData); 117 } 118 119 try { 120 if (!rmMessageProcessor.processMessage(rmMessageContext)) { 121 msgContext.setPastPivot(true); 122 msgContext.setResponseMessage(null); 123 } else { 124 msgContext.setPastPivot(true); 125 } 126 } catch (AxisFault af) { 127 RMProvider.log.error(af); 128 FaultProcessor faultProcessor = new FaultProcessor(storageManager, af); 129 if (!faultProcessor.sendFault(rmMessageContext)) { 130 msgContext.setPastPivot(true); 131 msgContext.setResponseMessage(null); 132 return; 133 } 134 return; 135 } 136 } 137 } 138 139 public void setClient(boolean client) { 142 this.client = client; 143 } 144 145 private boolean isIgnorableMessage(MessageContext msgContext) throws Exception { 146 boolean result = false; 147 AddressingHeaders addrH = new AddressingHeaders(msgContext.getRequestMessage().getSOAPEnvelope()); 148 List lst = getIgnorableActions(msgContext); 149 if (lst != null && addrH.getAction() != null) { 150 Iterator ite = lst.iterator(); 151 while (ite.hasNext()) { 152 String str = (String ) ite.next(); 153 if (str.equals(addrH.getAction().toString())) 154 result = true; 155 } 156 } 157 158 return result; 159 } 160 161 private List getIgnorableActions(MessageContext msgContext) { 162 SOAPService soapService = msgContext.getService(); 163 Hashtable options = soapService.getOptions(); 164 Iterator ite = options.keySet().iterator(); 165 List actionList = new ArrayList (); 166 while (ite.hasNext()) { 167 String key = (String ) ite.next(); 168 169 if (key.regionMatches(0, Constants.IGNORE_ACTION, 0, Constants.IGNORE_ACTION.length())) 170 actionList.add(options.get(key)); 171 } 172 return actionList; 173 } 174 175 177 private CallbackData getCallbackData(RMMessageContext rmMsgContext) { 178 CallbackData cbData = new CallbackData(); 179 180 cbData.setSequenceId(rmMsgContext.getSequenceID()); 182 cbData.setMessageId(rmMsgContext.getMessageID()); 183 cbData.setMessageType(rmMsgContext.getMessageType()); 184 185 Action action = rmMsgContext.getAddressingHeaders().getAction(); 186 if (action != null) { 187 cbData.setAction(action.toString()); 188 } 189 190 return cbData; 191 } 192 194 } | Popular Tags |