Class MessageHelper


  • public class MessageHelper
    extends Object
    • Constructor Detail

      • MessageHelper

        public MessageHelper()
    • Method Detail

      • cloneMessageContext

        public static MessageContext cloneMessageContext​(MessageContext synCtx,
                                                         boolean cloneSoapEnvelope)
                                                  throws org.apache.axis2.AxisFault
        Throws:
        org.apache.axis2.AxisFault
      • cloneMessageContext

        public static MessageContext cloneMessageContext​(MessageContext synCtx,
                                                         boolean cloneSoapEnvelope,
                                                         boolean isCloneJson)
                                                  throws org.apache.axis2.AxisFault
        This method is similar to cloneMessageContext(MessageContext, boolean, boolean, boolean, boolean) In order to refactor the code, new method signature was created and this method calls the new method
        Parameters:
        synCtx - Synapse MessageContext which has to be cloned
        cloneSoapEnvelope - The flag to say whether to clone the SOAP envelope or not.
        isCloneJson - The flag to say whether to clone the JSON payload or not.
        Returns:
        cloned Synapse MessageContext.
        Throws:
        org.apache.axis2.AxisFault - if there is a failure in creating the new Synapse MC or in a failure in cloning the underlying axis2 MessageContext.
      • cloneMessageContext

        public static MessageContext cloneMessageContext​(MessageContext synCtx,
                                                         boolean cloneSoapEnvelope,
                                                         boolean isCloneJson,
                                                         boolean isAggregate)
                                                  throws org.apache.axis2.AxisFault
        This method is similar to cloneMessageContext(MessageContext, boolean, boolean, boolean, boolean) other than always generating seperate correlation ids for the cloned message contexts
        Parameters:
        synCtx - Synapse MessageContext which has to be cloned
        cloneSoapEnvelope - The flag to say whether to clone the SOAP envelope or not.
        isCloneJson - The flag to say whether to clone the JSON payload or not.
        isAggregate - whether this method is called inside aggregate mediator
        Returns:
        cloned Synapse MessageContext.
        Throws:
        org.apache.axis2.AxisFault - if there is a failure in creating the new Synapse MC or in a failure in cloning the underlying axis2 MessageContext.
      • cloneMessageContext

        public static MessageContext cloneMessageContext​(MessageContext synCtx,
                                                         boolean cloneSoapEnvelope,
                                                         boolean isCloneJson,
                                                         boolean isAggregate,
                                                         boolean isCloneCorrelationId)
                                                  throws org.apache.axis2.AxisFault
        This method will simulate cloning the message context and creating an exact copy of the passed message. One should use this method with care; that is because, inside the new MC, most of the attributes of the MC like opCtx and so on are still kept as references inside the axis2 MessageContext for performance improvements. (Note: U dont have to worrie about the SOAPEnvelope, it is a cloned copy and not a reference from any other MC)
        Parameters:
        synCtx - - this will be cloned.
        cloneSoapEnvelope - whether to clone the soap envelope.
        isCloneJson - whether to clone the JSON payload.
        isAggregate - whether this method is called inside aggregate mediator
        isCloneCorrelationId - whether to generate correlation id for the cloned message
        Returns:
        cloned Synapse MessageContext.
        Throws:
        org.apache.axis2.AxisFault - if there is a failure in creating the new Synapse MC or in a failure in clonning the underlying axis2 MessageContext.
        See Also:
        cloneAxis2MessageContext(org.apache.axis2.context.MessageContext, boolean)
      • cloneMessageContext

        public static MessageContext cloneMessageContext​(MessageContext synCtx)
                                                  throws org.apache.axis2.AxisFault
        This method does exactly what cloneMessageContext(MessageContext) does, other than cloning the SOAP envelop based on the cloneSOAPEnvelope argument.
        Parameters:
        synCtx - Synapse message context to be cloned.
        Returns:
        The cloned Synapse Message Context.
        Throws:
        org.apache.axis2.AxisFault - If something goes wrong with message cloning.
      • cloneMessageContextForAggregateMediator

        @Deprecated
        public static MessageContext cloneMessageContextForAggregateMediator​(MessageContext synCtx)
                                                                      throws org.apache.axis2.AxisFault
        Deprecated.
        In an effort to refactor the code, this method is deprecated. Use cloneMessageContext(MessageContext, boolean, boolean, boolean, boolean) with the isAggregate flag set to true
        Parameters:
        synCtx - Synapse message context to be cloned.
        Returns:
        The cloned Synapse Message Context.
        Throws:
        org.apache.axis2.AxisFault - If something goes wrong with message cloning.
      • getClonedTemplateStack

        public static Stack<TemplateContext> getClonedTemplateStack​(Stack<TemplateContext> oriTemplateStack)
        Get a clone of a Template Function stack
        Parameters:
        oriTemplateStack - original template function stack to be cloned
        Returns:
        clone of a Template Function stack
      • cloneAxis2MessageContext

        public static org.apache.axis2.context.MessageContext cloneAxis2MessageContext​(org.apache.axis2.context.MessageContext mc,
                                                                                       boolean cloneSoapEnvelope)
                                                                                throws org.apache.axis2.AxisFault
        Throws:
        org.apache.axis2.AxisFault
      • cloneAxis2MessageContext

        public static org.apache.axis2.context.MessageContext cloneAxis2MessageContext​(org.apache.axis2.context.MessageContext mc,
                                                                                       boolean cloneSoapEnvelope,
                                                                                       boolean isCloneJson)
                                                                                throws org.apache.axis2.AxisFault
        This method is similar to cloneMessageContext(MessageContext, boolean, boolean, boolean, boolean) In order to refactor the code, new method signature was created and this method calls the new method
        Parameters:
        mc - Axis2 message context
        cloneSoapEnvelope - The flag to say whether to clone the SOAP envelope or not.
        isCloneJson - The flag to say whether to clone the JSON payload or not.
        Returns:
        The cloned Axis2 message context.
        Throws:
        org.apache.axis2.AxisFault - If something goes wrong during cloning.
      • cloneAxis2MessageContext

        public static org.apache.axis2.context.MessageContext cloneAxis2MessageContext​(org.apache.axis2.context.MessageContext mc,
                                                                                       boolean cloneSoapEnvelope,
                                                                                       boolean isCloneJson,
                                                                                       boolean isAggregrate)
                                                                                throws org.apache.axis2.AxisFault
        This method will simulate cloning the message context and creating an exact copy of the passed message. One should use this method with care; that is because, inside the new MC, most of the attributes of the MC like opCtx and so on are still kept as references. Otherwise there will be perf issues. But ..... this may reveal in some conflicts in the cloned message if you try to do advanced mediations with the cloned message, in which case you should manually get a clone of the changing part of the MC and set that cloned part to your MC. Changing the MC after doing that will solve most of the issues. (Note: You don't have to worry about the SOAPEnvelope, it is a cloned copy and not a reference from any other MC)
        Parameters:
        mc - - this will be cloned for getting an exact copy
        cloneSoapEnvelope - The flag to say whether to clone the SOAP envelope or not.
        isCloneJson - The flag to say whether to clone the JSON payload or not.
        isAggregrate - The flag to say whether it is called inside aggregate mediator.
        Returns:
        cloned MessageContext from the given mc
        Throws:
        org.apache.axis2.AxisFault - if there is a failure in copying the certain attributes of the provided message context
      • cloneAxis2MessageContext

        public static org.apache.axis2.context.MessageContext cloneAxis2MessageContext​(org.apache.axis2.context.MessageContext mc)
                                                                                throws org.apache.axis2.AxisFault
        This method does exactly what cloneAxis2MessageContext(org.apache.axis2.context.MessageContext) does, other than cloning the SOAP envelop based on the cloneSOAPEnvelope argument.
        Parameters:
        mc - Axis2 message context
        Returns:
        The cloned Axis2 message context.
        Throws:
        org.apache.axis2.AxisFault - If something goes wrong during cloning.
      • getClonedTransportHeaders

        public static Map getClonedTransportHeaders​(org.apache.axis2.context.MessageContext msgCtx)
      • clonePartially

        public static org.apache.axis2.context.MessageContext clonePartially​(org.apache.axis2.context.MessageContext ori)
                                                                      throws org.apache.axis2.AxisFault
        Throws:
        org.apache.axis2.AxisFault
      • clonePartially

        public static org.apache.axis2.context.MessageContext clonePartially​(org.apache.axis2.context.MessageContext ori,
                                                                             boolean isAggregate)
                                                                      throws org.apache.axis2.AxisFault
        Throws:
        org.apache.axis2.AxisFault
      • clonePartiallyForAggregate

        @Deprecated
        public static org.apache.axis2.context.MessageContext clonePartiallyForAggregate​(org.apache.axis2.context.MessageContext ori)
                                                                                  throws org.apache.axis2.AxisFault
        Deprecated.
        In an effort to refactor the code, this method is deprecated. Use clonePartially(org.apache.axis2.context.MessageContext, boolean) with the isAggregate flag true
        Throws:
        org.apache.axis2.AxisFault
      • cloneSOAPEnvelope

        public static org.apache.axiom.soap.SOAPEnvelope cloneSOAPEnvelope​(org.apache.axiom.soap.SOAPEnvelope envelope)
        This method will clone the provided SOAPEnvelope and returns the cloned envelope as an exact copy of the provided envelope
        Parameters:
        envelope - - this will be cloned to get the new envelope
        Returns:
        cloned SOAPEnvelope from the provided one
      • cloneOptions

        public static org.apache.axis2.client.Options cloneOptions​(org.apache.axis2.client.Options options)
        Clones the given Options object. This is not a deep copy because this will be called for each and every message going out from synapse. The parent of the cloning options object is kept as a reference.
        Parameters:
        options - cloning object
        Returns:
        cloned Options object
      • removeAddressingHeaders

        public static org.apache.axiom.soap.SOAPEnvelope removeAddressingHeaders​(org.apache.axis2.context.MessageContext axisMsgCtx)
        Removes Submission and Final WS-Addressing headers and return the SOAPEnvelope from the given message context
        Parameters:
        axisMsgCtx - the Axis2 Message context
        Returns:
        the resulting SOAPEnvelope
      • getPolicy

        public static org.apache.neethi.Policy getPolicy​(MessageContext synCtx,
                                                         String propertyKey)
        Get the Policy object for the given name from the Synapse configuration at runtime
        Parameters:
        synCtx - the current synapse configuration to get to the synapse configuration
        propertyKey - the name of the property which holds the Policy required
        Returns:
        the Policy object with the given name, from the configuration
      • cloneSOAPFault

        public static org.apache.axiom.soap.SOAPFault cloneSOAPFault​(org.apache.axiom.soap.SOAPFault fault)
        Clones the SOAPFault, fault cloning is not the same as cloning the OMElement because if the Fault is accessed through the SOAPEnvelope.getBody().getFault() method it will lead to a class cast because the cloned element is just an OMElement but not a Fault.
        Parameters:
        fault - that needs to be cloned
        Returns:
        the cloned fault
      • removeProcessedHeaders

        public static void removeProcessedHeaders​(org.apache.axis2.context.MessageContext axisMsgCtx,
                                                  boolean preserveAddressing)
        Remove the headers that are marked as processed.
        Parameters:
        axisMsgCtx - the Axis2 Message context
        preserveAddressing - if true preserve the addressing headers
      • copyResponseMessageHeaders

        public static void copyResponseMessageHeaders​(org.apache.axis2.context.MessageContext resultAxisMsgCtx,
                                                      org.apache.axis2.context.MessageContext axisInMsgCtx)
        Copy the response message headers received from the back-end response to the axis2 message context.
        Parameters:
        resultAxisMsgCtx - axis2 message context of the response received from the backend
        axisInMsgCtx - axis2 message context of the response to be sent to the client
      • setWireLogHolderProperties

        public static void setWireLogHolderProperties​(MessageContext synCtx,
                                                      boolean isBreakPoint,
                                                      SynapseMediationFlowPoint mediationFlowPoint)
        This method is to set mediatorId property to axis2 message context. This Id will be copied to iosession from the DeliveryAgent.java class and it will be used at wire level to identify to which mediator the wirelogs belongs.
        Parameters:
        synCtx -
      • maskURLPassword

        public static String maskURLPassword​(String url)
        Mask the password of the connection url with ***
        Parameters:
        url - the actual url
        Returns:
        the masked url