1 17 package org.apache.sandesha.server.msgprocessors; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.Message; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.components.uuid.UUIDGen; 23 import org.apache.axis.components.uuid.UUIDGenFactory; 24 import org.apache.axis.message.SOAPEnvelope; 25 import org.apache.axis.message.addressing.AddressingHeaders; 26 import org.apache.sandesha.Constants; 27 import org.apache.sandesha.EnvelopeCreator; 28 import org.apache.sandesha.IStorageManager; 29 import org.apache.sandesha.RMMessageContext; 30 import org.apache.sandesha.ws.rm.CreateSequence; 31 import org.apache.sandesha.ws.rm.Identifier; 32 import org.apache.sandesha.ws.rm.RMHeaders; 33 import org.apache.sandesha.ws.rm.SequenceOffer; 34 35 40 public class CreateSequenceProcessor implements IRMMessageProcessor { 41 IStorageManager storageManager; 42 43 public UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); 44 45 public CreateSequenceProcessor(IStorageManager storageManager) { 46 this.storageManager = storageManager; 47 } 48 49 public boolean processMessage(RMMessageContext rmMessageContext) throws AxisFault { 50 51 AddressingHeaders addrHeaders = rmMessageContext.getAddressingHeaders(); 52 RMHeaders rmHeaders = rmMessageContext.getRMHeaders(); 53 54 if (rmHeaders.getSequenceAcknowledgement() != null) { 55 processForAckIfAny(rmMessageContext); 56 } 57 58 if (rmHeaders.getCreateSequence() == null) 60 throw new AxisFault(); 61 62 String seqId = getNextUUID(); 63 storageManager.addRequestedSequence(seqId); 64 65 66 CreateSequence createSeq = rmMessageContext.getRMHeaders().getCreateSequence(); 67 if (createSeq.getAcksTo() != null) { 69 storageManager.setAcksTo(seqId, createSeq.getAcksTo().getAddress().toString()); 70 } 71 72 SequenceOffer offer = createSeq.getOffer(); 74 boolean offerAccepted = false; 75 boolean hasOffer = false; 76 if (offer != null) { 77 hasOffer = true; 78 offerAccepted = acceptOrRejectOffer(offer); 79 if (offerAccepted) { 80 String responseSeqId = null; 81 if (offer != null) { 82 Identifier id = offer.getIdentifier(); 83 if (id != null) 84 responseSeqId = id.getIdentifier(); 85 } 86 String incomingSeqId = seqId; 87 if (responseSeqId != null) { 88 storageManager.addOutgoingSequence(incomingSeqId); 89 storageManager.setTemporaryOutSequence(incomingSeqId, responseSeqId); 90 storageManager.setApprovedOutSequence(responseSeqId, responseSeqId); 91 } 93 } 94 } 95 96 setOutGoingAddress(rmMessageContext, addrHeaders); 97 98 SOAPEnvelope resEnvelope; 99 try { 100 resEnvelope = EnvelopeCreator.createCreateSequenceResponseEnvelope(seqId, 101 rmMessageContext, hasOffer, offerAccepted); 102 } catch (Exception e) { 103 throw new AxisFault(org.apache.sandesha.Constants.FaultCodes.WSRM_SERVER_INTERNAL_ERROR); 104 } 105 rmMessageContext.setMessageType(org.apache.sandesha.Constants.MSG_TYPE_CREATE_SEQUENCE_RESPONSE); 106 107 if (rmMessageContext.getSync()) { 108 rmMessageContext.getMsgContext().setResponseMessage(new Message(resEnvelope)); 109 return true; 110 111 } else { 112 MessageContext msgContext = new MessageContext(rmMessageContext.getMsgContext().getAxisEngine()); 113 msgContext.setResponseMessage(new Message(resEnvelope)); 114 rmMessageContext.setMsgContext(msgContext); 115 116 rmMessageContext.setSync(false); 117 storageManager.addCreateSequenceResponse(rmMessageContext); 118 return false; 119 } 120 121 } 122 123 private synchronized String getNextUUID() { 124 return Constants.UUID + uuidGen.nextUUID(); 125 } 126 127 private boolean acceptOrRejectOffer(SequenceOffer offer) { 129 return true; 130 } 131 132 private void processForAckIfAny(RMMessageContext rmMsgCtx) throws AxisFault { 133 AcknowledgementProcessor ackProcessor = new AcknowledgementProcessor(storageManager); 134 ackProcessor.processMessage(rmMsgCtx); 135 } 136 137 private void setOutGoingAddress(RMMessageContext rmMsgCtx, AddressingHeaders addrHeaders) { 138 139 if (addrHeaders.getReplyTo() == null || addrHeaders.getReplyTo().getAddress().toString() 140 .equals(Constants.WSA.NS_ADDRESSING_ANONYMOUS)) { 141 rmMsgCtx.setSync(true); 142 } else { 143 rmMsgCtx.setSync(false); 144 rmMsgCtx.setOutGoingAddress(addrHeaders.getReplyTo().getAddress().toString()); 145 } 146 147 } 148 } | Popular Tags |