Package org.apache.sandesha2.storage.beans

Examples of org.apache.sandesha2.storage.beans.RMSBean


    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx, configCtx
        .getAxisConfiguration());
   
    // Find the rmsBean
    RMSBean rmsBean = SandeshaUtil.getRMSBeanFromSequenceId(storageManager, sequenceID);
    if (rmsBean != null) {
   
      // Notify the clients of a failure
      notifyClientsOfFault(rmsBean.getInternalSequenceID(), storageManager, configCtx, fault);
     
      rmMsgCtx.pause();
     
      // Cleanup sending side.
      if (log.isDebugEnabled())
        log.debug("Terminating sending sequence " + rmsBean);
      TerminateManager.terminateSendingSide(rmsBean, storageManager);
     
      // Update the last activated time.
      rmsBean.setLastActivatedTime(System.currentTimeMillis());
     
      // Update the bean in the map
      storageManager.getRMSBeanMgr().update(rmsBean);
    }
    else {
View Full Code Here


  public static RMSBean setupNewClientSequence(MessageContext firstAplicationMsgCtx,
      String internalSequenceId, StorageManager storageManager) throws SandeshaException {
    if (log.isDebugEnabled())
      log.debug("Enter: SequenceManager::setupNewClientSequence");
   
    RMSBean rmsBean = new RMSBean();
    rmsBean.setInternalSequenceID(internalSequenceId);

    // If we are server-side, we use the details from the inbound sequence to help set
    // up the reply sequence.
    String inboundSequence = null;
    RMDBean inboundBean = null;
    if(firstAplicationMsgCtx.isServerSide()) {
      inboundSequence = (String) firstAplicationMsgCtx.getProperty(Sandesha2Constants.MessageContextProperties.INBOUND_SEQUENCE_ID);
      if(inboundSequence != null) {
        inboundBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, inboundSequence);
      }
    }
   
    // Finding the spec version
    String specVersion = getSpecVersion(firstAplicationMsgCtx, storageManager);
    rmsBean.setRMVersion(specVersion);

    // Set up the To EPR
    EndpointReference toEPR = firstAplicationMsgCtx.getTo();

    if (toEPR == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
      log.debug(message);
      throw new SandeshaException(message);
    }

    rmsBean.setToEPR(toEPR.getAddress());

    // Discover the correct acksTo and replyTo EPR for this RMSBean
    EndpointReference acksToEPR = null;
    EndpointReference replyToEPR = null;

    if (firstAplicationMsgCtx.isServerSide()) {
      // Server side, we want the replyTo and AcksTo EPRs to point into this server.
      // We can work that out by looking at the RMD bean that pulled the message in,
      // and copying its 'ReplyTo' address.
      if(inboundBean != null && inboundBean.getReplyToEPR() != null) {
        acksToEPR = new EndpointReference(inboundBean.getReplyToEPR());
        replyToEPR = new EndpointReference(inboundBean.getReplyToEPR());
      } else {
        String beanInfo = (inboundBean == null) ? "null" : inboundBean.toString();
        String message = SandeshaMessageHelper.getMessage(
            SandeshaMessageKeys.cannotChooseAcksTo, inboundSequence, beanInfo);
        SandeshaException e = new SandeshaException(message);
        if(log.isDebugEnabled()) log.debug("Throwing", e);
        throw e;
      }

    } else {
      replyToEPR = firstAplicationMsgCtx.getReplyTo();
     
      // If the replyTo is the none URI, we need to rewrite it as the
      // anon replyTo. Setting the value to null should have that effect.
      if(replyToEPR != null && replyToEPR.hasNoneAddress()) {
        replyToEPR = null;
      }

      // For client-side sequences there are 3 options:
      // 1) An explict AcksTo, set via the client API
      // 2) The replyTo from the app message
      // 3) The anonymous URI (for which we can leave a null EPR)
      String acksTo = (String) firstAplicationMsgCtx.getProperty(SandeshaClientConstants.AcksTo);
      if (acksTo != null) {
        if (log.isDebugEnabled())
          log.debug("Using explicit AcksTo, addr=" + acksTo);
        acksToEPR = new EndpointReference(acksTo);
      } else if(replyToEPR != null) {
        if (log.isDebugEnabled())
          log.debug("Using replyTo EPR as AcksTo, addr=" + replyToEPR.getAddress());
        acksToEPR = replyToEPR;
      }
    }
    // In case either of the replyTo or AcksTo is anonymous, rewrite them using the AnonURI template
    //(this should be done only for RM 1.1)
    ConfigurationContext config = firstAplicationMsgCtx.getConfigurationContext();
   
    if (Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(specVersion)) {
      replyToEPR = SandeshaUtil.rewriteEPR(rmsBean, replyToEPR, config);
      acksToEPR = SandeshaUtil.rewriteEPR(rmsBean, acksToEPR, config);
    }
   
    // Store both the acksTo and replyTo
    if(replyToEPR != null) rmsBean.setReplyToEPR(replyToEPR.getAddress());
    if(acksToEPR  != null) rmsBean.setAcksToEPR(acksToEPR.getAddress());
   
    // New up the client completed message ranges list
    rmsBean.setClientCompletedMessages(new RangeString());

    // saving transportTo value;
    String transportTo = (String) firstAplicationMsgCtx.getProperty(Constants.Configuration.TRANSPORT_URL);
    if (transportTo != null) {
      rmsBean.setTransportTo(transportTo);
    }

    // Set the soap version use by this client
    rmsBean.setSoapVersion(SandeshaUtil.getSOAPVersion(firstAplicationMsgCtx.getEnvelope()));

    //setting the autoTermination property for the client side.
    if (!firstAplicationMsgCtx.isServerSide()) {
      Object avoidAutoTermination = firstAplicationMsgCtx.getProperty(SandeshaClientConstants.AVOID_AUTO_TERMINATION);
      if (avoidAutoTermination!=null && JavaUtils.isTrueExplicitly(avoidAutoTermination))
        rmsBean.setAvoidAutoTermination(true);
    }
    // updating the last activated time.
    rmsBean.setLastActivatedTime(System.currentTimeMillis());
   
    if (log.isDebugEnabled())
      log.debug("Exit: SequenceManager::setupNewClientSequence " + rmsBean);
    return rmsBean;
  }
