Package org.apache.sandesha2.storage

Examples of org.apache.sandesha2.storage.Transaction


      return response;
   
    SOAPFault faultPart = envelope.getBody().getFault();

    if (faultPart != null) {
      Transaction transaction = null;

      try {
        transaction = storageManager.getTransaction();

        // constructing the fault
        AxisFault axisFault = getAxisFaultFromFromSOAPFault(faultPart);
        response = manageIncomingFault (axisFault, rmMsgCtx, faultPart);
       
        if(transaction != null && transaction.isActive()) transaction.commit();
        transaction = null;
      } finally {
        if (transaction != null && transaction.isActive())
          transaction.rollback();
      }
    }
    return response;
  }
View Full Code Here


      if(lock != null && !lock.ownsLock(workId, this)) {
        if (log.isDebugEnabled()) log.debug("Exit: SenderWorker::run, another worker holds the lock");
        return;
      }

    Transaction transaction = null;
   
    try {
      StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext, configurationContext.getAxisConfiguration());
      SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
     
      transaction = storageManager.getTransaction();

      String key = senderBean.getMessageContextRefKey();
      MessageContext msgCtx = null;
      RMMsgContext   rmMsgCtx = null;
      if(messageToSend != null) {
        msgCtx = messageToSend.getMessageContext();
        rmMsgCtx = messageToSend;
      } else {
        msgCtx = storageManager.retrieveMessageContext(key, configurationContext);
     
        if (msgCtx == null) {
          // This sender bean has already been processed
         
          if(transaction != null && transaction.isActive()) transaction.commit();
          transaction = null;

          return;
        }
     
        rmMsgCtx = MsgInitializer.initializeMessage(msgCtx);
      }

      // sender will not send the message if following property is
      // set and not true.
      // But it will set if it is not set (null)

      // This is used to make sure that the mesage get passed the
      // Sandesha2TransportSender.

      String qualifiedForSending = (String) msgCtx.getProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING);
      if (qualifiedForSending != null && !qualifiedForSending.equals(Sandesha2Constants.VALUE_TRUE)) {
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, !qualified for sending");
       
        if(transaction != null && transaction.isActive()) {
          transaction.commit();
          transaction = null;
        }
       
        return;
      }

      if (msgCtx == null) {
        if (log.isDebugEnabled())
          log.debug(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.sendHasUnavailableMsgEntry));
       
        if(transaction != null && transaction.isActive()) {
          transaction.commit();
          transaction = null;
        }
       
        return;     
      }

      // operation is the lowest level Sandesha2 should be attached
      ArrayList<Integer> msgsNotToSend = SandeshaUtil.getPropertyBean(msgCtx.getAxisOperation()).getMsgTypesToDrop();

      if (msgsNotToSend != null && msgsNotToSend.contains(new Integer(rmMsgCtx.getMessageType()))) {
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, message type to be dropped " + rmMsgCtx.getMessageType());
       
        if(transaction != null && transaction.isActive()) {
          transaction.commit();
          transaction = null;
        }
       
        return
      }

      // If we are sending to the anonymous URI then we _must_ have a transport waiting,
      // or the message can't go anywhere. If there is nothing here then we leave the
      // message in the sender queue, and a MakeConnection (or a retransmitted request)
      // will hopefully pick it up soon.
      Boolean makeConnection = (Boolean) msgCtx.getProperty(Sandesha2Constants.MAKE_CONNECTION_RESPONSE);
      EndpointReference toEPR = msgCtx.getTo();

      MessageContext inMsg = null;
      OperationContext op = msgCtx.getOperationContext();
     
      RequestResponseTransport t = (RequestResponseTransport) msgCtx.getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
     
      if (t==null) {
        if (op != null)
          inMsg = op.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        if (inMsg != null)
          t = (RequestResponseTransport) inMsg.getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
      }

      // If we are anonymous, and this is not a makeConnection, then we must have a transport waiting
      if((toEPR==null || toEPR.hasAnonymousAddress()) &&
         (makeConnection == null || !makeConnection.booleanValue()) &&
         (t == null || !t.getStatus().equals(RequestResponseTransportStatus.WAITING))) {
       
        // Mark this sender bean so that we know that the transport is unavailable, if the
        // bean is still stored.
        SenderBean bean = senderBeanMgr.retrieve(senderBean.getMessageID());
        if(bean != null && bean.isTransportAvailable()) {
          bean.setTransportAvailable(false);
          senderBeanMgr.update(bean);
        }
       
        // Commit the update
        if(transaction != null && transaction.isActive()) transaction.commit();
        transaction = null;
       
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, no response transport for anonymous message");
        return;
      }
     
      int messageType = senderBean.getMessageType();
     
      if (isAckPiggybackableMsgType(messageType)) {
        // Commit the update
        if(transaction != null && transaction.isActive()) transaction.commit();
        transaction = storageManager.getTransaction();

        // Piggyback ack messages based on the 'To' address of the message
        AcknowledgementManager.piggybackAcksIfPresent(rmMsgCtx, storageManager);
      }
      if (transaction != null && transaction.isActive())
        transaction.commit();     
     
      transaction = storageManager.getTransaction();

      /*Removing the sending of AckRequested msgs as has performance impact.
        It could be rewritten to send AckRequested headers infrequantly and
        hence be less of a performance impact.  Functionally it
        may be required to interop with other implementations but until
        the problem occurs it's best not to do it at all and keep performance
        as optimal as possible
      //If this is an application msg we need to add an ackRequest to the header   
      if(messageType == Sandesha2Constants.MessageTypes.APPLICATION){       
        //Add an ackRequest       
        RMSBean rmsBean = SandeshaUtil.getRMSBeanFromSequenceId(storageManager, senderBean.getSequenceID());       
        RMMsgCreator.addAckRequest(rmMsgCtx, senderBean.getSequenceID(), rmsBean);               
        if (transaction != null && transaction.isActive())          
          transaction.commit();
       
        transaction = storageManager.getTransaction();     
      } */
     
      //if this is a sync RM exchange protocol we always have to add an ack
      boolean ackPresent = false;
      Iterator it = rmMsgCtx.getSequenceAcknowledgements();
      if (it.hasNext())
        ackPresent = true;
     
      if (!ackPresent && toEPR.hasAnonymousAddress()
          && rmMsgCtx.getMessageContext().isServerSide()
          &&
        (messageType==Sandesha2Constants.MessageTypes.APPLICATION ||
           messageType==Sandesha2Constants.MessageTypes.UNKNOWN ||
           messageType==Sandesha2Constants.MessageTypes.LAST_MESSAGE)) {
       
        String inboundSequenceId = senderBean.getInboundSequenceId();
        if (inboundSequenceId==null)
          throw new SandeshaException ("InboundSequenceID is not set for the sequence:" + senderBean.getSequenceID());
       
        RMDBean incomingSequenceBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, inboundSequenceId);

        if (incomingSequenceBean!=null)
          RMMsgCreator.addAckMessage(rmMsgCtx, inboundSequenceId, incomingSequenceBean, false, true);
      }

      if (transaction != null && transaction.isActive())
        transaction.commit();     
     
      transaction = storageManager.getTransaction();
     
      senderBean = updateMessage(rmMsgCtx,senderBean,storageManager);

      if (senderBean == null) {
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, !continueSending");
       
        if(transaction != null && transaction.isActive()) {
          transaction.rollback();
          transaction = null;
        }
       
        return;
      }

      // Although not actually sent yet, update the send count to indicate an attempt
      if (senderBean.isReSend()) {
        senderBeanMgr.update(senderBean);
      }

      // sending the message
      boolean successfullySent = false;
     
      // No need to redecorate application messages ... only for rm protocol messages
      if(Sandesha2Constants.MessageTypes.APPLICATION!=senderBean.getMessageType()){
        //try to redecorate the EPR if necessary
        if (log.isDebugEnabled())
          log.debug("Redecorate EPR : " + msgCtx.getEnvelope().getHeader());
        EndpointReference replyToEPR = msgCtx.getReplyTo();
        if(replyToEPR!=null){
          replyToEPR = SandeshaUtil.getEPRDecorator(msgCtx.getConfigurationContext()).decorateEndpointReference(replyToEPR);
          msgCtx.setReplyTo(replyToEPR);
        }
      }
      // have to commit the transaction before sending. This may
      // get changed when WS-AT is available.
      if(transaction != null) {
        transaction.commit();
        transaction = null;
      }

      boolean processResponseForFaults = false;
      try {
        InvocationResponse response = InvocationResponse.CONTINUE;
       
        if(storageManager.requiresMessageSerialization()) {
          if(msgCtx.isPaused()) {
            if (log.isDebugEnabled())
              log.debug("Resuming a send for message : " + msgCtx.getEnvelope().getHeader());
            msgCtx.setPaused(false);
            msgCtx.setProperty(MessageContext.TRANSPORT_NON_BLOCKING, Boolean.FALSE);
            response = AxisEngine.resumeSend(msgCtx);
          } else {
            if (log.isDebugEnabled())
              log.debug("Sending a message : " + msgCtx.getEnvelope().getHeader());
            msgCtx.setProperty(MessageContext.TRANSPORT_NON_BLOCKING, Boolean.FALSE);
            AxisEngine.send(msgCtx)// TODO check if this should return an invocation response
          }
        } else {
 
          ArrayList<Handler> retransmittablePhases = (ArrayList<Handler>) msgCtx.getProperty(Sandesha2Constants.RETRANSMITTABLE_PHASES);
          if (retransmittablePhases!=null) {
            msgCtx.setExecutionChain(retransmittablePhases);
          } else {
            ArrayList<Handler> emptyExecutionChain = new ArrayList<Handler>();
            msgCtx.setExecutionChain(emptyExecutionChain);
          }
         
          msgCtx.setCurrentHandlerIndex(0);
          msgCtx.setCurrentPhaseIndex(0);
          msgCtx.setPaused(false);
       
          if (log.isDebugEnabled())
            log.debug("Resuming a send for message : " + msgCtx.getEnvelope().getHeader());
              msgCtx.setProperty(MessageContext.TRANSPORT_NON_BLOCKING, Boolean.FALSE);
          response = AxisEngine.resumeSend(msgCtx);
        }
        if(log.isDebugEnabled()) log.debug("Engine resume returned " + response);
        if(response != InvocationResponse.SUSPEND) {
          if(t != null) {
            if(log.isDebugEnabled()) log.debug("Signalling transport in " + t);
            t.signalResponseReady();
          }
        }
       
        successfullySent = true;
       
      } catch (AxisFault e) {
        //this is a possible SOAP 1.2 Fault. So letting it proceed.
       
        processResponseForFaults = true;
       
        recordError(e, rmMsgCtx, storageManager);
       
      } catch (Exception e) {
        String message = SandeshaMessageHelper.getMessage(
            SandeshaMessageKeys.sendMsgError, e.toString());
       
        if (log.isDebugEnabled())
          log.debug(message, e);
       
        recordError(e, rmMsgCtx, storageManager);
       
      }
      // Establish the transaction for post-send processing
      transaction = storageManager.getTransaction();

      // update or delete only if the object is still present.
      SenderBean bean1 = senderBeanMgr
          .retrieve(senderBean.getMessageID());
      if (bean1 != null) {
        if (senderBean.isReSend()) {
          bean1.setTimeToSend(senderBean.getTimeToSend());
          senderBeanMgr.update(bean1);
        } else {
          senderBeanMgr.delete(bean1.getMessageID());

          // removing the message from the storage.
          String messageStoredKey = bean1.getMessageContextRefKey();
          storageManager.removeMessageContext(messageStoredKey);
        }
      }

      // Commit the transaction to release the SenderBean

      if (transaction!=null)
        transaction.commit();
     
      transaction = null;

      if ((processResponseForFaults || successfullySent) && !msgCtx.isServerSide())
        checkForSyncResponses(msgCtx);
     
      if ((rmMsgCtx.getMessageType() == Sandesha2Constants.MessageTypes.TERMINATE_SEQ)
          &&
           (Sandesha2Constants.SPEC_2005_02.NS_URI.equals(rmMsgCtx.getRMNamespaceValue()))) {
        try {
          transaction = storageManager.getTransaction();
          //terminate message sent using the SandeshaClient. Since the terminate message will simply get the
          //InFlow of the reference message get called which could be zero sized (OutOnly operations).
         
          // terminate sending side if this is the WSRM 1.0 spec.
          // If the WSRM versoion is 1.1 termination will happen in the terminate sequence response message.
         
          TerminateSequence terminateSequence = rmMsgCtx.getTerminateSequence();
          String sequenceID = terminateSequence.getIdentifier().getIdentifier();
 
          RMSBean rmsBean = SandeshaUtil.getRMSBeanFromSequenceId(storageManager, sequenceID);
          TerminateManager.terminateSendingSide(rmsBean, storageManager, false, null);
         
          if(transaction != null && transaction.isActive()) transaction.commit();
          transaction = null;
        } finally {
          if(transaction != null && transaction.isActive()) {
            transaction.rollback();
            transaction = null;
          }
        }
      }

    } catch (Exception e) {
      if (log.isDebugEnabled()) log.debug("Caught exception", e);
    } finally {
      if (lock!=null && workId!=null) {
        lock.removeWork(workId);
      }

      if (transaction!=null && transaction.isActive()) {
        try {
          transaction.rollback();
        } catch (SandeshaStorageException e) {
          if (log.isWarnEnabled())
            log.warn("Caught exception rolling back transaction", e);
        }
      }
View Full Code Here

 
  private void recordError (Exception e, RMMsgContext outRMMsg, StorageManager storageManager) throws SandeshaStorageException {
    // Store the Exception as a sequence property to enable the client to lookup the last
    // exception time and timestamp.
   
    Transaction transaction = null;
   
    try
    {
      // Get the internal sequence id from the context
      String internalSequenceId = (String)outRMMsg.getProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID);
      if(internalSequenceId == null) internalSequenceId = senderBean.getInternalSequenceID();
     
      if(internalSequenceId != null) {
        // Create a new Transaction
        transaction = storageManager.getTransaction();
       
        RMSBean bean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, internalSequenceId);
     
        if (bean != null) {           
          bean.setLastSendError(e);
          bean.setLastSendErrorTimestamp(System.currentTimeMillis());

          // Update the RMSBean
          storageManager.getRMSBeanMgr().update(bean);
        }
       
        // Commit the properties
        if(transaction != null) {
          transaction.commit();
          transaction = null;
        }
      }
    }
    catch (Exception e1)
    {
      if (log.isDebugEnabled())
        log.debug(e1);
    } finally {
      if (transaction != null) {
        transaction.rollback();
        transaction = null;
      }
    }
  }
