1 17 18 package org.apache.sandesha.server; 19 20 import org.apache.axis.MessageContext; 21 import org.apache.axis.components.logger.LogFactory; 22 import org.apache.axis.components.uuid.UUIDGen; 23 import org.apache.axis.components.uuid.UUIDGenFactory; 24 import org.apache.axis.message.addressing.AddressingHeaders; 25 import org.apache.commons.logging.Log; 26 import org.apache.sandesha.Constants; 27 import org.apache.sandesha.IStorageManager; 28 import org.apache.sandesha.RMMessageContext; 29 import org.apache.sandesha.util.RMMessageCreator; 30 31 36 public class RMInvokerWork { 37 38 private IStorageManager storageManager; 39 private static final Log log = LogFactory.getLog(RMInvokerWork.class.getName()); 40 private static final UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); 41 private InvokeHandler invoker = null; 42 43 public RMInvokerWork() { 44 setStorageManager(new ServerStorageManager()); 45 getStorageManager().init(); 46 } 47 48 49 protected boolean doRealInvoke(MessageContext aMessageContext) throws Exception { 50 if (invoker == null) { 51 invoker = InvokerFactory.getInstance().createInvokeHandler(); 52 } 53 return invoker.handleInvoke(aMessageContext); 54 } 55 56 57 public void executeInvoke() throws Exception { 58 59 Object seq = getStorageManager().getNextSeqToProcess(); 60 if (seq != null) { 61 synchronized (seq) { 62 RMMessageContext rmMessageContext = getStorageManager().getNextMessageToProcess(seq); 63 doWork(rmMessageContext); 64 } 65 } 66 } 67 68 69 72 protected void setStorageManager(IStorageManager storageManager) { 73 this.storageManager = storageManager; 74 } 75 76 79 protected IStorageManager getStorageManager() { 80 return storageManager; 81 } 82 83 protected void doWork(RMMessageContext rmMessageContext) throws Exception { 84 if (rmMessageContext != null) { 85 AddressingHeaders addrHeaders = rmMessageContext.getAddressingHeaders(); 86 boolean isVoid = doRealInvoke(rmMessageContext.getMsgContext()); 87 88 if (!isVoid) { 89 90 String oldAction = rmMessageContext.getAddressingHeaders().getAction() 91 .toString(); 92 rmMessageContext.getAddressingHeaders().setAction(oldAction + Constants.RESPONSE); 93 if (rmMessageContext.isLastMessage()) { 94 if (addrHeaders.getReplyTo() != null) { 96 String replyTo = addrHeaders.getReplyTo().getAddress().toString(); 97 RMMessageContext terminateMsg = RMMessageCreator.createTerminateSeqMsg(rmMessageContext, Constants.SERVER); 98 terminateMsg.setOutGoingAddress(replyTo); 99 getStorageManager().insertTerminateSeqMessage(terminateMsg); 100 } else { 101 RMInvokerWork.log.error(Constants.ErrorMessages.CANNOT_SEND_THE_TERMINATE_SEQ); 102 } 103 } 104 rmMessageContext.setMessageType(Constants.MSG_TYPE_SERVICE_RESPONSE); 109 110 boolean hasResponseSeq = getStorageManager().isResponseSequenceExist(rmMessageContext.getSequenceID()); 111 boolean firstMsgOfResponseSeq = false; 112 if (!(hasResponseSeq && rmMessageContext.getRMHeaders().getSequence() 113 .getMessageNumber().getMessageNumber() == 1)) { 114 firstMsgOfResponseSeq = !hasResponseSeq; 115 } 116 117 rmMessageContext.setMsgNumber(getStorageManager().getNextMessageNumber(rmMessageContext.getSequenceID())); 118 getStorageManager().insertOutgoingMessage(rmMessageContext); 119 120 121 if (firstMsgOfResponseSeq) { 122 String msgIdStr = Constants.UUID + RMInvokerWork.uuidGen.nextUUID(); 123 124 RMMessageContext csRMMsgCtx = RMMessageCreator.createCreateSeqMsg(rmMessageContext, Constants.SERVER, msgIdStr, null); 125 csRMMsgCtx.setOutGoingAddress(rmMessageContext.getAddressingHeaders() 126 .getReplyTo().getAddress().toString()); 127 128 csRMMsgCtx.addToMsgIdList(msgIdStr); 129 csRMMsgCtx.setMessageID(msgIdStr); 130 131 getStorageManager().setTemporaryOutSequence(csRMMsgCtx.getSequenceID(), 132 msgIdStr); 133 getStorageManager().addCreateSequenceRequest(csRMMsgCtx); 134 } 135 } 136 } 137 } 138 } 139 | Popular Tags |