Package org.apache.sandesha2.storage

Examples of org.apache.sandesha2.storage.StorageManager


    if (log.isDebugEnabled())
      log.debug("Enter: CreateSeqResponseMsgProcessor::processInMessage");

    ConfigurationContext configCtx = createSeqResponseRMMsgCtx.getMessageContext().getConfigurationContext();

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx, configCtx
        .getAxisConfiguration());

    // Processing the create sequence response.

    CreateSequenceResponse createSeqResponsePart = (CreateSequenceResponse) createSeqResponseRMMsgCtx
        .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE);
    if (createSeqResponsePart == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noCreateSeqResponse);
      log.debug(message);
      throw new SandeshaException(message);
    }

    String newOutSequenceId = createSeqResponsePart.getIdentifier().getIdentifier();
    if (newOutSequenceId == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.newSeqIdIsNull);
      log.debug(message);
      throw new SandeshaException(message);
    }

    RelatesTo relatesTo = createSeqResponseRMMsgCtx.getMessageContext().getRelatesTo();
    String createSeqMsgId = null;
    if (relatesTo != null) {
      createSeqMsgId = relatesTo.getValue();
    } else {
      // Work out the related message from the operation context
      OperationContext context = createSeqResponseRMMsgCtx.getMessageContext().getOperationContext();
      MessageContext createSeq = context.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
      if(createSeq != null) createSeqMsgId = createSeq.getMessageID();
    }
    if(createSeqMsgId == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.relatesToNotAvailable);
      log.error(message);
      throw new SandeshaException(message);
    }

    SenderBeanMgr retransmitterMgr = storageManager.getSenderBeanMgr();
    RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();

    RMSBean rmsBean = rmsBeanMgr.retrieve(createSeqMsgId);
    if (rmsBean == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound);
      log.debug(message);
      throw new SandeshaException(message);
    }

    // Check that the create sequence response message proves possession of the correct token
    String tokenData = rmsBean.getSecurityTokenData();
    if(tokenData != null) {
      SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
      MessageContext crtSeqResponseCtx = createSeqResponseRMMsgCtx.getMessageContext();
      OMElement body = crtSeqResponseCtx.getEnvelope().getBody();
      SecurityToken token = secManager.recoverSecurityToken(tokenData);
      secManager.checkProofOfPossession(token, body, crtSeqResponseCtx);
    }

    String internalSequenceId = rmsBean.getInternalSequenceID();
    if (internalSequenceId == null || "".equals(internalSequenceId)) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.tempSeqIdNotSet);
      log.debug(message);
      throw new SandeshaException(message);
    }
    createSeqResponseRMMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID,internalSequenceId);
   
    rmsBean.setSequenceID(newOutSequenceId);

    // We should poll for any reply-to that uses the anonymous URI, when MakeConnection
    // is enabled.
    if (Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(createSeqResponseRMMsgCtx.getRMSpecVersion())) {
      SandeshaPolicyBean policy = SandeshaUtil.getPropertyBean(configCtx.getAxisConfiguration());
      if(policy.isEnableMakeConnection()) {
        String acksTo = rmsBean.getAcksToEPR();
        EndpointReference reference = new EndpointReference(acksTo);
        if(acksTo == null || reference.hasAnonymousAddress()) {
          rmsBean.setPollingMode(true);
        }
      }
    }

    SenderBean createSequenceSenderBean = retransmitterMgr.retrieve(createSeqMsgId);
    if (createSequenceSenderBean == null)
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound));

    // deleting the create sequence entry.
    retransmitterMgr.delete(createSeqMsgId);
   
    // Remove the create sequence message
    storageManager.removeMessageContext(rmsBean.getCreateSequenceMsgStoreKey());
       
    // processing for accept (offer has been sent)
    Accept accept = createSeqResponsePart.getAccept();
    if (accept != null) {

      // TODO this should be detected in the Fault manager.
      if (rmsBean.getOfferedSequence() == null) {
        String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.accptButNoSequenceOffered);
        log.debug(message);
        throw new SandeshaException(message);
      }

      RMDBean rMDBean = new RMDBean();
     
      EndpointReference acksToEPR = accept.getAcksTo().getEPR();
      rMDBean.setAcksToEPR(acksToEPR.getAddress());
      rMDBean.setSequenceID(rmsBean.getOfferedSequence());
      rMDBean.setNextMsgNoToProcess(1);
      rMDBean.setOutboundInternalSequence(rmsBean.getInternalSequenceID());

      rMDBean.setServiceName(createSeqResponseRMMsgCtx.getMessageContext().getAxisService().getName());
     
      //Storing the referenceMessage of the sending side sequence as the reference message
      //of the receiving side as well.
      //This can be used when creating new outgoing messages.
     
      String referenceMsgStoreKey = rmsBean.getReferenceMessageStoreKey();
      MessageContext referenceMsg = storageManager.retrieveMessageContext(referenceMsgStoreKey, configCtx);
     
      String newMessageStoreKey = SandeshaUtil.getUUID();
      storageManager.storeMessageContext(newMessageStoreKey,referenceMsg);
     
      rMDBean.setReferenceMessageKey(newMessageStoreKey);

      // If this is an offered sequence that needs polling then we need to setup the
      // rmdBean for polling too, so that it still gets serviced after the outbound
      // sequence terminates.
      if (Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(createSeqResponseRMMsgCtx.getRMSpecVersion())) {
        if(rmsBean.isPollingMode()) {
          rMDBean.setPollingMode(true);
        }
      }
     
      String rmSpecVersion = createSeqResponseRMMsgCtx.getRMSpecVersion();
      rMDBean.setRMVersion(rmSpecVersion);
     
      EndpointReference toEPR = createSeqResponseRMMsgCtx.getTo();
      if (toEPR==null) {
        //Most probably this is a sync response message, using the replyTo of the request message
        OperationContext operationContext = createSeqResponseRMMsgCtx.getMessageContext().getOperationContext();
        if (operationContext!=null) {
          MessageContext createSequnceMessage = operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
          if (createSequnceMessage!=null)
            toEPR = createSequnceMessage.getReplyTo();
        }
      }
     
      if (toEPR!=null)
        rMDBean.setToAddress(toEPR.getAddress());
     
      rMDBean.setServerCompletedMessages(new RangeString());
      RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();

      // Store the security token for the offered sequence
      rMDBean.setSecurityTokenData(rmsBean.getSecurityTokenData());
     
      rMDBean.setLastActivatedTime(System.currentTimeMillis());
