Package org.apache.sandesha2.storage.beanmanagers

Examples of org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr


  }
 
  private static void cleanSendingSideData (ConfigurationContext configContext,String internalSequenceID, boolean serverSide) throws SandeshaException {
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configContext);
   
    SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropretyBeanMgr();
    SenderBeanMgr retransmitterBeanMgr = storageManager.getRetransmitterBeanMgr();
    CreateSeqBeanMgr createSeqBeanMgr = storageManager.getCreateSeqBeanMgr();
   
    String outSequenceID = SandeshaUtil.getSequenceProperty(internalSequenceID,Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID,configContext);
   
    if (!serverSide) {
      boolean stopListnerForAsyncAcks = false;
      SequencePropertyBean acksToBean = sequencePropertyBeanMgr.retrieve(internalSequenceID,Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);
       
      String addressingNamespace = SandeshaUtil.getSequenceProperty(internalSequenceID,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,configContext);
      String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace);
       
      if (acksToBean!=null) {
        String acksTo = acksToBean.getValue();
        if (acksTo!=null && !anonymousURI.equals(acksTo)) {
          stopListnerForAsyncAcks = true;
        }
      }
    }
   
    //removing retransmitterMgr entries
    Collection collection = retransmitterBeanMgr.find(internalSequenceID);
    Iterator iterator = collection.iterator();
    while (iterator.hasNext()) {
      SenderBean retransmitterBean = (SenderBean) iterator.next();
      retransmitterBeanMgr.delete(retransmitterBean.getMessageID());
    }
   
    //removing the createSeqMgrEntry
    CreateSeqBean findCreateSequenceBean = new CreateSeqBean ();
    findCreateSequenceBean.setInternalSequenceID(internalSequenceID);
    collection = createSeqBeanMgr.find(findCreateSequenceBean);
    iterator = collection.iterator();
    while (iterator.hasNext()) {
      CreateSeqBean createSeqBean = (CreateSeqBean) iterator.next();
      createSeqBeanMgr.delete(createSeqBean.getCreateSeqMsgID());
    }
   
    //removing sequence properties
    SequencePropertyBean findSequencePropertyBean1 = new SequencePropertyBean ();
    findSequencePropertyBean1.setSequenceID(internalSequenceID);
    collection = sequencePropertyBeanMgr.find(findSequencePropertyBean1);
    iterator = collection.iterator();
    while (iterator.hasNext()) {
      SequencePropertyBean sequencePropertyBean = (SequencePropertyBean) iterator.next();
      doUpdatesIfNeeded (outSequenceID,sequencePropertyBean,sequencePropertyBeanMgr);
     
      if (isProportyDeletable(sequencePropertyBean.getName())) {
        sequencePropertyBeanMgr.delete(sequencePropertyBean.getSequenceID(),sequencePropertyBean.getName());
      }
    }
  }
