Package org.apache.axis2.context

Examples of org.apache.axis2.context.MessageContext


      }
    }
   
    Parameter propertiesFromRefReqMsg = axisModule.getParameter(Sandesha2Constants.propertiesToCopyFromReferenceRequestMessage);
    OperationContext referenceOpCtx = fromMessage.getOperationContext();
    MessageContext referenceRequestMessage = null;
    if (referenceOpCtx!=null)
      referenceRequestMessage=referenceOpCtx.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
   
    if (propertiesFromRefReqMsg!=null && referenceRequestMessage!=null) {
      String value = (String) propertiesFromRefReqMsg.getValue();
      if (value!=null) {
        value = value.trim();
        String[] propertyNames = value.split(",");
        for (int i=0;i<propertyNames.length;i++) {
          String propertyName = propertyNames[i];
          Object val = referenceRequestMessage.getProperty(propertyName);
          if (val!=null) {
            toMessage.setProperty(propertyName,val);
          }
        }
      }
View Full Code Here


  }
  public static void executeAndStore (RMMsgContext rmMsgContext, String storageKey) throws AxisFault {
    if (log.isDebugEnabled())
      log.debug("Enter: SandeshaUtil::executeAndStore, " + storageKey);
   
    MessageContext msgContext = rmMsgContext.getMessageContext();
    ConfigurationContext configurationContext = msgContext.getConfigurationContext();

    SandeshaPolicyBean policy = getPropertyBean(msgContext.getAxisOperation());
    if(policy.isUseMessageSerialization()) {
      msgContext.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_TRUE);

      StorageManager store = getSandeshaStorageManager(configurationContext, configurationContext.getAxisConfiguration());
      store.storeMessageContext(storageKey, msgContext);
     
    } else {
      // message will be stored in the Sandesha2TransportSender
      msgContext.setProperty(Sandesha2Constants.MESSAGE_STORE_KEY, storageKey);
 
      TransportOutDescription transportOut = msgContext.getTransportOut();
 
      msgContext.setProperty(Sandesha2Constants.ORIGINAL_TRANSPORT_OUT_DESC, transportOut);
      msgContext.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE, Sandesha2Constants.VALUE_TRUE);
 
      Sandesha2TransportOutDesc sandesha2TransportOutDesc = new Sandesha2TransportOutDesc();
      msgContext.setTransportOut(sandesha2TransportOutDesc);
 
       // sending the message once through Sandesha2TransportSender.
       AxisEngine engine = new AxisEngine(configurationContext);
 
      if (msgContext.isPaused())
        engine.resumeSend(msgContext);
      else {
        //this invocation has to be a blocking one.
       
        Boolean isTransportNonBlocking = (Boolean) msgContext.getProperty(MessageContext.TRANSPORT_NON_BLOCKING);
        if (isTransportNonBlocking!=null && isTransportNonBlocking.booleanValue())
          msgContext.setProperty(MessageContext.TRANSPORT_NON_BLOCKING, Boolean.FALSE);
       
        engine.send(msgContext);
       
        msgContext.setProperty(MessageContext.TRANSPORT_NON_BLOCKING, isTransportNonBlocking);
      }
    }
    if (log.isDebugEnabled())
      log.debug("Exit: SandeshaUtil::executeAndStore");
  }
View Full Code Here

   
    return phases;
  }
 
  public static MessageContext cloneMessageContext (MessageContext oldMsg) throws AxisFault {
    MessageContext newMsg = new MessageContext ();
    newMsg.setOptions(new Options (oldMsg.getOptions()));
   
   
    //TODO hd to use following hack since a 'clone' method was not available for SOAPEnvelopes.
    //Do it the correct way when that becomes available.
    OMElement newElement = oldMsg.getEnvelope().cloneOMElement();
    String elementString = newElement.toString();
   
    try {
      ByteArrayInputStream stream = new ByteArrayInputStream(
          elementString.getBytes("UTF8"));
      StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(
          XMLInputFactory.newInstance().createXMLStreamReader(stream),
          null);
      SOAPEnvelope envelope = builder.getSOAPEnvelope();

      newMsg.setEnvelope(envelope);
    } catch (XMLStreamException e) {
      throw AxisFault.makeFault(e);
    } catch (UnsupportedEncodingException e) {
      throw AxisFault.makeFault(e);
    }
   
    newMsg.setConfigurationContext(oldMsg.getConfigurationContext());
    newMsg.setAxisService(oldMsg.getAxisService());
    newMsg.setTransportOut(oldMsg.getTransportOut());
    newMsg.setTransportIn(oldMsg.getTransportIn());
   
    return newMsg;
   
  }