View Full Code Here


    String sequenceId = ackRequested.getIdentifier().getIdentifier();

    MessageContext msgContext = rmMsgCtx.getMessageContext();
    ConfigurationContext configurationContext = msgContext.getConfigurationContext();

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,
        configurationContext.getAxisConfiguration());
   
    // Check that the sender of this AckRequest holds the correct token
    RMDBean rmdBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, sequenceId);

    if(rmdBean != null && rmdBean.getSecurityTokenData() != null) {;
      SecurityManager secManager = SandeshaUtil.getSecurityManager(configurationContext);
      SecurityToken token = secManager.recoverSecurityToken(rmdBean.getSecurityTokenData());
     
      secManager.checkProofOfPossession(token, soapHeader, msgContext);
    }

    // Check that the sequence requested exists
    if (FaultManager.checkForUnknownSequence(rmMsgCtx, sequenceId, storageManager, piggybackedAckRequest)) {
      if (log.isDebugEnabled())
        log.debug("Exit: AckRequestedProcessor::processAckRequestedHeader, Unknown sequence ");
      return false;
    }

    // throwing a fault if the sequence is terminated
    if (FaultManager.checkForSequenceTerminated(rmMsgCtx, sequenceId, rmdBean, piggybackedAckRequest)) {
      if (log.isDebugEnabled())
        log.debug("Exit: AckRequestedProcessor::processAckRequestedHeader, Sequence terminated");
      return false;
    }

    // Setting the ack depending on AcksTo.
    EndpointReference acksTo = new EndpointReference(rmdBean.getAcksToEPR());
    String acksToStr = acksTo.getAddress();

    if (acksToStr == null)
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.acksToStrNotSet));

    AxisOperation ackOperation = SpecSpecificConstants.getWSRMOperation(
        Sandesha2Constants.MessageTypes.ACK,
        rmdBean.getRMVersion(),
        msgContext.getAxisService());
    MessageContext ackMsgCtx = SandeshaUtil.createNewRelatedMessageContext(rmMsgCtx, ackOperation);

    ackMsgCtx.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");

    RMMsgContext ackRMMsgCtx = MsgInitializer.initializeMessage(ackMsgCtx);
    ackRMMsgCtx.setRMNamespaceValue(rmMsgCtx.getRMNamespaceValue());

    ackMsgCtx.setMessageID(SandeshaUtil.getUUID());

    SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil.getSOAPVersion(msgContext.getEnvelope()));

    // Setting new envelope
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    try {
      ackMsgCtx.setEnvelope(envelope);
    } catch (AxisFault e3) {
      throw new SandeshaException(e3.getMessage());
    }

    ackMsgCtx.setTo(acksTo);
    ackMsgCtx.setReplyTo(msgContext.getTo());
    RMMsgCreator.addAckMessage(ackRMMsgCtx, sequenceId, rmdBean);
    ackRMMsgCtx.getMessageContext().setServerSide(true);

    if (acksTo.hasAnonymousAddress()) {

      AxisEngine engine = new AxisEngine(ackRMMsgCtx.getMessageContext().getConfigurationContext());

      // setting CONTEXT_WRITTEN since acksto is anonymous
      if (rmMsgCtx.getMessageContext().getOperationContext() == null) {
        // operation context will be null when doing in a GLOBAL
        // handler.
       
        ServiceContext serviceCtx = msgContext.getServiceContext();
        OperationContext opCtx =  ContextFactory.createOperationContext(ackOperation, serviceCtx);

        rmMsgCtx.getMessageContext().setOperationContext(opCtx);
      }

      rmMsgCtx.getMessageContext().getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN,
          Constants.VALUE_TRUE);

      rmMsgCtx.getMessageContext().setProperty(Sandesha2Constants.ACK_WRITTEN, "true");

      try {
        engine.send(ackRMMsgCtx.getMessageContext());
      } catch (AxisFault e1) {
        throw new SandeshaException(e1.getMessage());
      }

    } else {

      SenderBeanMgr retransmitterBeanMgr = storageManager.getSenderBeanMgr();

      String key = SandeshaUtil.getUUID();

      // dumping to the storage will be done be Sandesha2 Transport Sender
      // storageManager.storeMessageContext(key,ackMsgCtx);
View Full Code Here

    MakeConnection makeConnection = (MakeConnection) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.MAKE_CONNECTION);
    Address address = makeConnection.getAddress();
    Identifier identifier = makeConnection.getIdentifier();
   
    ConfigurationContext configurationContext = rmMsgCtx.getConfigurationContext();
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());
   
    SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
   
    //selecting the set of SenderBeans that suit the given criteria.
    SenderBean findSenderBean = new SenderBean ();
    findSenderBean.setSend(true);
    findSenderBean.setTransportAvailable(false);