View Full Code Here


    StorageManager storageManager = SandeshaUtil
        .getSandeshaStorageManager(configurationContext);

    Transaction addTerminateSeqTransaction = storageManager.getTransaction();
   
    SequencePropertyBeanMgr seqPropMgr = storageManager
        .getSequencePropretyBeanMgr();

    SequencePropertyBean terminated = seqPropMgr.retrieve(outSequenceId,
        Sandesha2Constants.SequenceProperties.TERMINATE_ADDED);

    if (terminated != null && terminated.getValue() != null
        && "true".equals(terminated.getValue())) {
      String message = "Terminate was added previously.";
      log.info(message);
    }

    RMMsgContext terminateRMMessage = RMMsgCreator
        .createTerminateSequenceMessage(referenceMessage, outSequenceId,internalSequenceId);
    terminateRMMessage.setFlow(MessageContext.OUT_FLOW);
    terminateRMMessage.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE,"true");
   
    SequencePropertyBean toBean = seqPropMgr.retrieve(internalSequenceId,
        Sandesha2Constants.SequenceProperties.TO_EPR);

    EndpointReference toEPR = new EndpointReference ( toBean.getValue());
    if (toEPR == null) {
      String message = "To EPR has an invalid value";
      throw new SandeshaException(message);
    }

    terminateRMMessage.setTo(new EndpointReference(toEPR.getAddress()));
   
    String addressingNamespaceURI = SandeshaUtil.getSequenceProperty(internalSequenceId,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,configurationContext);
    String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceURI);
   
    String rmVersion = SandeshaUtil.getRMVersion(internalSequenceId,configurationContext);
    if (rmVersion==null)
      throw new SandeshaException ("Cant find the rmVersion of the given message");
    terminateRMMessage.setWSAAction(SpecSpecificConstants.getTerminateSequenceAction(rmVersion));
    terminateRMMessage.setSOAPAction(SpecSpecificConstants.getTerminateSequenceSOAPAction(rmVersion));

    SequencePropertyBean transportToBean = seqPropMgr.retrieve(internalSequenceId,Sandesha2Constants.SequenceProperties.TRANSPORT_TO);
    if (transportToBean!=null) {
      terminateRMMessage.setProperty(MessageContextConstants.TRANSPORT_URL,transportToBean.getValue());
    }
   
    try {
      terminateRMMessage.addSOAPEnvelope();
    } catch (AxisFault e) {
      throw new SandeshaException(e.getMessage());
    }

    String key = SandeshaUtil.getUUID();
   
    SenderBean terminateBean = new SenderBean();
    terminateBean.setMessageContextRefKey(key);

   
    storageManager.storeMessageContext(key,terminateRMMessage.getMessageContext());

   
    //Set a retransmitter lastSentTime so that terminate will be send with
    // some delay.
    //Otherwise this get send before return of the current request (ack).
    //TODO: refine the terminate delay.
    terminateBean.setTimeToSend(System.currentTimeMillis()
        + Sandesha2Constants.TERMINATE_DELAY);

    terminateBean.setMessageID(terminateRMMessage.getMessageId());
   
    //this will be set to true at the sender.
    terminateBean.setSend(true);
   
    terminateRMMessage.getMessageContext().setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING,
        Sandesha2Constants.VALUE_FALSE);
   
    terminateBean.setReSend(false);

    SenderBeanMgr retramsmitterMgr = storageManager
        .getRetransmitterBeanMgr();

    retramsmitterMgr.insert(terminateBean);
   
    SequencePropertyBean terminateAdded = new SequencePropertyBean();
    terminateAdded.setName(Sandesha2Constants.SequenceProperties.TERMINATE_ADDED);
    terminateAdded.setSequenceID(outSequenceId);
    terminateAdded.setValue("true");

    seqPropMgr.insert(terminateAdded);
   
    //This should be dumped to the storage by the sender
    TransportOutDescription transportOut = terminateRMMessage.getMessageContext().getTransportOut();
    terminateRMMessage.setProperty(Sandesha2Constants.ORIGINAL_TRANSPORT_OUT_DESC,transportOut);
    terminateRMMessage.setProperty(Sandesha2Constants.MESSAGE_STORE_KEY,key);