View Full Code Here

          String message = "Can't continue the Sender. Context is null";
          log.debug(message);
          throw new SandeshaException(message);
        }

        Transaction pickMessagesToSendTransaction = storageManager.getTransaction();

        SenderBeanMgr mgr = storageManager.getRetransmitterBeanMgr();
        SenderBean senderBean = mgr.getNextMsgToSend();
        if (senderBean==null) {
          pickMessagesToSendTransaction.commit();
          continue;
          }
       

        MessageRetransmissionAdjuster retransmitterAdjuster = new MessageRetransmissionAdjuster();
        boolean continueSending = retransmitterAdjuster.adjustRetransmittion(senderBean, context);
        if (!continueSending)
          continue;
       
        pickMessagesToSendTransaction.commit();
       
        String key = (String) senderBean.getMessageContextRefKey();
        MessageContext msgCtx = storageManager.retrieveMessageContext(key, context);

        if (msgCtx == null) {
          String message = "Message context is not present in the storage";
        }

        // sender will not send the message if following property is
        // set and not true.
        // But it will set if it is not set (null)

        // This is used to make sure that the mesage get passed the Sandesha2TransportSender.

        String qualifiedForSending = (String) msgCtx.getProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING);
        if (qualifiedForSending != null && !qualifiedForSending.equals(Sandesha2Constants.VALUE_TRUE)) {
          continue;
        }

        if (msgCtx == null) {
          log.debug("ERROR: Sender has an Unavailable Message entry");
          break;
        }

        RMMsgContext rmMsgCtx = MsgInitializer.initializeMessage(msgCtx);

        //operation is the lowest level Sandesha2 should be attached
        ArrayList msgsNotToSend = SandeshaUtil.getPropertyBean(msgCtx.getAxisOperation()).getMsgTypesToDrop();

        if (msgsNotToSend != null && msgsNotToSend.contains(new Integer(rmMsgCtx.getMessageType()))) {
          continue;
        }
       
        updateMessage(msgCtx);

        Transaction preSendTransaction = storageManager.getTransaction();

        int messageType = rmMsgCtx.getMessageType();
        if (messageType == Sandesha2Constants.MessageTypes.APPLICATION) {
          Sequence sequence = (Sequence) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
          String sequenceID = sequence.getIdentifier().getIdentifier();
 
        }
       
        //checking weather this message can carry piggybacked acks
        if (isAckPiggybackableMsgType(messageType) && !isAckAlreadyPiggybacked(rmMsgCtx)) {
          // piggybacking if an ack if available for the same sequence.
          //TODO do piggybacking based on wsa:To
          AcknowledgementManager.piggybackAcksIfPresent(rmMsgCtx);
        }
       
        preSendTransaction.commit();
       
        //sending the message
        TransportOutDescription transportOutDescription = msgCtx.getTransportOut();
        TransportSender transportSender = transportOutDescription.getSender();
         
        boolean successfullySent = false;
        if (transportSender != null) {
          try {
           
            //TODO change this to cater for security.
            transportSender.invoke(msgCtx);
            successfullySent = true;
          } catch (AxisFault e) {
            // TODO Auto-generated catch block
              log.debug("Could not send message");
            log.debug(e.getStackTrace().toString());
          }
        }

        Transaction postSendTransaction = storageManager.getTransaction();

        // update or delete only if the object is still present.
        SenderBean bean1 = mgr.retrieve(senderBean.getMessageID());
        if (bean1 != null) {
          if (senderBean.isReSend()) {
            bean1.setSentCount(senderBean.getSentCount());
            bean1.setTimeToSend(senderBean.getTimeToSend());
            mgr.update(bean1);
          } else
            mgr.delete(bean1.getMessageID());
        }

        postSendTransaction.commit(); // commiting the current transaction

        if (successfullySent) {
          if (!msgCtx.isServerSide())
            checkForSyncResponses(msgCtx);
        }

        Transaction terminateCleaningTransaction = storageManager.getTransaction();
        if (rmMsgCtx.getMessageType() == Sandesha2Constants.MessageTypes.TERMINATE_SEQ) {
          // terminate sending side.
          TerminateSequence terminateSequence = (TerminateSequence) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ);
          String sequenceID = terminateSequence.getIdentifier().getIdentifier();
          ConfigurationContext configContext = msgCtx.getConfigurationContext();
         
          String internalSequenceID = SandeshaUtil.getSequenceProperty(sequenceID,Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID,configContext);
          TerminateManager.terminateSendingSide(configContext,internalSequenceID, msgCtx.isServerSide());
        }

        terminateCleaningTransaction.commit();
       
      } catch (AxisFault e) {
        String message = "An Exception was throws in sending";
        log.debug(message,e);
       
View Full Code Here

            .getStorageMapBeanMgr();

        SequencePropertyBeanMgr sequencePropMgr = storageManager
            .getSequencePropretyBeanMgr();

        Transaction preInvocationTransaction = storageManager.getTransaction();
       
        //Getting the incomingSequenceIdList
        SequencePropertyBean allSequencesBean = (SequencePropertyBean) sequencePropMgr
            .retrieve(
                Sandesha2Constants.SequenceProperties.ALL_SEQUENCES,
                Sandesha2Constants.SequenceProperties.INCOMING_SEQUENCE_LIST);
        if (allSequencesBean == null)
          continue;

        ArrayList allSequencesList = SandeshaUtil.getArrayListFromString (allSequencesBean
            .getValue());
       
        preInvocationTransaction.commit();
       
        Iterator allSequencesItr = allSequencesList.iterator();

        currentIteration: while (allSequencesItr.hasNext()) {

          String sequenceId = (String) allSequencesItr.next();
         
          Transaction invocationTransaction = storageManager.getTransaction();   //Transaction based invocation
         
          NextMsgBean nextMsgBean = nextMsgMgr.retrieve(sequenceId);
          if (nextMsgBean == null) {

            String message = "Next message not set correctly. Removing invalid entry.";
            log.debug(message);
            allSequencesItr.remove();
           
            //cleaning the invalid data of the all sequences.
            allSequencesBean.setValue(allSequencesList.toString());
            sequencePropMgr.update(allSequencesBean)
           
            throw new SandeshaException (message);
          }

          long nextMsgno = nextMsgBean.getNextMsgNoToProcess();
          if (nextMsgno <= 0) {
            String message = "Invalid messaage number as the Next Message Number. Removing invalid entry";
           
            throw new SandeshaException(message);
          }

          Iterator stMapIt = storageMapMgr.find(
              new InvokerBean(null, nextMsgno, sequenceId))
              .iterator();
         
          boolean invoked = false;
         
          while (stMapIt.hasNext()) {

            InvokerBean stMapBean = (InvokerBean) stMapIt
                .next();
            String key = stMapBean.getMessageContextRefKey();


            MessageContext msgToInvoke = storageManager.retrieveMessageContext(key,context);

            RMMsgContext rmMsg = MsgInitializer
                .initializeMessage(msgToInvoke);
            Sequence seq = (Sequence) rmMsg
                .getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);

            long msgNo = seq.getMessageNumber().getMessageNumber();

            try {
              //Invoking the message.

              //currently Transaction based invocation can be supplied only for the in-only case.
             
              if (!AxisOperationFactory.MEP_URI_IN_ONLY.equals(msgToInvoke.getAxisOperation().getMessageExchangePattern())) {
                invocationTransaction.commit();
              }
             
              new AxisEngine (msgToInvoke.getConfigurationContext())
                  .resume(msgToInvoke);
              invoked = true;
             
              if (!AxisOperationFactory.MEP_URI_IN_ONLY.equals(msgToInvoke.getAxisOperation().getMessageExchangePattern())) {
                invocationTransaction = storageManager.getTransaction();
              }           

              storageMapMgr.delete(key);
            } catch (AxisFault e) {
              throw new SandeshaException(e);
            }

            //undating the next msg to invoke


            if (rmMsg.getMessageType() == Sandesha2Constants.MessageTypes.APPLICATION) {
              Sequence sequence = (Sequence) rmMsg
                  .getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
              if (sequence.getLastMessage() != null) {
               
                TerminateManager.cleanReceivingSideAfterInvocation(context, sequenceId);
               
                //this sequence has no more invocations
//                stopInvokerForTheSequence(sequenceId);
               
                //exit from current iteration. (since an entry was removed)
                invocationTransaction.commit();
                break currentIteration;
              }
            }
          }

          if (invoked) {
            nextMsgno++;
            nextMsgBean.setNextMsgNoToProcess(nextMsgno);
            nextMsgMgr.update(nextMsgBean);
            invocationTransaction.commit();
          }
        }
       
      } catch (SandeshaException e1) {
        e1.printStackTrace();
View Full Code Here

   
    ConfigurationContext context = terminateSeqMsg.getConfigurationContext();
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(context);
    SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropretyBeanMgr();

    Transaction terminateReceivedTransaction = storageManager.getTransaction();
    SequencePropertyBean terminateReceivedBean = new SequencePropertyBean ();
    terminateReceivedBean.setSequenceID(sequenceId);
    terminateReceivedBean.setName(Sandesha2Constants.SequenceProperties.TERMINATE_RECEIVED);
    terminateReceivedBean.setValue("true");
   
    sequencePropertyBeanMgr.insert(terminateReceivedBean);
   
    //add the terminate sequence response if required.
    if (SpecSpecificConstants.isTerminateSequenceResponseRequired (terminateSeqRMMsg.getRMSpecVersion()))
      addTerminateSequenceResponse (terminateSeqRMMsg,sequenceId);
   
    setUpHighestMsgNumbers(context,storageManager,sequenceId,terminateSeqRMMsg);
   
    terminateReceivedTransaction.commit();
   
    Transaction terminateTransaction = storageManager.getTransaction();
    TerminateManager.cleanReceivingSideOnTerminateMessage(context,sequenceId);
   
   
    SequencePropertyBean terminatedBean = new SequencePropertyBean (
             sequenceId,Sandesha2Constants.SequenceProperties.SEQUENCE_TERMINATED,Sandesha2Constants.VALUE_TRUE);
   
    sequencePropertyBeanMgr.insert(terminatedBean);
   
   
    terminateTransaction.commit();
   
    //removing an entry from the listener
    String transport = terminateSeqMsg.getTransportIn().getName().getLocalPart();
 
    Transaction lastUpdatedTransaction = storageManager.getTransaction();
    SequenceManager.updateLastActivatedTime(sequenceId,context);
   
    lastUpdatedTransaction.commit();   
    terminateSeqRMMsg.pause();
  }