View Full Code Here

    boolean piggybackedAck = !(rmMsgCtx.getMessageType()==Sandesha2Constants.MessageTypes.ACK);
   
    MessageContext msgCtx = rmMsgCtx.getMessageContext();
    ConfigurationContext configCtx = msgCtx.getConfigurationContext();

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx, configCtx
        .getAxisConfiguration());

    SenderBeanMgr retransmitterMgr = storageManager.getSenderBeanMgr();

    String outSequenceId = sequenceAck.getIdentifier().getIdentifier();
    RMSBean rmsBean = SandeshaUtil.getRMSBeanFromSequenceId(storageManager, outSequenceId);

    if (outSequenceId == null || "".equals(outSequenceId)) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.outSeqIDIsNull);
      log.debug(message);
      throw new SandeshaException(message);
    }
    if (FaultManager.checkForUnknownSequence(rmMsgCtx, outSequenceId, storageManager, piggybackedAck)) {
      if (log.isDebugEnabled())
        log.debug("Exit: AcknowledgementProcessor::processAckHeader, Unknown sequence");
      return;
    }
    if (FaultManager.checkForSequenceTerminated(rmMsgCtx, outSequenceId, rmsBean, piggybackedAck)) {
      if (log.isDebugEnabled())
        log.debug("Exit: AcknowledgementProcessor::processAckHeader, Sequence terminated");
      return;
    }

    // Check that the sender of this Ack holds the correct token
    String internalSequenceId = rmsBean.getInternalSequenceID();
    if(rmsBean.getSecurityTokenData() != null) {
      SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
      SecurityToken token = secManager.recoverSecurityToken(rmsBean.getSecurityTokenData());
     
      secManager.checkProofOfPossession(token, soapHeader, msgCtx);
    }
   
    if(log.isDebugEnabled()) log.debug("Got Ack for RM Sequence: " + outSequenceId + ", internalSeqId: " + internalSequenceId);
    Iterator ackRangeIterator = sequenceAck.getAcknowledgementRanges().iterator();

    if (FaultManager.checkForUnknownSequence(rmMsgCtx, outSequenceId, storageManager, piggybackedAck)) {
      if (log.isDebugEnabled())
        log.debug("Exit: AcknowledgementProcessor::processAckHeader, Unknown sequence ");
      return;
    }
   
    if (FaultManager.checkForInvalidAcknowledgement(rmMsgCtx, sequenceAck, storageManager, rmsBean, piggybackedAck)) {
      if (log.isDebugEnabled())
        log.debug("Exit: AcknowledgementProcessor::processAckHeader, Invalid Ack range ");
      return;
    }
   
    String replyToAddress = rmsBean.getReplyToEPR();
    EndpointReference replyTo = new EndpointReference (replyToAddress);
    boolean anonReplyTo = replyTo.hasAnonymousAddress();
   
    String rmVersion = rmMsgCtx.getRMSpecVersion();
   
    // Compare the clientCompletedMessages with the range we just got, to work out if there
    // is any new information in this ack message
    RangeString completedMessages = rmsBean.getClientCompletedMessages();
    long numberOfNewMessagesAcked = 0;

    while(ackRangeIterator.hasNext()) {
      AcknowledgementRange ackRange = (AcknowledgementRange) ackRangeIterator.next();
      long lower = ackRange.getLowerValue();
      long upper = ackRange.getUpperValue();
      Range ackedRange = new Range(lower, upper);
      // Quick check to see if the whole range is already covered
      if(!completedMessages.isRangeCompleted(ackedRange)) {
        //we now know that this range is complete so we update it. This should aggregate the
        //ranges together and tell us which numbers are newly acked
        Range[] newRanges = completedMessages.addRange(ackedRange).getRanges();
       
        // We now take each newly acked message in turn and see if we need to update a sender bean
        for (int rangeIndex=0; rangeIndex < newRanges.length; rangeIndex++) {
          //now work on each newly acked message in this range
          for(long messageNo = newRanges[rangeIndex].lowerValue; messageNo<=newRanges[rangeIndex].upperValue; messageNo++){
           
            numberOfNewMessagesAcked++;
            SenderBean matcher = new SenderBean();
            matcher.setSequenceID(outSequenceId);
           
            matcher.setMessageNumber(messageNo);
           
            SenderBean retransmitterBean = retransmitterMgr.findUnique(matcher);
            if (retransmitterBean != null) {
              // Check we haven't got an Ack for a message that hasn't been sent yet !
              if (retransmitterBean.getSentCount() == 0) {
                FaultManager.makeInvalidAcknowledgementFault(rmMsgCtx, sequenceAck, ackRange,
                    storageManager, piggybackedAck);
                if (log.isDebugEnabled())
                  log.debug("Exit: AcknowledgementProcessor::processAckHeader, Invalid Ack");
                return;
              }
             
              String storageKey = retransmitterBean.getMessageContextRefKey();
             
              boolean syncResponseNeeded = false;
              if (Sandesha2Constants.SPEC_VERSIONS.v1_0.equals(rmVersion) && anonReplyTo) {
                MessageContext applicationMessage = storageManager.retrieveMessageContext(storageKey, configCtx);
                AxisOperation operation = applicationMessage.getAxisOperation();
                if(operation!= null) {
                  int mep = operation.getAxisSpecifMEPConstant();
                  syncResponseNeeded = (mep == WSDLConstants.MEP_CONSTANT_OUT_IN);
                }
              }

              if (!syncResponseNeeded) {
                // removing the application message from the storage.
                retransmitterMgr.delete(retransmitterBean.getMessageID());
                storageManager.removeMessageContext(storageKey);
              }
            }
          }//end for
        }//end for
      } //end while
    }

    // updating the last activated time of the sequence.
    rmsBean.setLastActivatedTime(System.currentTimeMillis());

    //adding a MakeConnection for the response sequence if needed.
    if (rmsBean.getOfferedSequence() != null) {

      RMDBeanMgr rMDBeanMgr = storageManager.getRMDBeanMgr();
      RMDBean rMDBean = rMDBeanMgr.retrieve(outSequenceId);
     
      if (rMDBean!=null && rMDBean.isPollingMode()) {
        PollingManager manager = storageManager.getPollingManager();
        if(manager != null) manager.schedulePollingRequest(rMDBean.getSequenceID(), false);
      }
    }

    // We overwrite the previous client completed message ranges with the
    // latest view, but only if it is an update i.e. contained a new
    // ack range (which is because we do not previous acks arriving late
    // to break us)
    if (numberOfNewMessagesAcked>0) {
      rmsBean.setClientCompletedMessages(completedMessages);
      long noOfMsgsAcked = rmsBean.getNumberOfMessagesAcked() + numberOfNewMessagesAcked;
      rmsBean.setNumberOfMessagesAcked(noOfMsgsAcked);
    }
   
    // Update the RMSBean
    storageManager.getRMSBeanMgr().update(rmsBean);

    // Try and terminate the sequence
    if (!rmsBean.isAvoidAutoTermination())
      TerminateManager.checkAndTerminate(rmMsgCtx.getConfigurationContext(), storageManager, rmsBean);