View Full Code Here

        .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);
           
            List retransmitterBeans = retransmitterMgr.find(matcher);
            if (! retransmitterBeans.isEmpty()){
              Iterator retransmitterBeansItr = retransmitterBeans.iterator();
              while (retransmitterBeansItr.hasNext()) {
                SenderBean retransmitterBean = (SenderBean) retransmitterBeansItr.next();
                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.getAxisSpecificMEPConstant();
                      syncResponseNeeded = (mep == WSDLConstants.MEP_CONSTANT_OUT_IN);
                    }
                  }

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

          }//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);
    }
   
    // Update the RMSBean
    storageManager.getRMSBeanMgr().update(rmsBean);

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

    if (log.isDebugEnabled())
      log.debug("Exit: AcknowledgementProcessor::processAckHeader");
  }
View Full Code Here

    }

    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);
   
    // Check to see if we have already received a sequence id. If we have then this response is redundant,
    // and we can forget about it.
    // TODO: Should we terminate or close the extra sequence? We can only do that if the new sequence
    // id is different from the one we got back the first time. For now it should be enough to just
    // ignore it, and let it time out.
    if(rmsBean.getSequenceID() != null) {
      if(log.isDebugEnabled())
        log.debug("Exit: CreateSeqResponseMsgProcessor::processInMessage, sequence id is already set. " +
            "Existing id:" + rmsBean.getSequenceID() + ", new id:" + newOutSequenceId);
      return false;
    }

    // Store the new sequence id
    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);
        }
      }
    }

    // deleting the create sequence sender bean 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());
     
      rmdBeanMgr.insert(rMDBean);
      SandeshaUtil.startWorkersForSequence(configCtx, rMDBean);
    }
   
    rmsBean.setLastActivatedTime(System.currentTimeMillis());
    rmsBeanMgr.update(rmsBean);
    SandeshaUtil.startWorkersForSequence(configCtx, rmsBean);

    // Locate and update all of the messages for this sequence, now that we know
    // the sequence id.