View Full Code Here

       
        String outSequenceID = SandeshaUtil.getSequenceProperty(internalSeqenceID,Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID,configurationContext);
        if (outSequenceID==null)
          throw new SandeshaException ("SequenceID was not found. Cannot send the terminate message");
       
    Transaction addTerminateSeqTransaction = storageManager.getTransaction();
   
    String terminated = SandeshaUtil.getSequenceProperty(outSequenceID,
        Sandesha2Constants.SequenceProperties.TERMINATE_ADDED,configurationContext);
   
   
   
    //registring an InOutOperationContext for this.
    //since the serviceContext.fireAndForget only sets a inOnly One
    //this does not work when there is a terminateSequnceResponse
    //TODO do processing of terminateMessagesCorrectly., create a new message instead of sendign the one given by the serviceClient
    //TODO important
    try {
      AxisOperation oldOPeration = msgContext.getAxisOperation();
      AxisOperation outInAxisOp = new OutInAxisOperation (new QName ("temp"));
      //setting flows
      outInAxisOp.setRemainingPhasesInFlow(oldOPeration.getRemainingPhasesInFlow());
     
      OperationContext opcontext = OperationContextFactory.createOperationContext(OperationContextFactory.MEP_CONSTANT_OUT_IN,outInAxisOp);
        opcontext.setParent(msgContext.getServiceContext());
      configurationContext.registerOperationContext(rmMsgCtx.getMessageId(),opcontext);
    } catch (AxisFault e1) {
      throw new SandeshaException ("Could not register an outInAxisOperation");
    }
   
    if (terminated != null
        && "true".equals(terminated)) {
      String message = "Terminate was added previously.";
      log.info(message);
      return;
    }

    TerminateSequence terminateSequencePart = (TerminateSequence) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ);
    terminateSequencePart.getIdentifier().setIndentifer(outSequenceID);
   
    rmMsgCtx.setFlow(MessageContext.OUT_FLOW);
    msgContext.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE,"true");
   
    rmMsgCtx.setTo(new EndpointReference(toAddress));
   
    String rmVersion = SandeshaUtil.getRMVersion(internalSeqenceID,configurationContext);
    if (rmVersion==null)
      throw new SandeshaException ("Cant find the rmVersion of the given message");
   
    rmMsgCtx.setWSAAction(SpecSpecificConstants.getTerminateSequenceAction(rmVersion));
    rmMsgCtx.setSOAPAction(SpecSpecificConstants.getTerminateSequenceSOAPAction(rmVersion));

    String transportTo = SandeshaUtil.getSequenceProperty(internalSeqenceID,Sandesha2Constants.SequenceProperties.TRANSPORT_TO,configurationContext);
    if (transportTo!=null) {
      rmMsgCtx.setProperty(MessageContextConstants.TRANSPORT_URL,transportTo);
    }
   
    try {
      rmMsgCtx.addSOAPEnvelope();
    } catch (AxisFault e) {
      throw new SandeshaException(e.getMessage());
    }

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

   
    storageManager.storeMessageContext(key,msgContext);

   
    //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(msgContext.getMessageID());
   
    //this will be set to true at the sender.
    terminateBean.setSend(true);
   
    msgContext.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 = msgContext.getTransportOut();
    rmMsgCtx.setProperty(Sandesha2Constants.ORIGINAL_TRANSPORT_OUT_DESC,transportOut);
    rmMsgCtx.setProperty(Sandesha2Constants.MESSAGE_STORE_KEY,key);
    rmMsgCtx.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE,Sandesha2Constants.VALUE_TRUE);
    rmMsgCtx.getMessageContext().setTransportOut(new Sandesha2TransportOutDesc ());
    addTerminateSeqTransaction.commit();
   
      AxisEngine engine = new AxisEngine (configurationContext);
      try {
      engine.send(msgContext);
    } catch (AxisFault e) {
View Full Code Here

   
    ConfigurationContext context = createSeqMsg.getConfigurationContext();
   
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(context);
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
    Transaction createSequenceTransaction = storageManager.getTransaction();   //begining of a new transaction

    try {
      String newSequenceId = SequenceManager.setupNewSequence(createSeqRMMsg)//newly created sequnceID.
     
      RMMsgContext createSeqResponse = RMMsgCreator.createCreateSeqResponseMsg(
          createSeqRMMsg, outMessage,newSequenceId);    // converting the blank out message in to a create
                                                            // sequence response.
      createSeqResponse.setFlow(MessageContext.OUT_FLOW);
     
      createSeqResponse.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE,"true")//for making sure that this wont be processed again.
      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) {
          String message = "An accept part has not been generated for the create seq request with an offer part";
          log.debug(message);
          throw new SandeshaException(message);
        }

        String offeredSequenceID = offer.getIdentifer().getIdentifier(); //offered seq. id.
       
        boolean offerEcepted = offerAccepted (offeredSequenceID,context,createSeqRMMsg);
       
        if (offerEcepted)  {
          //Setting the CreateSequence table entry for the outgoing side.
          CreateSeqBean createSeqBean = new CreateSeqBean();
          createSeqBean.setSequenceID(offeredSequenceID);
          String outgoingSideInternalSequenceID = SandeshaUtil.getOutgoingSideInternalSequenceID(newSequenceId);
          createSeqBean.setInternalSequenceID(outgoingSideInternalSequenceID);
          createSeqBean.setCreateSeqMsgID(SandeshaUtil.getUUID()); //this is a dummy value.
       
          CreateSeqBeanMgr createSeqMgr = storageManager.getCreateSeqBeanMgr();
          createSeqMgr.insert(createSeqBean);
       
          //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.
       
          //setting the out_sequence_id
          SequencePropertyBean outSequenceBean = new SequencePropertyBean();
          outSequenceBean.setName(Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);
          outSequenceBean.setValue(offeredSequenceID);
          outSequenceBean.setSequenceID(outgoingSideInternalSequenceID);
          seqPropMgr.insert(outSequenceBean);

          //setting the internal_sequence_id
          SequencePropertyBean internalSequenceBean = new SequencePropertyBean();
          internalSequenceBean.setName(Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
          internalSequenceBean.setSequenceID(offeredSequenceID);
          internalSequenceBean.setValue(outgoingSideInternalSequenceID);
          seqPropMgr.insert(internalSequenceBean);
        } else {
          //removing the accept part.
          createSeqResPart.setAccept(null);
          createSeqResponse.addSOAPEnvelope();
        }
      }

      EndpointReference acksTo = createSeqPart.getAcksTo().getAddress().getEpr();
      if (acksTo == null || acksTo.getAddress() == null
          || acksTo.getAddress() == "") {
        String message = "Acks to not present in the create sequence message";
        log.debug(message);
        throw new AxisFault(message);
      }

      SequencePropertyBean acksToBean = new SequencePropertyBean(
          newSequenceId, Sandesha2Constants.SequenceProperties.ACKS_TO_EPR,acksTo.getAddress());

      seqPropMgr.insert(acksToBean);
     
      outMessage.setResponseWritten(true);

      //commiting tr. before sending the response msg.
      createSequenceTransaction.commit();
     
      Transaction updateLastActivatedTransaction = storageManager.getTransaction();
      SequenceManager.updateLastActivatedTime(newSequenceId,createSeqRMMsg.getMessageContext().getConfigurationContext());
      updateLastActivatedTransaction.commit();
     
      AxisEngine engine = new AxisEngine(context);
      engine.send(outMessage);
     
      SequencePropertyBean toBean = seqPropMgr.retrieve(newSequenceId,Sandesha2Constants.SequenceProperties.TO_EPR);