View Full Code Here

 
  public void run() {
    if(log.isDebugEnabled()) log.debug("Enter: InvokerWorker::run");
   
    Transaction transaction = null;
    MessageContext msgToInvoke = null;
   
    try {
     
      StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());
      InvokerBeanMgr invokerBeanMgr = storageManager.getInvokerBeanMgr();
     
      //starting a transaction
      transaction = storageManager.getTransaction();
     
      InvokerBean invokerBean = invokerBeanMgr.retrieve(messageContextKey);
     
      msgToInvoke = storageManager.retrieveMessageContext(messageContextKey, configurationContext);
      RMMsgContext rmMsg = MsgInitializer.initializeMessage(msgToInvoke);

      // ending the transaction before invocation.
      if(transaction != null) {
        transaction.commit();
        transaction = null;
      }
         
      //starting a transaction for the invocation work.
      transaction = storageManager.getTransaction();
      // Lock the RMD Bean just to avoid deadlocks
      SandeshaUtil.getRMDBeanFromSequenceId(storageManager, invokerBean.getSequenceID());
      // Depending on the transaction  support, the service will be invoked only once.
      // Therefore we delete the invoker bean and message now, ahead of time
      invokerBeanMgr.delete(messageContextKey);
      // removing the corresponding message context as well.
      storageManager.removeMessageContext(messageContextKey);

      try {

        boolean postFailureInvocation = false;

        // StorageManagers should st following property to
        // true, to indicate that the message received comes
        // after a failure.
        String postFaulureProperty = (String) msgToInvoke
            .getProperty(Sandesha2Constants.POST_FAILURE_MESSAGE);
        if (postFaulureProperty != null
            && Sandesha2Constants.VALUE_TRUE.equals(postFaulureProperty))
          postFailureInvocation = true;

        AxisEngine engine = new AxisEngine(msgToInvoke.getConfigurationContext());
        if (postFailureInvocation) {
          makeMessageReadyForReinjection(msgToInvoke);
          if (log.isDebugEnabled())
            log.debug("Receiving message, key=" + messageContextKey + ", msgCtx="
                + msgToInvoke.getEnvelope().getHeader());
          engine.receive(msgToInvoke);
        } else {
          if (log.isDebugEnabled())
            log.debug("Resuming message, key=" + messageContextKey + ", msgCtx="
                + msgToInvoke.getEnvelope().getHeader());
          msgToInvoke.setPaused(false);
          engine.resumeReceive(msgToInvoke);
        }
       
        if(transaction!=null){
          transaction.commit();
View Full Code Here

    messageContext.getOptions().setAction(null);
    messageContext.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, Sandesha2Constants.VALUE_TRUE);
  }

  private void handleFault(RMMsgContext inRMMsgContext, Exception e) {
    MessageContext inMsgContext = inRMMsgContext.getMessageContext();
    AxisEngine engine = new AxisEngine(inMsgContext.getConfigurationContext());
    try {         
      MessageContext faultContext = MessageContextBuilder.createFaultMessageContext(inMsgContext, e);
      // Copy some of the parameters to the new message context.
      faultContext.setProperty(Constants.Configuration.CONTENT_TYPE, inMsgContext
          .getProperty(Constants.Configuration.CONTENT_TYPE));

      EndpointReference faultEPR = inRMMsgContext.getFaultTo();
      if (faultEPR==null)
        faultEPR = inRMMsgContext.getReplyTo();
View Full Code Here

 
  public boolean processOutMessage(RMMsgContext rmMsgCtx) throws AxisFault {
    if (log.isDebugEnabled())
      log.debug("Enter: ApplicationMsgProcessor::processOutMessage");

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

    //validating the outgoing message
    MessageValidator.validateOutgoingMessage(rmMsgCtx);
   
    // setting the Fault callback
    SandeshaListener faultCallback = (SandeshaListener) msgContext.getOptions().getProperty(
        SandeshaClientConstants.SANDESHA_LISTENER);
    if (faultCallback != null) {
      OperationContext operationContext = msgContext.getOperationContext();
      if (operationContext != null) {
        operationContext.setProperty(SandeshaClientConstants.SANDESHA_LISTENER, faultCallback);
      }
    }

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

    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) {
      if (inboundSequence == null || "".equals(inboundSequence)) {
        String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.incomingSequenceNotValidID, inboundSequence);
        log.debug(message);
        throw new SandeshaException(message);
      }

      internalSequenceId = SandeshaUtil.getOutgoingSideInternalSequenceID(inboundSequence);
    } 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 = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
        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;
    }
   
    if (internalSequenceId!=null)
      rmMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID,internalSequenceId);

    /*
     * 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(SandeshaMessageHelper.getMessage(
            SandeshaMessageKeys.msgNumberMustBeLargerThanZero, Long.toString(givenMessageNumber)));
      }
    }

    // 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;

    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.getAxisSpecifMEPConstant();
      }
      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) {
          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.getAxisSpecifMEPConstant();
      }

      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
    storageManager.getRMSBeanMgr().update(rmsBean);
   
    if(startPolling) {
      SandeshaUtil.startWorkersForSequence(msgContext.getConfigurationContext(), rmsBean);
    }
   
    SOAPEnvelope env = rmMsgCtx.getSOAPEnvelope();
    if (env == null) {
      SOAPEnvelope envelope = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil.getSOAPVersion(env))
          .getDefaultEnvelope();
      rmMsgCtx.setSOAPEnvelop(envelope);
    }

    SOAPBody soapBody = rmMsgCtx.getSOAPEnvelope().getBody();
    if (soapBody == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.soapBodyNotPresent);
      log.debug(message);
      throw new SandeshaException(message);
    }

    String messageId1 = SandeshaUtil.getUUID();
    if (rmMsgCtx.getMessageId() == null) {
      rmMsgCtx.setMessageId(messageId1);
    }

    EndpointReference toEPR = msgContext.getTo();

   
    if (toEPR != null) {
      // setting default actions.
      String to = toEPR.getAddress();
      String operationName = msgContext.getOperationContext().getAxisOperation().getName().getLocalPart();
      if (msgContext.getWSAAction() == null) {
        msgContext.setWSAAction(to + "/" + operationName);
      }
      if (msgContext.getSoapAction() == null) {
        msgContext.setSoapAction("\"" + to + "/" + operationName + "\"");
      }
    }
   
    // processing the response if not an dummy.
    if (!dummyMessage)
      processResponseMessage(rmMsgCtx, rmsBean, internalSequenceId, outSequenceID, messageNumber, storageKey, storageManager);
   
    //Users wont be able to get reliable response msgs in the back channel in the back channel of a
    //reliable message. If he doesn't have a endpoint he should use polling mechanisms.
    msgContext.pause();
   
    if (log.isDebugEnabled())
      log.debug("Exit: ApplicationMsgProcessor::processOutMessage " + Boolean.TRUE);
    return true;
  }
View Full Code Here

      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
          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");
        return;
      }

      if (msgCtx == null) {
        if (log.isDebugEnabled())
          log.debug(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.sendHasUnavailableMsgEntry));
        return;     
      }

      // 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()))) {
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, message type to be dropped " + rmMsgCtx.getMessageType());
        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()) &&
View Full Code Here

    try {

      // create the responseMessageContext

      MessageContext responseMessageContext = msgCtx.getOperationContext().getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
      SOAPEnvelope resenvelope = null;
      if (responseMessageContext!=null)
        resenvelope = responseMessageContext.getEnvelope();
     
      boolean transportInPresent = (msgCtx.getProperty(MessageContext.TRANSPORT_IN) != null);
      if (!transportInPresent && (responseMessageContext==null || responseMessageContext.getEnvelope()==null)) {
        if(log.isDebugEnabled()) log.debug("Exit: SenderWorker::checkForSyncResponses, no response present");
        return;
      }
     
      //to find out weather the response was built by me.
      boolean syncResponseBuilt = false;
     
      if (responseMessageContext==null || responseMessageContext.getEnvelope()==null) {
        if (responseMessageContext==null)
          responseMessageContext = new MessageContext();

        OperationContext requestMsgOpCtx = msgCtx.getOperationContext();
        responseMessageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, requestMsgOpCtx
                .getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
        responseMessageContext.setProperty(Constants.Configuration.CONTENT_TYPE, requestMsgOpCtx
                .getProperty(Constants.Configuration.CONTENT_TYPE));
        responseMessageContext.setProperty(HTTPConstants.MTOM_RECEIVED_CONTENT_TYPE, requestMsgOpCtx
                .getProperty(HTTPConstants.MTOM_RECEIVED_CONTENT_TYPE));

        //If the response MsgCtx was not available Axis2 would hv put the transport info into a
        //HashMap, getting the data from it.
        HashMap transportInfoMap = (HashMap) msgCtx.getProperty(Constants.Configuration.TRANSPORT_INFO_MAP);
        if (transportInfoMap != null) {
          responseMessageContext.setProperty(Constants.Configuration.CONTENT_TYPE,
                  transportInfoMap.get(Constants.Configuration.CONTENT_TYPE));
          responseMessageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
                  transportInfoMap.get(Constants.Configuration.CHARACTER_SET_ENCODING));
        }
     
        responseMessageContext.setConfigurationContext(msgCtx.getConfigurationContext());
        responseMessageContext.setTransportIn(msgCtx.getTransportIn());
        responseMessageContext.setTransportOut(msgCtx.getTransportOut());

        responseMessageContext.setProperty(MessageContext.TRANSPORT_IN, msgCtx
            .getProperty(MessageContext.TRANSPORT_IN));
        responseMessageContext.setServiceContext(msgCtx.getServiceContext());
        responseMessageContext.setServiceGroupContext(msgCtx.getServiceGroupContext());

        responseMessageContext.setProperty(Sandesha2Constants.MessageContextProperties.MAKECONNECTION_ENTRY,
        msgCtx.getProperty(Sandesha2Constants.MessageContextProperties.MAKECONNECTION_ENTRY));

        // If request is REST we assume the responseMessageContext is REST,
        // so set the variable

        responseMessageContext.setDoingREST(msgCtx.isDoingREST());

        resenvelope = responseMessageContext.getEnvelope();
        try {
          // MessageContext is modified in TransportUtils.createSOAPMessage(). It might be used by axis.engine or handler.
          // To catch the modification and pass it to engine or handler, resenvelope is created by responseMessageContext.
       
          if (resenvelope==null) {
            //We try to build the response out of the transport stream.
            resenvelope = TransportUtils.createSOAPMessage(responseMessageContext);
            responseMessageContext.setEnvelope(resenvelope);
            syncResponseBuilt = true;
          } else {
           
          }
        } catch (AxisFault e) {
          //Cannot find a valid SOAP envelope.
          if (log.isErrorEnabled() ) {
            log.error (SandeshaMessageHelper
                .getMessage(SandeshaMessageKeys.soapEnvNotSet));
          log.error ("Caught exception", e);
          }
       
          return;
        }
       
        //If addressing is disabled we will be adding this message simply as the application response of the request message.
        Boolean addressingDisabled = (Boolean) msgCtx.getOptions().getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
        if (addressingDisabled!=null && Boolean.TRUE.equals(addressingDisabled)) {
          // If the AxisOperation object doesn't have a message receiver, it means that this was
          // an out only op where we have added an ACK to the response.  Set the requestMsgOpCtx to
          // be the RMIn
          OperationContext responseMsgOpCtx = requestMsgOpCtx;
          if (requestMsgOpCtx.getAxisOperation().getMessageReceiver() == null) {
            // Generate a new RM In Only operation

            ServiceContext serviceCtx = responseMessageContext.getServiceContext();
            AxisOperation op = msgCtx.getAxisService().getOperation(Sandesha2Constants.RM_IN_ONLY_OPERATION);
            responseMsgOpCtx = ContextFactory.createOperationContext (op, serviceCtx);         

          }
         
          responseMessageContext.setOperationContext(responseMsgOpCtx);
        }
       
        AxisOperation operation = msgCtx.getAxisOperation();
        if (operation!=null && responseMessageContext.getAxisMessage()==null
            && (operation instanceof OutInAxisOperation))
          responseMessageContext.setAxisMessage(operation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));

        RMMsgContext responseRMMessage = MsgInitializer.initializeMessage(responseMessageContext);
        if (responseRMMessage.getMessageType()==Sandesha2Constants.MessageTypes.ACK) {
          responseMessageContext.setAxisOperation(SpecSpecificConstants.getWSRMOperation
              (Sandesha2Constants.MessageTypes.ACK, responseRMMessage.getRMSpecVersion(), responseMessageContext.getAxisService()));
          responseMessageContext.setOperationContext(null);
        }
       
      }
     
      //if the syncResponseWas not built here and the client was not expecting a sync response. We will not try to execute
      //here. Doing so will cause a double invocation for a async message.
      if (msgCtx.getOptions().isUseSeparateListener()==true &&  !syncResponseBuilt) {
        return;
      }
     
     
      //setting the message as serverSide will let it go through the MessageReceiver (may be callback MR).
      responseMessageContext.setServerSide(true);
   
      if (responseMessageContext.getSoapAction()==null) {
        //if there is no SOAP action in the response message, Axis2 will wrongly identify it as a REST message
        //This happens because we set serverSide to True in a previous step.
        //So we have to add a empty SOAPAction here.
        responseMessageContext.setSoapAction("");
      }

      AxisEngine engine = new AxisEngine(msgCtx.getConfigurationContext());
      if (resenvelope!=null) {
        //we proceed only if we hv found a valid envelope.
View Full Code Here

      StorageManager storageManager) throws AxisFault {

    if (log.isDebugEnabled())
      log.debug("Enter: ApplicationMsgProcessor::addCreateSequenceMessage, " + rmsBean);

    MessageContext applicationMsg = applicationRMMsg.getMessageContext();
    ConfigurationContext configCtx = applicationMsg.getConfigurationContext();

    // generating a new create sequeuce message.
    RMMsgContext createSeqRMMessage = RMMsgCreator.createCreateSeqMsg(rmsBean, applicationRMMsg);

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

    SenderBeanMgr retransmitterMgr = storageManager.getSenderBeanMgr();

    SequenceOffer offer = createSequencePart.getSequenceOffer();
    if (offer != null) {
      String offeredSequenceId = offer.getIdentifer().getIdentifier();

      rmsBean.setOfferedSequence(offeredSequenceId);
    }

    MessageContext createSeqMsg = createSeqRMMessage.getMessageContext();
    createSeqMsg.setRelationships(null); // create seq msg does not
                        // relateTo anything
   
    String createSequenceMessageStoreKey = SandeshaUtil.getUUID(); // the key that will be used to store
                                     //the create sequence message.
   
    rmsBean.setCreateSeqMsgID(createSeqMsg.getMessageID());
    rmsBean.setCreateSequenceMsgStoreKey(createSequenceMessageStoreKey);
   
    //cloning the message and storing it as a reference.
    MessageContext clonedMessage = SandeshaUtil.cloneMessageContext(createSeqMsg);
    String clonedMsgStoreKey = SandeshaUtil.getUUID();
    storageManager.storeMessageContext(clonedMsgStoreKey, clonedMessage);
    rmsBean.setReferenceMessageStoreKey(clonedMsgStoreKey);
   
    SecurityToken token = (SecurityToken) createSeqRMMessage.getProperty(Sandesha2Constants.MessageContextProperties.SECURITY_TOKEN);
View Full Code Here

   
  }
 
  public static void validateOutgoingMessage (RMMsgContext rmMsgContext) throws SandeshaException {
   
    MessageContext msgContext = rmMsgContext.getMessageContext();
    if (!msgContext.isServerSide()) {
      //validating messages from the client.
     
      //if sync InOut and NoOffer and RM 1.0 an exception should be thrown
      String rmNamespace = rmMsgContext.getRMNamespaceValue();
      String mep = msgContext.getAxisOperation().getMessageExchangePattern();
      String offer = (String) msgContext.getProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID);
     
      EndpointReference replyTo = rmMsgContext.getMessageContext().getOptions().getReplyTo();
      boolean anonReplyTo = false;
      if (replyTo==null || replyTo.hasAnonymousAddress())
        anonReplyTo = true;
View Full Code Here

TOP

Related Classes of org.apache.axis2.context.MessageContext

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.