View Full Code Here

   
    // If the message is a reply to an outbound message then we can update the RMSBean that
    // matches.
    EndpointReference toEPR = msgCtx.getTo();
    if(toEPR == null || toEPR.hasAnonymousAddress()) {
      RMSBean outBean = null;

      // Look for the correct outbound sequence by checking the anon uuid (if there is one)
      String toAddress = (toEPR == null) ? null : toEPR.getAddress();
      if(SandeshaUtil.isWSRMAnonymous(toAddress)) {
        RMSBean finderBean = new RMSBean();
        finderBean.setAnonymousUUID(toAddress);
        outBean = storageManager.getRMSBeanMgr().findUnique(finderBean);
      }
     
      // Fall back to the sequence that may have been offered at sequence creation time
      if(outBean == null) {
        String outboundSequence = bean.getOutboundInternalSequence();
        if(outboundSequence != null) {
          outBean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, outboundSequence);
        }
      }
     
      // Update the reply count
      if(outBean != null && outBean.getExpectedReplies() > 0 ) {
        outBean.setExpectedReplies(outBean.getExpectedReplies() - 1);
        RMSBeanMgr outMgr = storageManager.getRMSBeanMgr();
        outMgr.update(outBean);
      }
    }
   
    // Set the last activated time
    bean.setLastActivatedTime(System.currentTimeMillis());
   
    // Update the RMD bean
    mgr.update(bean);
   
    // If we are doing sync 2-way over WSRM 1.0, then we may just have received one of
    // the reply messages that we were looking for. If so we can remove the matching sender bean.
    int mep = msgCtx.getAxisOperation().getAxisSpecificMEPConstant();
    if(specVersion!=null && specVersion.equals(Sandesha2Constants.SPEC_VERSIONS.v1_0) &&
        mep == WSDLConstants.MEP_CONSTANT_OUT_IN) {
      RelatesTo relatesTo = msgCtx.getRelatesTo();
      if(relatesTo != null) {
        String messageId = relatesTo.getValue();
        SenderBean matcher = new SenderBean();
        matcher.setMessageID(messageId);
        SenderBean sender = storageManager.getSenderBeanMgr().findUnique(matcher);
        if(sender != null) {
          if(log.isDebugEnabled()) log.debug("Deleting sender for sync-2-way message");
         
          storageManager.removeMessageContext(sender.getMessageContextRefKey());
         
          //this causes the request to be deleted even without an ack.
          storageManager.getSenderBeanMgr().delete(messageId);
         
          // Try and terminate the corresponding outbound sequence
          RMSBean rmsBean = SandeshaUtil.getRMSBeanFromSequenceId(storageManager, sender.getSequenceID());
          TerminateManager.checkAndTerminate(rmMsgCtx.getConfigurationContext(), storageManager, rmsBean);
        }
      }
    }