View Full Code Here

      return;
    }
   
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx);
   
    Transaction closeSequenceTransaction = storageManager.getTransaction();
   
    SequencePropertyBeanMgr sequencePropMgr = storageManager.getSequencePropretyBeanMgr();
    SequencePropertyBean sequenceClosedBean = new SequencePropertyBean ();
    sequenceClosedBean.setSequenceID(sequenceID);
    sequenceClosedBean.setName(Sandesha2Constants.SequenceProperties.SEQUENCE_CLOSED);
    sequenceClosedBean.setValue(Sandesha2Constants.VALUE_TRUE);
   
    sequencePropMgr.insert(sequenceClosedBean);
   
    RMMsgContext ackRMMsgCtx = AcknowledgementManager.generateAckMessage(rmMsgCtx,sequenceID);
   
    MessageContext ackMsgCtx = ackRMMsgCtx.getMessageContext();
   
    String rmNamespaceValue = rmMsgCtx.getRMNamespaceValue();
    ackRMMsgCtx.setRMNamespaceValue(rmNamespaceValue);
   

    SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
        .getSOAPVersion(rmMsgCtx.getSOAPEnvelope()));
   
    //Setting new envelope
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    try {
      ackMsgCtx.setEnvelope(envelope);
    } catch (AxisFault e3) {
      throw new SandeshaException(e3.getMessage());
    }
   
    //adding the ack part to the envelope.
    SequenceAcknowledgement sequenceAcknowledgement = (SequenceAcknowledgement) ackRMMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT);
 
    MessageContext closeSequenceMsg = rmMsgCtx.getMessageContext();
   
    MessageContext closeSequenceResponseMsg = null;
    closeSequenceResponseMsg = Utils.createOutMessageContext(closeSequenceMsg);
   
    RMMsgContext closeSeqResponseRMMsg = RMMsgCreator
        .createCloseSeqResponseMsg(rmMsgCtx, closeSequenceResponseMsg);
   
    closeSeqResponseRMMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT,sequenceAcknowledgement);
   
    closeSeqResponseRMMsg.setFlow(MessageContext.OUT_FLOW);
    closeSeqResponseRMMsg.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE,"true");

    closeSequenceResponseMsg.setResponseWritten(true);
   
    closeSeqResponseRMMsg.addSOAPEnvelope();
   
    AxisEngine engine = new AxisEngine (closeSequenceMsg.getConfigurationContext());
   
    try {
      engine.send(closeSequenceResponseMsg);
    } catch (AxisFault e) {
      String message = "Could not send the terminate sequence response";
      throw new SandeshaException (message,e);
    }
   
   
    closeSequenceTransaction.commit();
  }
View Full Code Here

    ConfigurationContext configurationContext = referenceMessage.getMessageContext().getConfigurationContext();
    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);
    terminateRMMessage.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE,Sandesha2Constants.VALUE_TRUE);
    terminateRMMessage.getMessageContext().setTransportOut(new Sandesha2TransportOutDesc ());
    addTerminateSeqTransaction.commit();
   
      AxisEngine engine = new AxisEngine (configurationContext);
      try {
      engine.send(terminateRMMessage.getMessageContext());
    } catch (AxisFault e) {
View Full Code Here

TOP

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

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.