View Full Code Here

    long messageNumber = sequence.getMessageNumber().getMessageNumber();
    String sequenceID = sequence.getIdentifier().getIdentifier();
   
    ConfigurationContext configCtx = applicationRMMessage.getMessageContext().getConfigurationContext();
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx);
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
   
    boolean lastMessageNumberExceeded = false;
    String reason = null;
    SequencePropertyBean lastMessageBean = seqPropMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.LAST_OUT_MESSAGE_NO);
    if (lastMessageBean!=null) {
      long lastMessageNo = Long.parseLong(lastMessageBean.getValue());
      if (messageNumber>lastMessageNo) {
        lastMessageNumberExceeded = true;
        reason = "The message number of the message '" + messageNumber + "' exceeded the last message number '" + lastMessageNo + "'"+
View Full Code Here

  public RMMsgContext checkForSequenceClosed ( RMMsgContext referenceRMMessage, String sequenceID) throws SandeshaException {
    MessageContext referenceMessage = referenceRMMessage.getMessageContext();
    ConfigurationContext configCtx = referenceMessage.getConfigurationContext();
   
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx);
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
   
    boolean sequenceClosed = false;
    String reason = null;
    SequencePropertyBean sequenceClosedBean = seqPropMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.SEQUENCE_CLOSED);
    if (sequenceClosedBean!=null && Sandesha2Constants.VALUE_TRUE.equals(sequenceClosedBean.getValue()))  {
      sequenceClosed = true;
      reason = "The sequence with the id " + sequenceID + " was closed previously. Cannot accept this message";
    }
   
View Full Code Here

        CreateSequence createSequence = (CreateSequence) referenceRMMsgContext
            .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
        acksToStr = createSequence.getAcksTo().getAddress().getEpr()
            .getAddress();
      } else {
        SequencePropertyBeanMgr seqPropMgr = storageManager
            .getSequencePropretyBeanMgr();
        String sequenceId = data.getSequenceId();
        SequencePropertyBean acksToBean = seqPropMgr.retrieve(
            sequenceId, Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);
        if (acksToBean != null) {
          EndpointReference epr = new EndpointReference (acksToBean
              .getValue());
          if (epr != null)
View Full Code Here

      }
     
      return;
    }
   
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
   
    //setting acked msg no range
    Sequence sequence = (Sequence) rmMsgCtx
        .getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
    String sequenceId = sequence.getIdentifier().getIdentifier();
    ConfigurationContext configCtx = rmMsgCtx.getMessageContext()
        .getConfigurationContext();
    if (configCtx == null) {
      String message = "Configuration Context is null";
      log.debug(message);
      throw new SandeshaException(message);
    }

    faultMessageContext = faultManager.checkForUnknownSequence(rmMsgCtx,sequenceId);
    if (faultMessageContext != null) {
      ConfigurationContext configurationContext = msgCtx.getConfigurationContext();
      AxisEngine engine = new AxisEngine(configurationContext);
     
      try {
        engine.send(faultMessageContext.getMessageContext());
      } catch (AxisFault e) {
        throw new SandeshaException ("Could not send the fault message",e);
      }
     
      return;
    }
   
    //setting mustUnderstand to false.
    sequence.setMustUnderstand(false);
    rmMsgCtx.addSOAPEnvelope();
   
    //throwing a fault if the sequence is closed.
    faultMessageContext = faultManager. checkForSequenceClosed(rmMsgCtx,sequenceId);
    if (faultMessageContext != null) {
      ConfigurationContext configurationContext = msgCtx.getConfigurationContext();
      AxisEngine engine = new AxisEngine(configurationContext);
     
      try {
        engine.sendFault(faultMessageContext.getMessageContext());
      } catch (AxisFault e) {
        throw new SandeshaException ("Could not send the fault message",e);
      }
     
      return;
    }

    Transaction lastUpdatedTimeTransaction = storageManager.getTransaction();
   
    //updating the last activated time of the sequence.
    SequenceManager.updateLastActivatedTime(sequenceId,configCtx);
    lastUpdatedTimeTransaction.commit();
   
    Transaction updataMsgStringTransaction = storageManager
        .getTransaction();
   
    SequencePropertyBean msgsBean = seqPropMgr.retrieve(sequenceId,
        Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES);

    long msgNo = sequence.getMessageNumber().getMessageNumber();
    if (msgNo == 0) {
      String message = "Wrong message number";
      log.debug(message);
      throw new SandeshaException(message);
    }
   
    String key = SandeshaUtil.getUUID()//key to store the message.
   
    //updating the Highest_In_Msg_No property which gives the highest message number retrieved from this sequence.
    String highetsInMsgNoStr = SandeshaUtil.getSequenceProperty(sequenceId,Sandesha2Constants.SequenceProperties.HIGHEST_IN_MSG_NUMBER,configCtx);
    String highetsInMsgKey = SandeshaUtil.getSequenceProperty(sequenceId,Sandesha2Constants.SequenceProperties.HIGHEST_IN_MSG_KEY,configCtx);
   
    long highestInMsgNo=0;
    if (highetsInMsgNoStr!=null) {
      highestInMsgNo = Long.parseLong(highetsInMsgNoStr);
    }
   
    if (msgNo>highestInMsgNo) {
      highestInMsgNo = msgNo;
     
      String str = new Long(msgNo).toString();
      SequencePropertyBean highestMsgNoBean = new SequencePropertyBean (sequenceId,Sandesha2Constants.SequenceProperties.HIGHEST_IN_MSG_NUMBER,str);
      SequencePropertyBean highestMsgKeyBean = new SequencePropertyBean (sequenceId,Sandesha2Constants.SequenceProperties.HIGHEST_IN_MSG_KEY,key);
     
      if (highetsInMsgNoStr!=null) {
        seqPropMgr.update(highestMsgNoBean);
        seqPropMgr.update(highestMsgKeyBean);
      }else{
        seqPropMgr.insert(highestMsgNoBean);
        seqPropMgr.insert(highestMsgKeyBean);
      }
    }
   
    String messagesStr = "";
    if (msgsBean!=null)
      messagesStr = (String) msgsBean.getValue();
    else {
      msgsBean = new SequencePropertyBean ();
      msgsBean.setSequenceID(sequenceId);
      msgsBean.setName(Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES);
      msgsBean.setValue(messagesStr);
    }
     

    if (msgNoPresentInList(messagesStr, msgNo)
        && (Sandesha2Constants.QOS.InvocationType.DEFAULT_INVOCATION_TYPE == Sandesha2Constants.QOS.InvocationType.EXACTLY_ONCE)) {
      //this is a duplicate message and the invocation type is
      // EXACTLY_ONCE.
      rmMsgCtx.pause();
    }

    if (messagesStr != "" && messagesStr != null)
      messagesStr = messagesStr + "," + Long.toString(msgNo);
    else
      messagesStr = Long.toString(msgNo);

    msgsBean.setValue(messagesStr);
    seqPropMgr.update(msgsBean);

    updataMsgStringTransaction.commit();

    Transaction invokeTransaction = storageManager.getTransaction();

    //  Pause the messages bean if not the right message to invoke.
    NextMsgBeanMgr mgr = storageManager.getNextMsgBeanMgr();
    NextMsgBean bean = mgr.retrieve(sequenceId);

    if (bean == null)
      throw new SandeshaException("Error- The sequence does not exist");

    InvokerBeanMgr storageMapMgr = storageManager.getStorageMapBeanMgr();
   
    //inorder invocation is still a global property
    boolean inOrderInvocation = SandeshaUtil.getPropertyBean(msgCtx.getConfigurationContext().getAxisConfiguration()).isInOrder();
   
    if (inOrderInvocation) {
     
      //pause the message
      rmMsgCtx.pause();
     
      SequencePropertyBean incomingSequenceListBean = (SequencePropertyBean) seqPropMgr
          .retrieve(
              Sandesha2Constants.SequenceProperties.ALL_SEQUENCES,
              Sandesha2Constants.SequenceProperties.INCOMING_SEQUENCE_LIST);

      if (incomingSequenceListBean == null) {
        ArrayList incomingSequenceList = new ArrayList();
        incomingSequenceListBean = new SequencePropertyBean();
        incomingSequenceListBean
            .setSequenceID(Sandesha2Constants.SequenceProperties.ALL_SEQUENCES);
        incomingSequenceListBean
            .setName(Sandesha2Constants.SequenceProperties.INCOMING_SEQUENCE_LIST);
        incomingSequenceListBean.setValue(incomingSequenceList
            .toString());

        seqPropMgr.insert(incomingSequenceListBean);
      }

      ArrayList incomingSequenceList = SandeshaUtil
          .getArrayListFromString(incomingSequenceListBean.getValue());

      //Adding current sequence to the incoming sequence List.
      if (!incomingSequenceList.contains(sequenceId)) {
        incomingSequenceList.add(sequenceId);

        //saving the property.
        incomingSequenceListBean.setValue(incomingSequenceList
            .toString());
        seqPropMgr.insert(incomingSequenceListBean);
      }

      //saving the message.
      try {
        storageManager.storeMessageContext(key,rmMsgCtx
View Full Code Here

    MessageContext msgCtx = rmMsgCtx.getMessageContext();

    StorageManager storageManager = SandeshaUtil
        .getSandeshaStorageManager(msgCtx.getConfigurationContext());
    SequencePropertyBeanMgr seqPropMgr = storageManager
        .getSequencePropretyBeanMgr();

    Sequence sequence = (Sequence) rmMsgCtx
        .getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
    String sequenceId = sequence.getIdentifier().getIdentifier();
View Full Code Here

      }
    }
   
    //retrieving the the storage manager
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configContext);
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();

    Transaction outHandlerTransaction = storageManager.getTransaction();
    boolean serverSide = msgContext.isServerSide()

    // setting message Id if null
    if (msgContext.getMessageID() == null)
      msgContext.setMessageID(SandeshaUtil.getUUID());

    // find internal sequence id
    String internalSequenceId = null;

    String storageKey = SandeshaUtil.getUUID()//the key which will be used to store this message.
   
    /* Internal sequence id is the one used to refer to the sequence (since
    actual sequence id is not available when first msg arrives)
    server side - a derivation of the sequenceId of the incoming sequence
    client side - a derivation of wsaTo & SeequenceKey */

    boolean lastMessage = false;
    if (serverSide) {
      // getting the request message and rmMessage.
      MessageContext reqMsgCtx;
      try {
        reqMsgCtx = msgContext.getOperationContext().getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
      } catch (AxisFault e) {
        throw new SandeshaException (e);
      }

      RMMsgContext requestRMMsgCtx = MsgInitializer.initializeMessage(reqMsgCtx);

      Sequence reqSequence = (Sequence) requestRMMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
      if (reqSequence == null) {
        String message = "Sequence part is null";
        log.debug(message);
        throw new SandeshaException(message);
      }

      String incomingSeqId = reqSequence.getIdentifier().getIdentifier();
      if (incomingSeqId == null || incomingSeqId == "") {
        String message = "Invalid seqence Id";
        log.debug(message);
        throw new SandeshaException(message);
      }

      long requestMsgNo = reqSequence.getMessageNumber().getMessageNumber();
     
      internalSequenceId = SandeshaUtil.getOutgoingSideInternalSequenceID(incomingSeqId);
     
      //deciding weather the last message.
      String requestLastMsgNoStr = SandeshaUtil.getSequenceProperty(incomingSeqId,Sandesha2Constants.SequenceProperties.LAST_IN_MESSAGE_NO,configContext);
      if (requestLastMsgNoStr!=null) {
        long requestLastMsgNo = Long.parseLong(requestLastMsgNoStr);
        if (requestLastMsgNo==requestMsgNo)
          lastMessage = true;
      }

    } else {
      // set the internal sequence id for the client side.
      EndpointReference toEPR = msgContext.getTo();
      if (toEPR == null || toEPR.getAddress() == null || "".equals(toEPR.getAddress())) {
        String message = "TO End Point Reference is not set correctly. This is a must for the sandesha client side.";
        log.debug(message);
        throw new SandeshaException(message);
      }

      String to = toEPR.getAddress();
      String sequenceKey = (String) msgContext.getProperty(SandeshaClientConstants.SEQUENCE_KEY);
      internalSequenceId = SandeshaUtil.getInternalSequenceID(to,sequenceKey);
     
      String lastAppMessage = (String) msgContext.getProperty(SandeshaClientConstants.LAST_MESSAGE);
      if (lastAppMessage!=null && "true".equals(lastAppMessage))
        lastMessage = true;
    }

    /* checking weather the user has given the messageNumber (most of the cases this will not be the case where
       the system will generate the message numbers */

    //User should set it as a long object.
    Long messageNumberLng = (Long) msgContext.getProperty(SandeshaClientConstants.MESSAGE_NUMBER);
   
    long givenMessageNumber = -1;
    if (messageNumberLng!=null) {
      givenMessageNumber = messageNumberLng.longValue();
      if (givenMessageNumber<=0) {
        throw new SandeshaException ("The givem message number value is invalid (has to be larger than zero)");
      }
    }
   
    //the message number that was last used.
    long systemMessageNumber = getPreviousMsgNo(configContext, internalSequenceId);
   
    //The number given by the user has to be larger than the last stored number.
    if (givenMessageNumber>0 && givenMessageNumber<=systemMessageNumber) {
      String message = "The given message number is not larger than value of the last sent message.";
      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 fist message (systemMessageNumber = -1)
      messageNumber = 1;
    }
   
    //A dummy message is a one which will not be processed as a actual application message.
    //The RM handlers will simply let these go.
    String dummyMessageString = (String) msgContext.getOptions().getProperty(SandeshaClientConstants.DUMMY_MESSAGE);
    boolean dummyMessage = false;
    if (dummyMessageString!=null && Sandesha2Constants.VALUE_TRUE.equals(dummyMessageString))
      dummyMessage = true;
   
    //saving the used message number
    if (!dummyMessage)
      setNextMsgNo(configContext,internalSequenceId,messageNumber);
     
    //set this as the response highest message.
    SequencePropertyBean responseHighestMsgBean = new SequencePropertyBean (
        internalSequenceId,
        Sandesha2Constants.SequenceProperties.HIGHEST_OUT_MSG_NUMBER,
        new Long (messageNumber).toString()
    );
    seqPropMgr.insert(responseHighestMsgBean);
   
    if (lastMessage) {
 
      SequencePropertyBean responseHighestMsgKeyBean = new SequencePropertyBean (
          internalSequenceId,
          Sandesha2Constants.SequenceProperties.HIGHEST_OUT_MSG_KEY,
          storageKey
      )
     
      SequencePropertyBean responseLastMsgKeyBean = new SequencePropertyBean (
          internalSequenceId,
          Sandesha2Constants.SequenceProperties.LAST_OUT_MESSAGE_NO,
          new Long (messageNumber).toString()
      )
     
      seqPropMgr.insert(responseHighestMsgKeyBean);
      seqPropMgr.insert(responseLastMsgKeyBean);
    }
   
    boolean sendCreateSequence = false;

    SequencePropertyBean outSeqBean = seqPropMgr.retrieve(
        internalSequenceId,
        Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);

    // setting async ack endpoint for the server side. (if present)
    if (serverSide) {
      String incomingSequenceID = SandeshaUtil
          .getServerSideIncomingSeqIdFromInternalSeqId(internalSequenceId);
      SequencePropertyBean incomingToBean = seqPropMgr.retrieve(
          incomingSequenceID,
          Sandesha2Constants.SequenceProperties.TO_EPR);
      if (incomingToBean != null) {
        String incomingTo = incomingToBean.getValue();
        msgContext.setProperty(SandeshaClientConstants.AcksTo, incomingTo);
      }
    }

   
    //FINDING THE SPEC VERSION
    String specVersion = null;
    if (msgContext.isServerSide()) {
      //in the server side, get the RM version from the request sequence.
      MessageContext requestMessageContext;
      try {
        requestMessageContext = msgContext.getOperationContext().getMessageContext(AxisOperationFactory.MESSAGE_LABEL_IN_VALUE);
      } catch (AxisFault e) {
        throw new SandeshaException (e);
      }
     
      if (requestMessageContext==null)
        throw new SandeshaException ("Request message context is null, cant find out the request side sequenceID");
     
      RMMsgContext requestRMMsgCtx = MsgInitializer.initializeMessage(requestMessageContext);
      Sequence sequence = (Sequence) requestRMMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
     
      String requestSequenceID = sequence.getIdentifier().getIdentifier();
      SequencePropertyBean specVersionBean = seqPropMgr.retrieve(requestSequenceID,Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
      if (specVersionBean==null)
        throw new SandeshaException ("SpecVersion sequence property bean is not available for the incoming sequence. Cant find the RM version for outgoing side");
     
      specVersion = specVersionBean.getValue();
    } else {
      //in the client side, user will set the RM version.
      specVersion = (String) msgContext.getProperty(SandeshaClientConstants.RM_SPEC_VERSION);
    }
   
    if (specVersion==null)
      specVersion = SpecSpecificConstants.getDefaultSpecVersion();   //TODO change the default to v1_1.
   
    if (messageNumber == 1) {
      if (outSeqBean == null) { // out sequence will be set for the server side, in the case of an offer.
        sendCreateSequence = true;   // message number being one and not having an out sequence, implies that a create sequence has to be send.
      }

      // if fist message - setup the sending side sequence - both for the server and the client sides
      SequenceManager.setupNewClientSequence(msgContext, internalSequenceId,specVersion);
    }

    ServiceContext serviceContext = msgContext.getServiceContext();
    OperationContext operationContext = msgContext.getOperationContext();
   
    //SENDING THE CREATE SEQUENCE.
    if (sendCreateSequence) {
      SequencePropertyBean responseCreateSeqAdded = seqPropMgr
          .retrieve(internalSequenceId,Sandesha2Constants.SequenceProperties.OUT_CREATE_SEQUENCE_SENT);

      String addressingNamespaceURI = SandeshaUtil.getSequenceProperty(internalSequenceId,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,configContext);
      String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceURI);
     
      if (responseCreateSeqAdded == null) {
        responseCreateSeqAdded = new SequencePropertyBean(
            internalSequenceId,Sandesha2Constants.SequenceProperties.OUT_CREATE_SEQUENCE_SENT,"true");
        seqPropMgr.insert(responseCreateSeqAdded);

        String acksTo = null;
        if (serviceContext != null)
          acksTo = (String) msgContext.getProperty(SandeshaClientConstants.AcksTo);

        if (msgContext.isServerSide()) {
          // we do not set acksTo value to anonymous when the create
          // sequence is send from the server.
          MessageContext requestMessage;
          try {
            requestMessage = operationContext.getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
          } catch (AxisFault e) {
            throw new SandeshaException (e);
          }
         
          if (requestMessage == null) {
            String message = "Request message is not present";
            log.debug(message);
            throw new SandeshaException(message);
          }
          acksTo = requestMessage.getTo().getAddress();

        } else {
          if (acksTo == null)
            acksTo = anonymousURI;
        }

        if (!anonymousURI.equals(acksTo) && !serverSide) {
          String transportIn = (String) configContext   //TODO verify
              .getProperty(MessageContext.TRANSPORT_IN);
          if (transportIn == null)
            transportIn = org.apache.axis2.Constants.TRANSPORT_HTTP;
        } else if (acksTo == null && serverSide) {
          String incomingSequencId = SandeshaUtil.getServerSideIncomingSeqIdFromInternalSeqId(internalSequenceId);
          SequencePropertyBean bean = seqPropMgr.retrieve(
              incomingSequencId,Sandesha2Constants.SequenceProperties.REPLY_TO_EPR);
          if (bean != null) {
            EndpointReference acksToEPR = new EndpointReference(bean.getValue());
            if (acksToEPR != null)
              acksTo = (String) acksToEPR.getAddress();
View Full Code Here

    createSeqRMMessage.setFlow(MessageContext.OUT_FLOW);
    CreateSequence createSequencePart = (CreateSequence) createSeqRMMessage.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);

    //retrieving the storage manager.
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx);
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
    CreateSeqBeanMgr createSeqMgr = storageManager.getCreateSeqBeanMgr();
    SenderBeanMgr retransmitterMgr = storageManager.getRetransmitterBeanMgr();
   
    SequenceOffer offer = createSequencePart.getSequenceOffer();
    if (offer != null) {
      String offeredSequenceId = offer.getIdentifer().getIdentifier();

      SequencePropertyBean offeredSequenceBean = new SequencePropertyBean();
      offeredSequenceBean.setName(Sandesha2Constants.SequenceProperties.OFFERED_SEQUENCE);
      offeredSequenceBean.setSequenceID(internalSequenceId);
      offeredSequenceBean.setValue(offeredSequenceId);

      seqPropMgr.insert(offeredSequenceBean);
    }

    MessageContext createSeqMsg = createSeqRMMessage.getMessageContext();
    createSeqMsg.setRelationships(null); // create seq msg does not relateTo anything
View Full Code Here

    SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil.getSOAPVersion(rmMsg.getSOAPEnvelope()));
    ConfigurationContext configurationContext = rmMsg.getMessageContext().getConfigurationContext();

    //retrieving storage manager
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(msg.getConfigurationContext());
    SequencePropertyBeanMgr sequencePropertyMgr = storageManager.getSequencePropretyBeanMgr();
    SenderBeanMgr retransmitterMgr = storageManager.getRetransmitterBeanMgr();

    SequencePropertyBean toBean = sequencePropertyMgr.retrieve(
        internalSequenceId,Sandesha2Constants.SequenceProperties.TO_EPR);
    SequencePropertyBean replyToBean = sequencePropertyMgr.retrieve(
        internalSequenceId,Sandesha2Constants.SequenceProperties.REPLY_TO_EPR);

    // again - looks weird in the client side - but consistent
    SequencePropertyBean outSequenceBean = sequencePropertyMgr.retrieve(
        internalSequenceId,Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);

    if (toBean == null) {
      String message = "To is null";
      log.debug(message);
      throw new SandeshaException(message);
    }

    EndpointReference toEPR = new EndpointReference(toBean.getValue());
   
    EndpointReference replyToEPR = null;
    if (replyToBean != null) {
      replyToEPR = new EndpointReference(replyToBean.getValue());
    }

    if (toEPR == null || toEPR.getAddress() == null || toEPR.getAddress() == "") {
      String message = "To Property has an invalid value";
      log.debug(message);
      throw new SandeshaException(message);
    }

    String newToStr = null;
    if (msg.isServerSide()) {
      try {
        MessageContext requestMsg = msg.getOperationContext().getMessageContext(
                OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
        if (requestMsg != null) {
          newToStr = requestMsg.getReplyTo().getAddress();
        }
      } catch (AxisFault e) {
        throw new SandeshaException(e.getMessage());
      }
    }

    if (newToStr != null)
      rmMsg.setTo(new EndpointReference(newToStr));
    else
      rmMsg.setTo(toEPR);

    if (replyToEPR != null)
      rmMsg.setReplyTo(replyToEPR);

    String rmVersion = SandeshaUtil.getRMVersion(internalSequenceId,configurationContext);
    if (rmVersion==null)
      throw new SandeshaException ("Cant find the rmVersion of the given message");
   
    String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
   
    Sequence sequence = new Sequence(factory,rmNamespaceValue);
    MessageNumber msgNumber = new MessageNumber(factory,rmNamespaceValue);
    msgNumber.setMessageNumber(messageNumber);
    sequence.setMessageNumber(msgNumber);

    boolean lastMessage = false;
    // setting last message
    if (msg.isServerSide()) {
      MessageContext requestMsg = null;

      try {
        requestMsg = msg.getOperationContext().getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
      } catch (AxisFault e) {
        throw new SandeshaException(e.getMessage());
      }

      RMMsgContext reqRMMsgCtx = MsgInitializer.initializeMessage(requestMsg);
      Sequence requestSequence = (Sequence) reqRMMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
      if (requestSequence == null) {
        String message = "Request Sequence is null";
        log.debug(message);
        throw new SandeshaException(message);
      }

      if (requestSequence.getLastMessage() != null) {
        lastMessage = true;
        sequence.setLastMessage(new LastMessage(factory,rmNamespaceValue));

      }

    } else {
      // client side

      OperationContext operationContext = msg.getOperationContext();
      if (operationContext != null) {
        Object obj = msg.getProperty(SandeshaClientConstants.LAST_MESSAGE);
        if (obj != null && "true".equals(obj)) {
          lastMessage = true;
         
          SequencePropertyBean specVersionBean = sequencePropertyMgr.retrieve(internalSequenceId,Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
          if (specVersionBean==null)
            throw new SandeshaException ("Spec version bean is not set");
         
          String specVersion = specVersionBean.getValue();
          if (SpecSpecificConstants.isLastMessageIndicatorRequired(specVersion))
View Full Code Here

TOP

Related Classes of org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr

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.