View Full Code Here

    String dummyMessageString = (String) msgContext.getOptions().getProperty(SandeshaClientConstants.DUMMY_MESSAGE);
    boolean dummyMessage = false;
    if (dummyMessageString != null && Sandesha2Constants.VALUE_TRUE.equals(dummyMessageString))
      dummyMessage = true;

    RMSBean rmsBean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, internalSequenceId);

    //see if the sequence is closed
    if(rmsBean != null && rmsBean.isSequenceClosedClient()){
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotSendMsgAsSequenceClosed, internalSequenceId));
    }

    //see if the sequence is terminated
    if(rmsBean != null && rmsBean.isTerminateAdded()) {
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotSendMsgAsSequenceTerminated, internalSequenceId));
    }

    //see if the sequence is timed out
    if(rmsBean != null && rmsBean.isTimedOut()){
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotSendMsgAsSequenceTimedout, internalSequenceId));
    }
   
    // If the call application is a 2-way MEP, and uses a anonymous replyTo, and the
    // RM 1.1 spec level, then we must have MakeConnection enabled. We check that here,
    // before we start creating a new Sequence.
    if(!serverSide) {
      AxisOperation op = msgContext.getAxisOperation();
      int mep = WSDLConstants.MEP_CONSTANT_INVALID;
      if(op != null) {
        mep = op.getAxisSpecificMEPConstant();
      }
      if(mep == WSDLConstants.MEP_CONSTANT_OUT_IN) {
        String specVersion = null;
        if(rmsBean == null) {
          specVersion = SequenceManager.getSpecVersion(msgContext, storageManager);
        } else {
          specVersion = rmsBean.getRMVersion();
        }
        if(specVersion == Sandesha2Constants.SPEC_VERSIONS.v1_1) {
          EndpointReference replyTo = msgContext.getReplyTo();
          if(replyTo == null || replyTo.hasAnonymousAddress()) {
            //we are sync
            SandeshaPolicyBean policy = SandeshaUtil.getPropertyBean(configContext.getAxisConfiguration());
            if(!policy.isEnableMakeConnection()) {
              String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.makeConnectionDisabled);
              throw new SandeshaException(message);
            }           
          }
        }
      }
    }

    //setting the reference msg store key.
    if (rmsBean!=null && rmsBean.getReferenceMessageStoreKey()==null) {
      //setting this application message as the reference, if it hsnt already been set.
     
      String referenceMsgKey = SandeshaUtil.getUUID();
      storageManager.storeMessageContext(referenceMsgKey, msgContext);
      rmsBean.setReferenceMessageStoreKey(referenceMsgKey);
    }
   
    String outSequenceID = null;

    if (rmsBean == null) {
      // SENDING THE CREATE SEQUENCE.
      synchronized (RMSBeanMgr.class) {
        // There is a timing window where 2 sending threads can hit this point
        // at the same time and both will create an RMSBean to the same endpoint
        // with the same internal sequenceid
        // Check that someone hasn't created the bean
        rmsBean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, internalSequenceId);
        // if first message - setup the sending side sequence - both for the
        // server and the client sides.
        if (rmsBean == null) {
          rmsBean = SequenceManager.setupNewClientSequence(msgContext, internalSequenceId, storageManager);
          rmsBean = addCreateSequenceMessage(rmMsgCtx, rmsBean, storageManager);
        }
      }
   
    } else {
      outSequenceID = rmsBean.getSequenceID();
    }
   
    // the message number that was last used.
    long systemMessageNumber = rmsBean.getNextMessageNumber();

    // The number given by the user has to be larger than the last stored
    // number.
    if (givenMessageNumber > 0 && givenMessageNumber <= systemMessageNumber) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.msgNumberNotLargerThanLastMsg, Long
          .toString(givenMessageNumber));
      throw new SandeshaException(message);
    }

    // Finding the correct message number.
    long messageNumber = -1;
    if (givenMessageNumber > 0) // if given message number is valid use it.
                  // (this is larger than the last stored due
                  // to the last check)
      messageNumber = givenMessageNumber;
    else if (systemMessageNumber > 0) { // if system message number is valid
                      // use it.
      messageNumber = systemMessageNumber + 1;
    } else { // This is the first message (systemMessageNumber = -1)
      messageNumber = 1;
    }

    if (serverSide) {
      // Deciding whether this is the last message. We assume it is if it relates to
      // a message which arrived with the LastMessage flag on it.
      RMDBean rmdBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, inboundSequence);     
      // Get the last in message
      String lastRequestId = rmdBean.getLastInMessageId();
      RelatesTo relatesTo = msgContext.getRelatesTo();
      if(relatesTo != null && lastRequestId != null &&
          lastRequestId.equals(relatesTo.getValue())) {
        lastMessage = true;
      }
     
      //or a constant property may call it as the last msg
      Boolean inboundLast = (Boolean) msgContext.getProperty(Sandesha2Constants.MessageContextProperties.INBOUND_LAST_MESSAGE);
      if (inboundLast!=null && inboundLast.booleanValue())
        lastMessage = true;
    }
   
    if (lastMessage)
      rmsBean.setLastOutMessage(messageNumber);   

    // set this as the response highest message.
    rmsBean.setHighestOutMessageNumber(messageNumber);
   
    // saving the used message number, and the expected reply count
    boolean startPolling = false;
    if (!dummyMessage) {
      rmsBean.setNextMessageNumber(messageNumber);

      // Identify the MEP associated with the message.
      AxisOperation op = msgContext.getAxisOperation();
      int mep = WSDLConstants.MEP_CONSTANT_INVALID;
      if(op != null) {
        mep = op.getAxisSpecificMEPConstant();
      }

      if(mep == WSDLConstants.MEP_CONSTANT_OUT_IN) {
        // We only match up requests and replies when we are doing sync interactions
        EndpointReference replyTo = msgContext.getReplyTo();
        if(replyTo == null || replyTo.hasAnonymousAddress()) {
          long expectedReplies = rmsBean.getExpectedReplies();
          rmsBean.setExpectedReplies(expectedReplies + 1);
        }

        // If we support the RM anonymous URI then rewrite the ws-a anon to use the RM equivalent.
        //(do should be done only for WSRM 1.1)
       
        if (Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(rmMsgCtx.getRMSpecVersion())) {
          String oldAddress = (replyTo == null) ? null : replyTo.getAddress();
          EndpointReference newReplyTo = SandeshaUtil.rewriteEPR(rmsBean, msgContext
              .getReplyTo(), configContext);
          String newAddress = (newReplyTo == null) ? null : newReplyTo.getAddress();
          if (newAddress != null && !newAddress.equals(oldAddress)) {
            // We have rewritten the replyTo. If this is the first message that we have needed to
            // rewrite then we should set the sequence up for polling, and once we have saved the
            // changes to the sequence then we can start the polling thread.
            msgContext.setReplyTo(newReplyTo);
            if (!rmsBean.isPollingMode()) {
              rmsBean.setPollingMode(true);
              startPolling = true;
            }
          }
        }
      }
    }
   
    RelatesTo relatesTo = msgContext.getRelatesTo();
    if(relatesTo != null) {
      rmsBean.setHighestOutRelatesTo(relatesTo.getValue());
    }

    // setting async ack endpoint for the server side. (if present)
    if (serverSide) {
      if (rmsBean.getToEPR() != null) {
        msgContext.setProperty(SandeshaClientConstants.AcksTo, rmsBean.getToEPR());
      }
    }

    // Update the rmsBean
        rmsBean.setApplicationMessageMessageId(msgContext.getMessageID());
        storageManager.getRMSBeanMgr().update(rmsBean);
   
    if(startPolling) {
      SandeshaUtil.startWorkersForSequence(msgContext.getConfigurationContext(), rmsBean);
    }
