Package org.apache.synapse.mediators.bsf

## Class CommonScriptMessageContext

- java.lang.Object
- - org.apache.synapse.mediators.bsf.CommonScriptMessageContext

- All Implemented Interfaces:
    `ScriptMessageContext`, `org.apache.synapse.MessageContext`

      public class CommonScriptMessageContext
      extends Object
      implements ScriptMessageContext

  CommonScriptMessageContext decorates the Synapse MessageContext adding methods to use the message payload XML in a way natural to the scripting languages.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `CommonScriptMessageContext​(org.apache.synapse.MessageContext mc, org.apache.bsf.xml.XMLHelper xmlHelper)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addHeader​(boolean mustUnderstand, Object content)` | Add a new SOAP header to the message.
    `org.apache.synapse.config.SynapseConfiguration` | `getConfiguration()`
    `Map<String,​Object>` | `getContextEntries()`
    `Stack<org.apache.synapse.ContinuationState>` | `getContinuationStateStack()`
    `org.apache.synapse.Mediator` | `getDefaultConfiguration​(String arg0)`
    `org.apache.synapse.endpoints.Endpoint` | `getEndpoint​(String key)`
    `Object` | `getEntry​(String key)`
    `org.apache.axiom.soap.SOAPEnvelope` | `getEnvelope()`
    `Object` | `getEnvelopeXML()` | Get the XML representation of the complete SOAP envelope.
    `org.apache.synapse.core.SynapseEnvironment` | `getEnvironment()`
    `org.apache.synapse.Mediator` | `getFaultSequence()`
    `Stack<org.apache.synapse.FaultHandler>` | `getFaultStack()`
    `org.apache.axis2.addressing.EndpointReference` | `getFaultTo()`
    `org.apache.axiom.om.OMElement` | `getFormat​(String s)`
    `org.apache.axis2.addressing.EndpointReference` | `getFrom()`
    `Object` | `getJsonText()` | Get the Message Payload as a text.
    `Object` | `getLocalEntry​(String key)`
    `org.apache.synapse.Mediator` | `getMainSequence()`
    `int` | `getMessageFlowTracingState()`
    `String` | `getMessageID()`
    `String` | `getMessageString()`
    `Object` | `getPayloadJSON()` | Get the JSON object representation of the JSON message body of the request.
    `String` | `getPayloadText()` | Get the Message Payload as a text.
    `Object` | `getPayloadXML()` | Get the XML representation of SOAP Body payload.
    `Object` | `getProperty​(String key)`
    `Set` | `getPropertyKeySet()`
    `org.apache.axis2.addressing.RelatesTo` | `getRelatesTo()`
    `org.apache.axis2.addressing.EndpointReference` | `getReplyTo()`
    `org.apache.synapse.Mediator` | `getSequence​(String key)`
    `org.apache.synapse.Mediator` | `getSequenceTemplate​(String key)`
    `org.apache.commons.logging.Log` | `getServiceLog()`
    `String` | `getSoapAction()`
    `org.apache.axis2.addressing.EndpointReference` | `getTo()`
    `int` | `getTracingState()`
    `String` | `getWSAAction()`
    `String` | `getWSAMessageID()`
    `boolean` | `isContinuationEnabled()`
    `boolean` | `isDoingGET()`
    `boolean` | `isDoingMTOM()`
    `boolean` | `isDoingPOX()`
    `boolean` | `isDoingSWA()`
    `boolean` | `isFaultResponse()`
    `boolean` | `isResponse()`
    `boolean` | `isSOAP11()`
    `Object` | `jsonObject​(org.apache.synapse.MessageContext messageContext)` | Returns the JavaScript Object saved in this message context.
    `void` | `pushContinuationState​(org.apache.synapse.ContinuationState continuationState)`
    `void` | `pushFaultHandler​(org.apache.synapse.FaultHandler fault)`
    `void` | `removeProperty​(String key, String scope)` | Remove property from the message.
    `void` | `setConfiguration​(org.apache.synapse.config.SynapseConfiguration cfg)`
    `void` | `setContextEntries​(Map<String,​Object> entries)`
    `void` | `setContinuationEnabled​(boolean contStateStackEnabled)`
    `void` | `setDoingGET​(boolean b)`
    `void` | `setDoingMTOM​(boolean b)`
    `void` | `setDoingPOX​(boolean b)`
    `void` | `setDoingSWA​(boolean b)`
    `void` | `setEnvelope​(org.apache.axiom.soap.SOAPEnvelope envelope)`
    `void` | `setEnvironment​(org.apache.synapse.core.SynapseEnvironment se)`
    `void` | `setFaultResponse​(boolean b)`
    `void` | `setFaultTo​(String reference)` | This is used to set the value which specifies the receiver of the faults relating to the message.
    `void` | `setFaultTo​(org.apache.axis2.addressing.EndpointReference reference)`
    `void` | `setFrom​(String reference)` | This is used to set the value which specifies the sender of the message.
    `void` | `setFrom​(org.apache.axis2.addressing.EndpointReference reference)`
    `boolean` | `setJsonObject​(org.apache.synapse.MessageContext messageContext, Object jsonObject)` | Saves the JavaScript Object to the message context.
    `boolean` | `setJsonText​(org.apache.synapse.MessageContext messageContext, Object jsonObject)` | Saves the JSON String to the message context.
    `void` | `setMessageFlowTracingState​(int state)`
    `void` | `setMessageID​(String string)`
    `void` | `setPayloadJSON​(Object jsonPayload)` | Saves the payload of this message context as a JSON payload.
    `void` | `setPayloadJSON0​(Object jsonPayload)` | Saves the payload of this message context as a JSON payload.
    `void` | `setPayloadXML​(Object payload)` | Set the SOAP body payload from XML.
    `void` | `setProperty​(String key, Object value)` | Add a new property to the message.
    `void` | `setProperty​(String key, Object value, String scope)` | Add a new property to the message.
    `void` | `setRelatesTo​(org.apache.axis2.addressing.RelatesTo[] reference)`
    `void` | `setReplyTo​(String reference)` | This is used to set the value which specifies the receiver of the replies to the message.
    `void` | `setReplyTo​(org.apache.axis2.addressing.EndpointReference reference)`
    `void` | `setResponse​(boolean b)`
    `void` | `setScriptEngine​(ScriptEngine scriptEngine)` | Set a script engine.
    `void` | `setSoapAction​(String string)`
    `void` | `setTo​(String reference)` | This is used to set the value which specifies the receiver of the message.
    `void` | `setTo​(org.apache.axis2.addressing.EndpointReference reference)`
    `void` | `setTracingState​(int tracingState)`
    `void` | `setWSAAction​(String actionURI)`
    `void` | `setWSAMessageID​(String messageID)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CommonScriptMessageContext

          public CommonScriptMessageContext​(org.apache.synapse.MessageContext mc,
                                            org.apache.bsf.xml.XMLHelper xmlHelper)

  - ### Method Detail

    - #### getPayloadXML

          public Object getPayloadXML()
                               throws ScriptException

      Get the XML representation of SOAP Body payload. The payload is the first element inside the SOAP
      tags
      Specified by:
        `getPayloadXML` in interface `ScriptMessageContext`
      Returns:
        the XML SOAP Body
      Throws:
        `ScriptException` - in-case of an error in getting the XML representation of SOAP Body payload

    - #### setPayloadXML

          public void setPayloadXML​(Object payload)
                             throws org.apache.axiom.om.OMException,
                                    ScriptException

      Set the SOAP body payload from XML.
      Specified by:
        `setPayloadXML` in interface `ScriptMessageContext`
      Parameters:
        `payload` - Message payload
      Throws:
        `ScriptException` - For errors in converting xml To OM
        `org.apache.axiom.om.OMException` - For errors in OM manipulation

    - #### getPayloadJSON

          public Object getPayloadJSON()

      Get the JSON object representation of the JSON message body of the request.
      Specified by:
        `getPayloadJSON` in interface `ScriptMessageContext`
      Returns:
        JSON object of the message body

    - #### getJsonText

          public Object getJsonText()

      Get the Message Payload as a text.
      Specified by:
        `getJsonText` in interface `ScriptMessageContext`
      Returns:
        Payload as text

    - #### getPayloadText

          public String getPayloadText()

      Get the Message Payload as a text.
      Specified by:
        `getPayloadText` in interface `ScriptMessageContext`
      Returns:
        Payload as text

    - #### setPayloadJSON0

          public void setPayloadJSON0​(Object jsonPayload)
                               throws ScriptException

      Saves the payload of this message context as a JSON payload.
      Parameters:
        `jsonPayload` - Javascript native object to be set as the message body
      Throws:
        `ScriptException` - in case of creating a JSON object out of the javascript native object.

    - #### setJsonObject

          public boolean setJsonObject​(org.apache.synapse.MessageContext messageContext,
                                       Object jsonObject)

      Saves the JavaScript Object to the message context.
      Specified by:
        `setJsonObject` in interface `ScriptMessageContext`
      Parameters:
        `messageContext` - The message context of the sequence
        `jsonObject` - JavaScript Object saved in this message context
      Returns:
        true

    - #### setJsonText

          public boolean setJsonText​(org.apache.synapse.MessageContext messageContext,
                                     Object jsonObject)

      Saves the JSON String to the message context.
      Specified by:
        `setJsonText` in interface `ScriptMessageContext`
      Parameters:
        `messageContext` - The message context of the sequence
        `jsonObject` - JavaScript Object saved in this message context
      Returns:
        false if messageContext is null return true otherwise

    - #### jsonObject

          public Object jsonObject​(org.apache.synapse.MessageContext messageContext)

      Returns the JavaScript Object saved in this message context.
      Specified by:
        `jsonObject` in interface `ScriptMessageContext`
      Parameters:
        `messageContext` - The message context of the sequence
      Returns:
        o JavaScript Object saved in this message context

    - #### setScriptEngine

          public void setScriptEngine​(ScriptEngine scriptEngine)

      Set a script engine.
      Specified by:
        `setScriptEngine` in interface `ScriptMessageContext`
      Parameters:
        `scriptEngine` - a ScriptEngine instance

    - #### addHeader

          public void addHeader​(boolean mustUnderstand,
                                Object content)
                         throws ScriptException

      Add a new SOAP header to the message.
      Specified by:
        `addHeader` in interface `ScriptMessageContext`
      Parameters:
        `mustUnderstand` - the value for the `soapenv:mustUnderstand` attribute
        `content` - the XML for the new header
      Throws:
        `ScriptException` - if an error occurs when converting the XML to OM

    - #### getEnvelopeXML

          public Object getEnvelopeXML()
                                throws ScriptException

      Get the XML representation of the complete SOAP envelope.
      Specified by:
        `getEnvelopeXML` in interface `ScriptMessageContext`
      Returns:
        return an object that represents the payload in the current scripting language
      Throws:
        `ScriptException` - in-case of an error in getting the XML representation of SOAP envelope

    - #### setTo

          public void setTo​(String reference)

      This is used to set the value which specifies the receiver of the message.
      Specified by:
        `setTo` in interface `ScriptMessageContext`
      Parameters:
        `reference` - specifies the receiver of the message

    - #### setFaultTo

          public void setFaultTo​(String reference)

      This is used to set the value which specifies the receiver of the faults relating to the message.
      Specified by:
        `setFaultTo` in interface `ScriptMessageContext`
      Parameters:
        `reference` - specifies the receiver of the faults relating to the message

    - #### setFrom

          public void setFrom​(String reference)

      This is used to set the value which specifies the sender of the message.
      Specified by:
        `setFrom` in interface `ScriptMessageContext`
      Parameters:
        `reference` - specifies the sender of the message

    - #### setReplyTo

          public void setReplyTo​(String reference)

      This is used to set the value which specifies the receiver of the replies to the message.
      Specified by:
        `setReplyTo` in interface `ScriptMessageContext`
      Parameters:
        `reference` - specifies the receiver of the replies to the message

    - #### getConfiguration

          public org.apache.synapse.config.SynapseConfiguration getConfiguration()

      Specified by:
        `getConfiguration` in interface `org.apache.synapse.MessageContext`

    - #### setConfiguration

          public void setConfiguration​(org.apache.synapse.config.SynapseConfiguration cfg)

      Specified by:
        `setConfiguration` in interface `org.apache.synapse.MessageContext`

    - #### getEnvironment

          public org.apache.synapse.core.SynapseEnvironment getEnvironment()

      Specified by:
        `getEnvironment` in interface `org.apache.synapse.MessageContext`

    - #### setEnvironment

          public void setEnvironment​(org.apache.synapse.core.SynapseEnvironment se)

      Specified by:
        `setEnvironment` in interface `org.apache.synapse.MessageContext`

    - #### getContextEntries

          public Map<String,​Object> getContextEntries()

      Specified by:
        `getContextEntries` in interface `org.apache.synapse.MessageContext`

    - #### setContextEntries

          public void setContextEntries​(Map<String,​Object> entries)

      Specified by:
        `setContextEntries` in interface `org.apache.synapse.MessageContext`

    - #### getProperty

          public Object getProperty​(String key)

      Specified by:
        `getProperty` in interface `org.apache.synapse.MessageContext`

    - #### getEntry

          public Object getEntry​(String key)

      Specified by:
        `getEntry` in interface `org.apache.synapse.MessageContext`

    - #### getLocalEntry

          public Object getLocalEntry​(String key)

      Specified by:
        `getLocalEntry` in interface `org.apache.synapse.MessageContext`

    - #### setProperty

          public void setProperty​(String key,
                                  Object value)

      Add a new property to the message.
      Specified by:
        `setProperty` in interface `org.apache.synapse.MessageContext`
      Parameters:
        `key` - unique identifier of property
        `value` - value of property

    - #### setProperty

          public void setProperty​(String key,
                                  Object value,
                                  String scope)

      Add a new property to the message.
      Specified by:
        `setProperty` in interface `ScriptMessageContext`
      Parameters:
        `key` - unique identifier of property
        `value` - value of property
        `scope` - scope of the property

    - #### removeProperty

          public void removeProperty​(String key,
                                     String scope)

      Remove property from the message.
      Specified by:
        `removeProperty` in interface `ScriptMessageContext`
      Parameters:
        `key` - unique identifier of property
        `scope` - scope of the property

    - #### getPropertyKeySet

          public Set getPropertyKeySet()

      Specified by:
        `getPropertyKeySet` in interface `org.apache.synapse.MessageContext`

    - #### getMainSequence

          public org.apache.synapse.Mediator getMainSequence()

      Specified by:
        `getMainSequence` in interface `org.apache.synapse.MessageContext`

    - #### getFaultSequence

          public org.apache.synapse.Mediator getFaultSequence()

      Specified by:
        `getFaultSequence` in interface `org.apache.synapse.MessageContext`

    - #### getSequence

          public org.apache.synapse.Mediator getSequence​(String key)

      Specified by:
        `getSequence` in interface `org.apache.synapse.MessageContext`

    - #### getFormat

          public org.apache.axiom.om.OMElement getFormat​(String s)

      Specified by:
        `getFormat` in interface `org.apache.synapse.MessageContext`

    - #### getEndpoint

          public org.apache.synapse.endpoints.Endpoint getEndpoint​(String key)

      Specified by:
        `getEndpoint` in interface `org.apache.synapse.MessageContext`

    - #### getEnvelope

          public org.apache.axiom.soap.SOAPEnvelope getEnvelope()

      Specified by:
        `getEnvelope` in interface `org.apache.synapse.MessageContext`

    - #### setEnvelope

          public void setEnvelope​(org.apache.axiom.soap.SOAPEnvelope envelope)
                           throws org.apache.axis2.AxisFault

      Specified by:
        `setEnvelope` in interface `org.apache.synapse.MessageContext`
      Throws:
        `org.apache.axis2.AxisFault`

    - #### getFaultTo

          public org.apache.axis2.addressing.EndpointReference getFaultTo()

      Specified by:
        `getFaultTo` in interface `org.apache.synapse.MessageContext`

    - #### setFaultTo

          public void setFaultTo​(org.apache.axis2.addressing.EndpointReference reference)

      Specified by:
        `setFaultTo` in interface `org.apache.synapse.MessageContext`

    - #### getFrom

          public org.apache.axis2.addressing.EndpointReference getFrom()

      Specified by:
        `getFrom` in interface `org.apache.synapse.MessageContext`

    - #### setFrom

          public void setFrom​(org.apache.axis2.addressing.EndpointReference reference)

      Specified by:
        `setFrom` in interface `org.apache.synapse.MessageContext`

    - #### getMessageID

          public String getMessageID()

      Specified by:
        `getMessageID` in interface `org.apache.synapse.MessageContext`

    - #### setMessageID

          public void setMessageID​(String string)

      Specified by:
        `setMessageID` in interface `org.apache.synapse.MessageContext`

    - #### getRelatesTo

          public org.apache.axis2.addressing.RelatesTo getRelatesTo()

      Specified by:
        `getRelatesTo` in interface `org.apache.synapse.MessageContext`

    - #### setRelatesTo

          public void setRelatesTo​(org.apache.axis2.addressing.RelatesTo[] reference)

      Specified by:
        `setRelatesTo` in interface `org.apache.synapse.MessageContext`

    - #### getReplyTo

          public org.apache.axis2.addressing.EndpointReference getReplyTo()

      Specified by:
        `getReplyTo` in interface `org.apache.synapse.MessageContext`

    - #### setReplyTo

          public void setReplyTo​(org.apache.axis2.addressing.EndpointReference reference)

      Specified by:
        `setReplyTo` in interface `org.apache.synapse.MessageContext`

    - #### getTo

          public org.apache.axis2.addressing.EndpointReference getTo()

      Specified by:
        `getTo` in interface `org.apache.synapse.MessageContext`

    - #### setTo

          public void setTo​(org.apache.axis2.addressing.EndpointReference reference)

      Specified by:
        `setTo` in interface `org.apache.synapse.MessageContext`

    - #### setWSAAction

          public void setWSAAction​(String actionURI)

      Specified by:
        `setWSAAction` in interface `org.apache.synapse.MessageContext`

    - #### getWSAAction

          public String getWSAAction()

      Specified by:
        `getWSAAction` in interface `org.apache.synapse.MessageContext`

    - #### getSoapAction

          public String getSoapAction()

      Specified by:
        `getSoapAction` in interface `org.apache.synapse.MessageContext`

    - #### setSoapAction

          public void setSoapAction​(String string)

      Specified by:
        `setSoapAction` in interface `org.apache.synapse.MessageContext`

    - #### setWSAMessageID

          public void setWSAMessageID​(String messageID)

      Specified by:
        `setWSAMessageID` in interface `org.apache.synapse.MessageContext`

    - #### getWSAMessageID

          public String getWSAMessageID()

      Specified by:
        `getWSAMessageID` in interface `org.apache.synapse.MessageContext`

    - #### isDoingMTOM

          public boolean isDoingMTOM()

      Specified by:
        `isDoingMTOM` in interface `org.apache.synapse.MessageContext`

    - #### isDoingSWA

          public boolean isDoingSWA()

      Specified by:
        `isDoingSWA` in interface `org.apache.synapse.MessageContext`

    - #### setDoingMTOM

          public void setDoingMTOM​(boolean b)

      Specified by:
        `setDoingMTOM` in interface `org.apache.synapse.MessageContext`

    - #### setDoingSWA

          public void setDoingSWA​(boolean b)

      Specified by:
        `setDoingSWA` in interface `org.apache.synapse.MessageContext`

    - #### isDoingPOX

          public boolean isDoingPOX()

      Specified by:
        `isDoingPOX` in interface `org.apache.synapse.MessageContext`

    - #### setDoingPOX

          public void setDoingPOX​(boolean b)

      Specified by:
        `setDoingPOX` in interface `org.apache.synapse.MessageContext`

    - #### isDoingGET

          public boolean isDoingGET()

      Specified by:
        `isDoingGET` in interface `org.apache.synapse.MessageContext`

    - #### setDoingGET

          public void setDoingGET​(boolean b)

      Specified by:
        `setDoingGET` in interface `org.apache.synapse.MessageContext`

    - #### isSOAP11

          public boolean isSOAP11()

      Specified by:
        `isSOAP11` in interface `org.apache.synapse.MessageContext`

    - #### setResponse

          public void setResponse​(boolean b)

      Specified by:
        `setResponse` in interface `org.apache.synapse.MessageContext`

    - #### isResponse

          public boolean isResponse()

      Specified by:
        `isResponse` in interface `org.apache.synapse.MessageContext`

    - #### setFaultResponse

          public void setFaultResponse​(boolean b)

      Specified by:
        `setFaultResponse` in interface `org.apache.synapse.MessageContext`

    - #### isFaultResponse

          public boolean isFaultResponse()

      Specified by:
        `isFaultResponse` in interface `org.apache.synapse.MessageContext`

    - #### getTracingState

          public int getTracingState()

      Specified by:
        `getTracingState` in interface `org.apache.synapse.MessageContext`

    - #### setTracingState

          public void setTracingState​(int tracingState)

      Specified by:
        `setTracingState` in interface `org.apache.synapse.MessageContext`

    - #### getFaultStack

          public Stack<org.apache.synapse.FaultHandler> getFaultStack()

      Specified by:
        `getFaultStack` in interface `org.apache.synapse.MessageContext`

    - #### pushFaultHandler

          public void pushFaultHandler​(org.apache.synapse.FaultHandler fault)

      Specified by:
        `pushFaultHandler` in interface `org.apache.synapse.MessageContext`

    - #### pushContinuationState

          public void pushContinuationState​(org.apache.synapse.ContinuationState continuationState)

      Specified by:
        `pushContinuationState` in interface `org.apache.synapse.MessageContext`

    - #### getContinuationStateStack

          public Stack<org.apache.synapse.ContinuationState> getContinuationStateStack()

      Specified by:
        `getContinuationStateStack` in interface `org.apache.synapse.MessageContext`

    - #### isContinuationEnabled

          public boolean isContinuationEnabled()

      Specified by:
        `isContinuationEnabled` in interface `org.apache.synapse.MessageContext`

    - #### setContinuationEnabled

          public void setContinuationEnabled​(boolean contStateStackEnabled)

      Specified by:
        `setContinuationEnabled` in interface `org.apache.synapse.MessageContext`

    - #### getServiceLog

          public org.apache.commons.logging.Log getServiceLog()

      Specified by:
        `getServiceLog` in interface `org.apache.synapse.MessageContext`

    - #### getSequenceTemplate

          public org.apache.synapse.Mediator getSequenceTemplate​(String key)

      Specified by:
        `getSequenceTemplate` in interface `org.apache.synapse.MessageContext`

    - #### setPayloadJSON

          public void setPayloadJSON​(Object jsonPayload)
                              throws ScriptException

      Saves the payload of this message context as a JSON payload.
      Specified by:
        `setPayloadJSON` in interface `ScriptMessageContext`
      Parameters:
        `jsonPayload` - Javascript native object to be set as the message body
      Throws:
        `ScriptException` - in case of creating a JSON object out of the javascript native object.

    - #### getDefaultConfiguration

          public org.apache.synapse.Mediator getDefaultConfiguration​(String arg0)

      Specified by:
        `getDefaultConfiguration` in interface `org.apache.synapse.MessageContext`

    - #### getMessageString

          public String getMessageString()

      Specified by:
        `getMessageString` in interface `org.apache.synapse.MessageContext`

    - #### setMessageFlowTracingState

          public void setMessageFlowTracingState​(int state)

      Specified by:
        `setMessageFlowTracingState` in interface `org.apache.synapse.MessageContext`

    - #### getMessageFlowTracingState

          public int getMessageFlowTracingState()

      Specified by:
        `getMessageFlowTracingState` in interface `org.apache.synapse.MessageContext`