View Full Code Here

    // them in directly. Unfortunately that change ripples through the codebase...
    RMMsgContext rmMsgCtx = MsgInitializer.initializeMessage(msgCtx);

    ConfigurationContext configCtx = msgCtx.getConfigurationContext();

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx, configCtx
        .getAxisConfiguration());

    SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();

    String outSequenceId = sequenceAck.getIdentifier().getIdentifier();
    if (outSequenceId == null || "".equals(outSequenceId)) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.outSeqIDIsNull);
      log.debug(message);
      throw new SandeshaException(message);
    }
   
    String internalSequenceId = SandeshaUtil.getSequenceProperty(outSequenceId,
        Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID, storageManager);

    //here we cannot get the property key using the usual SandeshaUtil.getSequencePropertyKey function,
    //because this can be a applicationMessage, which piggybacks the acknowledgement.
    String sequencePropertyKey = internalSequenceId;

    // Check that the sender of this Ack holds the correct token
    SequencePropertyBean tokenBean = seqPropMgr.retrieve(outSequenceId, Sandesha2Constants.SequenceProperties.SECURITY_TOKEN);
    if(tokenBean != null) {
      SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
      SecurityToken token = secManager.recoverSecurityToken(tokenBean.getValue());
     
      secManager.checkProofOfPossession(token, soapHeader, msgCtx);
    }
   
    Iterator ackRangeIterator = sequenceAck.getAcknowledgementRanges().iterator();
    Iterator nackIterator = sequenceAck.getNackList().iterator();

    FaultManager faultManager = new FaultManager();
    SandeshaException fault = faultManager
        .checkForUnknownSequence(rmMsgCtx, outSequenceId, storageManager);
    if(fault == null) {
      fault = faultManager.checkForInvalidAcknowledgement(rmMsgCtx, storageManager);
    }
    if (fault != null) {
      throw fault;
    }

    // updating the last activated time of the sequence.
    SequenceManager.updateLastActivatedTime(sequencePropertyKey, storageManager);

    SenderBean input = new SenderBean();
    input.setSend(true);
    input.setReSend(true);
    Collection retransmitterEntriesOfSequence = senderBeanMgr.find(input);

    ArrayList ackedMessagesList = new ArrayList();
    while (ackRangeIterator.hasNext()) {
      AcknowledgementRange ackRange = (AcknowledgementRange) ackRangeIterator.next();
      long lower = ackRange.getLowerValue();
      long upper = ackRange.getUpperValue();

      for (long messageNo = lower; messageNo <= upper; messageNo++) {
        SenderBean retransmitterBean = getSenderEntry(retransmitterEntriesOfSequence, messageNo);
        if (retransmitterBean != null) {
          senderBeanMgr.delete(retransmitterBean.getMessageID());

          // removing the application message from the storage.
          String storageKey = retransmitterBean.getMessageContextRefKey();
          storageManager.removeMessageContext(storageKey);
        }

        ackedMessagesList.add(new Long(messageNo));
      }
    }

    while (nackIterator.hasNext()) {
      Nack nack = (Nack) nackIterator.next();
      long msgNo = nack.getNackNumber();

      // TODO - Process Nack
    }
   
    //adding a MakeConnection for the response sequence if needed.
    String offeredSequenceId = SandeshaUtil.getSequenceProperty(sequencePropertyKey,
        Sandesha2Constants.SequenceProperties.OFFERED_SEQUENCE, storageManager);
    if (offeredSequenceId!=null) {

      RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();
      RMDBean rmdBean = rmdBeanMgr.retrieve(outSequenceId);
     
      if (rmdBean!=null && rmdBean.isPollingMode())
        SandeshaUtil.shedulePollingRequest(offeredSequenceId, configCtx);
     
View Full Code Here

    if (log.isDebugEnabled())
      log.debug("Enter: CreateSeqResponseMsgProcessor::processInMessage");

    ConfigurationContext configCtx = createSeqResponseRMMsgCtx.getMessageContext().getConfigurationContext();

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx, configCtx
        .getAxisConfiguration());

    // Processing the create sequence response.

    CreateSequenceResponse createSeqResponsePart = (CreateSequenceResponse) createSeqResponseRMMsgCtx
        .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE);
    if (createSeqResponsePart == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noCreateSeqResponse);
      log.debug(message);
      throw new SandeshaException(message);
    }

    String newOutSequenceId = createSeqResponsePart.getIdentifier().getIdentifier();
    if (newOutSequenceId == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.newSeqIdIsNull);
      log.debug(message);
      throw new SandeshaException(message);
    }

    RelatesTo relatesTo = createSeqResponseRMMsgCtx.getMessageContext().getRelatesTo();
    if (relatesTo == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.relatesToNotAvailable);
      log.error(message);
      throw new SandeshaException(message);
    }
    String createSeqMsgId = relatesTo.getValue();

    SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
    RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();

    RMSBean rmsBean = rmsBeanMgr.retrieve(createSeqMsgId);
    if (rmsBean == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound);
      log.debug(message);
      throw new SandeshaException(message);
    }

    // Check that the create sequence response message proves possession of the correct token
    String tokenData = rmsBean.getSecurityTokenData();
    if(tokenData != null) {
      SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
      MessageContext crtSeqResponseCtx = createSeqResponseRMMsgCtx.getMessageContext();
      OMElement body = crtSeqResponseCtx.getEnvelope().getBody();
      SecurityToken token = secManager.recoverSecurityToken(tokenData);
      secManager.checkProofOfPossession(token, body, crtSeqResponseCtx);
    }

    String internalSequenceId = rmsBean.getInternalSequenceID();
    if (internalSequenceId == null || "".equals(internalSequenceId)) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.tempSeqIdNotSet);
      log.debug(message);
      throw new SandeshaException(message);
    }
    createSeqResponseRMMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID,internalSequenceId);
   
    String sequencePropertyKey = SandeshaUtil.getSequencePropertyKey(createSeqResponseRMMsgCtx);
   
    rmsBean.setSequenceID(newOutSequenceId);
    rmsBeanMgr.update(rmsBean);

    SenderBean createSequenceSenderBean = senderBeanMgr.retrieve(createSeqMsgId);
    if (createSequenceSenderBean == null)
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound));

    // deleting the create sequence entry.
    senderBeanMgr.delete(createSeqMsgId);

    // storing new out sequence id
    SequencePropertyBeanMgr sequencePropMgr = storageManager.getSequencePropertyBeanMgr();
    SequencePropertyBean outSequenceBean = new SequencePropertyBean(sequencePropertyKey,
        Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID, newOutSequenceId);
    SequencePropertyBean internalSequenceBean = new SequencePropertyBean(newOutSequenceId,
        Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID, sequencePropertyKey);

    sequencePropMgr.insert(outSequenceBean);
    sequencePropMgr.insert(internalSequenceBean);
   
    // Store the security token under the new sequence id
    if(tokenData != null) {
      SequencePropertyBean newToken = new SequencePropertyBean(newOutSequenceId,
          Sandesha2Constants.SequenceProperties.SECURITY_TOKEN, tokenData);
      sequencePropMgr.insert(newToken);
    }

    // processing for accept (offer has been sent)
    Accept accept = createSeqResponsePart.getAccept();
    if (accept != null) {
      // Find offered sequence from internal sequence id.
      SequencePropertyBean offeredSequenceBean = sequencePropMgr.retrieve(sequencePropertyKey,
          Sandesha2Constants.SequenceProperties.OFFERED_SEQUENCE);

      // TODO this should be detected in the Fault manager.
      if (offeredSequenceBean == null) {
        String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.accptButNoSequenceOffered);
        log.debug(message);
        throw new SandeshaException(message);
      }

      String offeredSequenceId = (String) offeredSequenceBean.getValue();

      EndpointReference acksToEPR = accept.getAcksTo().getEPR();
      SequencePropertyBean acksToBean = new SequencePropertyBean();
      acksToBean.setName(Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);
      acksToBean.setSequencePropertyKey(offeredSequenceId);
      acksToBean.setValue(acksToEPR.getAddress());

      sequencePropMgr.insert(acksToBean);

      RMDBean rmdBean = new RMDBean();
      rmdBean.setSequenceID(offeredSequenceId);
      rmdBean.setNextMsgNoToProcess(1);
     

      boolean pollingMode = false;
      if (Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(createSeqResponseRMMsgCtx.getRMSpecVersion())) {
        String replyToAddress = SandeshaUtil.getSequenceProperty(sequencePropertyKey,
                Sandesha2Constants.SequenceProperties.REPLY_TO_EPR, storageManager);
        if (replyToAddress!=null) {
          if (AddressingConstants.Submission.WSA_ANONYMOUS_URL.equals(replyToAddress))
            pollingMode = true;
          else if (AddressingConstants.Final.WSA_ANONYMOUS_URL.equals(replyToAddress))
            pollingMode = true;
          else if (replyToAddress.startsWith(Sandesha2Constants.WSRM_ANONYMOUS_URI_PREFIX))
            pollingMode = true;
        }
      }
     
      //Storing the referenceMessage of the sending side sequence as the reference message
      //of the receiving side as well.
      //This can be used when creating new outgoing messages.
     
      String referenceMsgStoreKey = rmsBean.getReferenceMessageStoreKey();
      MessageContext referenceMsg = storageManager.retrieveMessageContext(referenceMsgStoreKey, configCtx);
     
      String newMessageStoreKey = SandeshaUtil.getUUID();
      storageManager.storeMessageContext(newMessageStoreKey,referenceMsg);
     
      rmdBean.setReferenceMessageKey(newMessageStoreKey);
     
      rmdBean.setPollingMode(pollingMode);
     
      //if PollingMode is true, starting the pollingmanager.
      if (pollingMode)
        SandeshaUtil.startPollingManager(configCtx);
     
      RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();
      rmdBeanMgr.insert(rmdBean);

      String rmSpecVersion = createSeqResponseRMMsgCtx.getRMSpecVersion();

      SequencePropertyBean specVersionBean = new SequencePropertyBean(offeredSequenceId,
          Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION, rmSpecVersion);
      sequencePropMgr.insert(specVersionBean);

      SequencePropertyBean receivedMsgBean = new SequencePropertyBean(offeredSequenceId,
          Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES, "");
      sequencePropMgr.insert(receivedMsgBean);

      SequencePropertyBean msgsBean = new SequencePropertyBean();
      msgsBean.setSequencePropertyKey(offeredSequenceId);
      msgsBean.setName(Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
      msgsBean.setValue("");
      sequencePropMgr.insert(msgsBean);

      // setting the addressing version.
      String addressingNamespace = createSeqResponseRMMsgCtx.getAddressingNamespaceValue();
      SequencePropertyBean addressingVersionBean = new SequencePropertyBean(offeredSequenceId,
          Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE, addressingNamespace);
      sequencePropMgr.insert(addressingVersionBean);

      // Store the security token for the offered sequence
      if(tokenData != null) {
        SequencePropertyBean newToken = new SequencePropertyBean(offeredSequenceId,
            Sandesha2Constants.SequenceProperties.SECURITY_TOKEN, tokenData);
        sequencePropMgr.insert(newToken);
      }
    }

    SenderBean target = new SenderBean();
    target.setInternalSequenceID(internalSequenceId);
    target.setSend(false);
    target.setReSend(true);

    Iterator iterator = senderBeanMgr.find(target).iterator();
    while (iterator.hasNext()) {
      SenderBean tempBean = (SenderBean) iterator.next();

      // updating the application message
      String key = tempBean.getMessageContextRefKey();
      MessageContext applicationMsg = storageManager.retrieveMessageContext(key, configCtx);

      // TODO make following exception message more understandable to the
      // user (probably some others exceptions messages as well)
      if (applicationMsg == null)
        throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.unavailableAppMsg));

      String rmVersion = SandeshaUtil.getRMVersion(sequencePropertyKey, storageManager);
      if (rmVersion == null)
        throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDecideRMVersion));

      String assumedRMNamespace = SpecSpecificConstants.getRMNamespaceValue(rmVersion);

      RMMsgContext applicaionRMMsg = MsgInitializer.initializeMessage(applicationMsg);

      Sequence sequencePart = (Sequence) applicaionRMMsg.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
      if (sequencePart == null) {
        String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.seqPartIsNull);
        log.debug(message);
        throw new SandeshaException(message);
      }

      Identifier identifier = new Identifier(assumedRMNamespace);
      identifier.setIndentifer(newOutSequenceId);

      sequencePart.setIdentifier(identifier);

      try {
        applicaionRMMsg.addSOAPEnvelope();
      } catch (AxisFault e) {
        throw new SandeshaException(e.getMessage(), e);
      }

      // asking to send the application msssage
      tempBean.setSend(true);
      senderBeanMgr.update(tempBean);

      // updating the message. this will correct the SOAP envelope string.
      storageManager.updateMessageContext(key, applicationMsg);
    }

    SequenceManager.updateLastActivatedTime(sequencePropertyKey, storageManager);

    createSeqResponseRMMsgCtx.getMessageContext().getOperationContext().setProperty(
View Full Code Here

          SandeshaMessageKeys.cannotGetStorageManager));
  }
 
  public static StorageManager getInMemoryStorageManager(ConfigurationContext context) throws SandeshaException {

    StorageManager inMemoryStorageManager = (StorageManager) context.getProperty(Sandesha2Constants.INMEMORY_STORAGE_MANAGER);
    if (inMemoryStorageManager != null)
      return inMemoryStorageManager;

    //Currently module policies (default) are used to find the storage manager. These cant be overriden
    //TODO change this so that different services can hv different storage managers.
View Full Code Here

    return inMemoryStorageManager;
  }
 
  public static StorageManager getPermanentStorageManager(ConfigurationContext context) throws SandeshaException {

    StorageManager permanentStorageManager = (StorageManager) context.getProperty(Sandesha2Constants.PERMANENT_STORAGE_MANAGER);
    if (permanentStorageManager != null)
      return permanentStorageManager;

    //Currently module policies (default) are used to find the storage manager. These cant be overriden
    //TODO change this so that different services can hv different storage managers.
View Full Code Here

    return permanentStorageManager;
  }
 
  private static StorageManager getStorageManagerInstance (String className,ConfigurationContext context) throws SandeshaException {
   
    StorageManager storageManager = null;
    try {
        ClassLoader classLoader = (ClassLoadercontext.getProperty(Sandesha2Constants.MODULE_CLASS_LOADER);

        if (classLoader==null)
          throw new SandeshaException (SandeshaMessageHelper.getMessage(
              SandeshaMessageKeys.classLoaderNotFound));
       
        Class c = classLoader.loadClass(className);
      Class configContextClass = context.getClass();
     
      Constructor constructor = c.getConstructor(new Class[] { configContextClass });
      Object obj = constructor.newInstance(new Object[] {context});

      if (obj == null || !(obj instanceof StorageManager))
        throw new SandeshaException(SandeshaMessageHelper.getMessage(
            SandeshaMessageKeys.storageManagerMustImplement));

      StorageManager mgr = (StorageManager) obj;
      storageManager = mgr;
      return storageManager;
     
    } catch (Exception e) {
      String message = SandeshaMessageHelper.getMessage(
View Full Code Here

    String sequenceId = ackRequested.getIdentifier().getIdentifier();

    ConfigurationContext configurationContext = msgContext.getConfigurationContext();

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,
        configurationContext.getAxisConfiguration());

    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();

    //not getting the sequencePropertyKey from the usual method since the ackRequest may be embedded in a message
    //of a different sequence. (usual method SandeshaUtil.getSequencePropertyKey)
    String sequencePropertyKey = sequenceId;
   
    // Check that the sender of this AckRequest holds the correct token
    SequencePropertyBean tokenBean = seqPropMgr.retrieve(sequencePropertyKey, Sandesha2Constants.SequenceProperties.SECURITY_TOKEN);
    if(tokenBean != null) {
      SecurityManager secManager = SandeshaUtil.getSecurityManager(configurationContext);
      SecurityToken token = secManager.recoverSecurityToken(tokenBean.getValue());
     
      secManager.checkProofOfPossession(token, soapHeader, msgContext);
    }

    // Setting the ack depending on AcksTo.
    SequencePropertyBean acksToBean = seqPropMgr.retrieve(sequencePropertyKey,
        Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);

    EndpointReference acksTo = new EndpointReference(acksToBean.getValue());
    String acksToStr = acksTo.getAddress();

    if (acksToStr == null)
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.acksToStrNotSet));

    AxisOperation ackOperation = null;

    try {
      ackOperation = AxisOperationFactory.getOperationDescription(WSDL20_2004Constants.MEP_URI_IN_ONLY);
    } catch (AxisFault e) {
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.axisOperationError, e
          .toString()));
    }

    AxisOperation rmMsgOperation = rmMsgCtx.getMessageContext().getAxisOperation();
    if (rmMsgOperation != null) {
      ArrayList outFlow = rmMsgOperation.getPhasesOutFlow();
      if (outFlow != null) {
        ackOperation.setPhasesOutFlow(outFlow);
        ackOperation.setPhasesOutFaultFlow(outFlow);
      }
    }

    MessageContext ackMsgCtx = SandeshaUtil.createNewRelatedMessageContext(rmMsgCtx, ackOperation);

    ackMsgCtx.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");

    RMMsgContext ackRMMsgCtx = MsgInitializer.initializeMessage(ackMsgCtx);
    ackRMMsgCtx.setRMNamespaceValue(rmMsgCtx.getRMNamespaceValue());

    ackMsgCtx.setMessageID(SandeshaUtil.getUUID());

    SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil.getSOAPVersion(msgContext.getEnvelope()));

    // Setting new envelope
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    try {
      ackMsgCtx.setEnvelope(envelope);
    } catch (AxisFault e3) {
      throw new SandeshaException(e3.getMessage());
    }

    ackMsgCtx.setTo(acksTo);
    ackMsgCtx.setReplyTo(msgContext.getTo());
    RMMsgCreator.addAckMessage(ackRMMsgCtx,sequencePropertyKey,sequenceId, storageManager);
    ackRMMsgCtx.getMessageContext().setServerSide(true);
    ackMsgCtx.setProperty(AddressingConstants.WS_ADDRESSING_VERSION, msgContext
        .getProperty(AddressingConstants.WS_ADDRESSING_VERSION)); // TODO
                                      // do
                                      // this
                                      // in
                                      // the
                                      // RMMsgCreator

    String addressingNamespaceURI = SandeshaUtil.getSequenceProperty(sequencePropertyKey,
        Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE, storageManager);
    String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceURI);

    if (anonymousURI.equals(acksTo.getAddress())) {

      AxisEngine engine = new AxisEngine(ackRMMsgCtx.getMessageContext().getConfigurationContext());

      // setting CONTEXT_WRITTEN since acksto is anonymous
      if (rmMsgCtx.getMessageContext().getOperationContext() == null) {
        // operation context will be null when doing in a GLOBAL
        // handler.
        try {
          AxisOperation op = AxisOperationFactory.getAxisOperation(WSDL20_2004Constants.MEP_CONSTANT_IN_OUT);
          OperationContext opCtx = new OperationContext(op);
          rmMsgCtx.getMessageContext().setAxisOperation(op);
          rmMsgCtx.getMessageContext().setOperationContext(opCtx);
        } catch (AxisFault e2) {
          throw new SandeshaException(e2.getMessage());
        }
      }

      rmMsgCtx.getMessageContext().getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN,
          Constants.VALUE_TRUE);

      rmMsgCtx.getMessageContext().setProperty(Sandesha2Constants.ACK_WRITTEN, "true");

      try {
        engine.send(ackRMMsgCtx.getMessageContext());
      } catch (AxisFault e1) {
        throw new SandeshaException(e1.getMessage());
      }

    } else {

      SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();

      String key = SandeshaUtil.getUUID();

      // dumping to the storage will be done be Sandesha2 Transport Sender
      // storageManager.storeMessageContext(key,ackMsgCtx);

      SenderBean ackBean = new SenderBean();
      ackBean.setMessageContextRefKey(key);
      ackBean.setMessageID(ackMsgCtx.getMessageID());
      ackBean.setReSend(false);
      ackBean.setSequenceID(sequenceId);
     
      EndpointReference to = ackMsgCtx.getTo();
      if (to!=null)
        ackBean.setToAddress(to.getAddress());

      // this will be set to true in the sender.
      ackBean.setSend(true);

      ackMsgCtx.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);

      ackBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);

      // the internalSequenceId value of the retransmitter Table for the
      // messages related to an incoming
      // sequence is the actual sequence ID

      // operation is the lowest level, Sandesha2 can be engaged.
      SandeshaPolicyBean propertyBean = SandeshaUtil.getPropertyBean(msgContext.getAxisOperation());

      long ackInterval = propertyBean.getAcknowledgementInterval();

      // Ack will be sent as stand alone, only after the retransmitter
      // interval.
      long timeToSend = System.currentTimeMillis() + ackInterval;

      // removing old acks.
      SenderBean findBean = new SenderBean();
      findBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);

      // this will be set to true in the sandesha2TransportSender.
      findBean.setSend(true);
      findBean.setReSend(false);
      Collection coll = senderBeanMgr.find(findBean);
      Iterator it = coll.iterator();

      if (it.hasNext()) {
        SenderBean oldAckBean = (SenderBean) it.next();
        timeToSend = oldAckBean.getTimeToSend(); // If there is an
                              // old ack. This ack
                              // will be sent in
                              // the old
                              // timeToSend.
        senderBeanMgr.delete(oldAckBean.getMessageID());
      }

      ackBean.setTimeToSend(timeToSend);

      storageManager.storeMessageContext(key, ackMsgCtx);
      msgContext.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);
     
      // inserting the new ack.
      senderBeanMgr.insert(ackBean);
View Full Code Here

TOP

Related Classes of org.apache.sandesha2.storage.StorageManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.