View Full Code Here

 
      //if toAddress is RMAnon we may need to terminate the request side sequence here.
      EndpointReference toEPR = createSeqMsg.getTo();
      if (toEPR.hasAnonymousAddress()) {
 
        RMSBean findBean = new RMSBean ();
        findBean.setReplyToEPR(toEPR.getAddress());
        findBean.setTerminationPauserForCS(true);
       
        //TODO recheck
        RMSBean rmsBean = storageManager.getRMSBeanMgr().findUnique(findBean);
        if (rmsBean!=null) {         
          //AckManager hs not done the termination. Do the termination here.
          MessageContext requestSideRefMessage = storageManager.retrieveMessageContext(rmsBean.getReferenceMessageStoreKey(),context);
          if (requestSideRefMessage==null) {
            FaultManager.makeCreateSequenceRefusedFault(createSeqRMMsg,
                SandeshaMessageHelper.getMessage(SandeshaMessageKeys.referencedMessageNotFound, rmsBean.getInternalSequenceID()),
                new Exception());           
            // Return false if an Exception hasn't been thrown.
            if (log.isDebugEnabled())
              log.debug("Exit: CreateSeqMsgProcessor::processInMessage " + Boolean.FALSE);       
            return false;
          }
         
          RMMsgContext requestSideRefRMMessage = MsgInitializer.initializeMessage(requestSideRefMessage);
          TerminateManager.addTerminateSequenceMessage(requestSideRefRMMessage, rmsBean.getInternalSequenceID(), rmsBean.getSequenceID(), storageManager);
        }
      }
       

      MessageContext outMessage = null;
 
      // Create the new sequence id, as well as establishing the beans that handle the
      // sequence state.
      RMDBean rmdBean = SequenceManager.setupNewSequence(createSeqRMMsg, storageManager, secManager, token);
       
      RMMsgContext createSeqResponse = RMMsgCreator.createCreateSeqResponseMsg(createSeqRMMsg, rmdBean);
      outMessage = createSeqResponse.getMessageContext();
      // Set a message ID for this Create Sequence Response message
      outMessage.setMessageID(SandeshaUtil.getUUID());
       
      createSeqResponse.setFlow(MessageContext.OUT_FLOW);
 
      // for making sure that this won't be processed again
      createSeqResponse.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");
     
      CreateSequenceResponse createSeqResPart = (CreateSequenceResponse) createSeqResponse
          .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE);
 
        // OFFER PROCESSING
      SequenceOffer offer = createSeqPart.getSequenceOffer();
      if (offer != null) {
        Accept accept = createSeqResPart.getAccept();
        if (accept == null) {
          if (log.isDebugEnabled())
            log.debug(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcceptPart));
          FaultManager.makeCreateSequenceRefusedFault(createSeqRMMsg,
                                                      SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcceptPart),
                                                      new Exception());
          // Return false if an Exception hasn't been thrown.
          if (log.isDebugEnabled())
            log.debug("Exit: CreateSeqMsgProcessor::processInMessage " + Boolean.FALSE);       
          return false;
        }
 
        // offered seq id
        String offeredSequenceID = offer.getIdentifer().getIdentifier();
       
        boolean offerEcepted = offerAccepted(offeredSequenceID, context, createSeqRMMsg, storageManager);
 
        if (offerEcepted) {
          // Setting the CreateSequence table entry for the outgoing
          // side.
          RMSBean rMSBean = new RMSBean();
          rMSBean.setSequenceID(offeredSequenceID);
          String outgoingSideInternalSequenceId = SandeshaUtil
              .getOutgoingSideInternalSequenceID(rmdBean.getSequenceID());
          rMSBean.setInternalSequenceID(outgoingSideInternalSequenceId);
          // this is a dummy value
          rMSBean.setCreateSeqMsgID(SandeshaUtil.getUUID());
           
          rMSBean.setToEPR(rmdBean.getToEPR());
          rMSBean.setAcksToEPR(rmdBean.getToEPR())// The acks need to flow back into this endpoint
          rMSBean.setReplyToEPR(rmdBean.getReplyToEPR());
          rMSBean.setLastActivatedTime(System.currentTimeMillis());
          rMSBean.setRMVersion(rmdBean.getRMVersion());
          rMSBean.setClientCompletedMessages(new RangeString());
 
          // Setting sequence properties for the outgoing sequence.
          // Only will be used by the server side response path. Will
          // be wasted properties for the client side.
           
          Endpoint endpoint = offer.getEndpoint();
          if (endpoint!=null) {
            // setting the OfferedEndpoint
            rMSBean.setOfferedEndPoint(endpoint.getEPR().getAddress());
          }
   
          rmdBean.setOutboundInternalSequence(outgoingSideInternalSequenceId);
          RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();
          rmdBeanMgr.update(rmdBean);
 
          // Store the inbound token (if any) with the new sequence
          rMSBean.setSecurityTokenData(rmdBean.getSecurityTokenData());
         
          // If this new sequence has anonymous acksTo, then we must poll for the acks
          // If the inbound sequence is targetted at the WSRM anonymous URI, we need to start
          // polling for this sequence.
          String acksTo = rMSBean.getAcksToEPR();
          EndpointReference reference = new EndpointReference(acksTo);
          if ((acksTo == null || reference.hasAnonymousAddress()) &&
            Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(createSeqRMMsg.getRMSpecVersion())) {
            rMSBean.setPollingMode(true);
          }
         
          // Set the SOAP Version for this sequence.
          rMSBean.setSoapVersion(SandeshaUtil.getSOAPVersion(createSeqRMMsg.getSOAPEnvelope()));
         
          if (isReplayModel(createSeqRMMsg)) {
            rMSBean.setReplayModel(true);
            rmdBean.setReplayModel(true);
          }
         
          storageManager.getRMSBeanMgr().insert(rMSBean);
         
View Full Code Here

  public static final RMSBean getRMSBeanFromInternalSequenceId(StorageManager storageManager, String internalSequenceID)
 
  throws SandeshaException {
    RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();
    RMSBean bean = new RMSBean();
    bean.setInternalSequenceID(internalSequenceID);
   
    bean = rmsBeanMgr.findUnique(bean);

    return bean;
  }
View Full Code Here

 
  public static final RMSBean getRMSBeanFromSequenceId(StorageManager storageManager, String sequenceID)
 
  throws SandeshaException {
    RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();
    RMSBean bean = new RMSBean();
    bean.setSequenceID(sequenceID);
   
    bean = rmsBeanMgr.findUnique(bean);

    return bean;
  }
View Full Code Here

      if (log.isDebugEnabled())
        log.debug("Exit: CreateSeqMsgProcessor::offerAccepted, " + false);
      return false;
    }

    RMSBean createSeqFindBean = new RMSBean();
    createSeqFindBean.setSequenceID(sequenceId);
    Collection arr = storageManager.getRMSBeanMgr().find(createSeqFindBean);

    if (arr.size() > 0) {
      if (log.isDebugEnabled())
        log.debug("Exit: CreateSeqMsgProcessor::offerAccepted, " + false);
View Full Code Here

TOP

Related Classes of org.apache.sandesha2.storage.beans.RMSBean

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.