org.apache.synapse.mediators.bsf

## Interface ScriptMessageContext

- All Superinterfaces:
    org.apache.synapse.MessageContext
  All Known Implementing Classes:
    CommonScriptMessageContext, NashornJavaScriptMessageContext

      public interface ScriptMessageContext
      extends org.apache.synapse.MessageContext

  ScriptMessageContext decorates the MessageContext interface by adding methods to use when deals with message payload XML/Json, in a way natural to the scripting languages.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addHeader(boolean mustUnderstand, java.lang.Object content)` Add a new SOAP header to the message.
    `java.lang.Object` | `getEnvelopeXML()` Get the XML representation of the complete SOAP envelope.
    `java.lang.Object` | `getJsonText()` Get the Message Payload as a text.
    `java.lang.Object` | `getPayloadJSON()` Get the JSON object representation of the JSON message body of the request.
    `java.lang.String` | `getPayloadText()` Get the Message Payload as a text.
    `java.lang.Object` | `getPayloadXML()` Get the XML representation of SOAP Body payload.
    `java.lang.Object` | `jsonObject(org.apache.synapse.MessageContext messageContext)` Get the JSON object representation of the JSON message body of the request.
    `void` | `removeProperty(java.lang.String key, java.lang.String scope)` Remove property from the message.
    `void` | `setFaultTo(java.lang.String reference)` This is used to set the value which specifies the receiver of the faults relating to the message.
    `void` | `setFrom(java.lang.String reference)` This is used to set the value which specifies the sender of the message.
    `boolean` | `setJsonObject(org.apache.synapse.MessageContext messageContext, java.lang.Object jsonObject)` Saves the JavaScript Object to the message context.
    `boolean` | `setJsonText(org.apache.synapse.MessageContext messageContext, java.lang.Object jsonObject)` Saves the JSON String to the message context.
    `void` | `setPayloadJSON(java.lang.Object jsonPayload)` Saves the payload of this message context as a JSON payload.
    `void` | `setPayloadXML(java.lang.Object payload)` Set the SOAP body payload from XML.
    `void` | `setProperty(java.lang.String key, java.lang.Object value, java.lang.String scope)` Add a new property to the message.
    `void` | `setReplyTo(java.lang.String reference)` This is used to set the value which specifies the receiver of the replies to the message.
    `void` | `setScriptEngine(javax.script.ScriptEngine scriptEngine)` Set a script engine.
    `void` | `setTo(java.lang.String reference)` This is used to set the value which specifies the receiver of the message.

    - ### Methods inherited from interface org.apache.synapse.MessageContext

      `getConfiguration, getContextEntries, getContinuationStateStack, getDefaultConfiguration, getEndpoint, getEntry, getEnvelope, getEnvironment, getFaultSequence, getFaultStack, getFaultTo, getFormat, getFrom, getLocalEntry, getMainSequence, getMessageFlowTracingState, getMessageID, getMessageString, getProperty, getPropertyKeySet, getRelatesTo, getReplyTo, getSequence, getSequenceTemplate, getServiceLog, getSoapAction, getTo, getTracingState, getWSAAction, getWSAMessageID, isContinuationEnabled, isDoingGET, isDoingMTOM, isDoingPOX, isDoingSWA, isFaultResponse, isResponse, isSOAP11, pushContinuationState, pushFaultHandler, setConfiguration, setContextEntries, setContinuationEnabled, setDoingGET, setDoingMTOM, setDoingPOX, setDoingSWA, setEnvelope, setEnvironment, setFaultResponse, setFaultTo, setFrom, setMessageFlowTracingState, setMessageID, setProperty, setRelatesTo, setReplyTo, setResponse, setSoapAction, setTo, setTracingState, setWSAAction, setWSAMessageID`

- - ### Method Detail

    - #### getPayloadXML

          java.lang.Object getPayloadXML()
                                  throws javax.script.ScriptException

      Get the XML representation of SOAP Body payload. The payload is the first element inside the SOAP
      tags.
      Returns:
        the XML SOAP Body
      Throws:
        `javax.script.ScriptException` - in-case of an error in getting the XML representation of SOAP Body payload

    - #### setPayloadXML

          void setPayloadXML(java.lang.Object payload)
                      throws org.apache.axiom.om.OMException,
                             javax.script.ScriptException

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

    - #### getPayloadJSON

          java.lang.Object getPayloadJSON()

      Get the JSON object representation of the JSON message body of the request.
      Returns:
        JSON object of the message body

    - #### getJsonText

          java.lang.Object getJsonText()

      Get the Message Payload as a text.
      Returns:
        Payload as text

    - #### getPayloadText

          java.lang.String getPayloadText()

      Get the Message Payload as a text.
      Returns:
        Payload as text

    - #### setJsonObject

          boolean setJsonObject(org.apache.synapse.MessageContext messageContext,
                                java.lang.Object jsonObject)

      Saves the JavaScript Object to the message context.
      Parameters:
        `messageContext` - The message context of the sequence
        `jsonObject` - JavaScript Object which is passed to be saved in message context
      Returns:
        true

    - #### setJsonText

          boolean setJsonText(org.apache.synapse.MessageContext messageContext,
                              java.lang.Object jsonObject)

      Saves the JSON String to the message context.
      Parameters:
        `messageContext` - The message context of the sequence
        `jsonObject` - JavaScript string which is passed to be saved in message context
      Returns:
        false if messageContext is null return true otherwise

    - #### jsonObject

          java.lang.Object jsonObject(org.apache.synapse.MessageContext messageContext)

      Get the JSON object representation of the JSON message body of the request.
      Returns:
        JSON object of the message body

    - #### setScriptEngine

          void setScriptEngine(javax.script.ScriptEngine scriptEngine)

      Set a script engine.
      Parameters:
        `scriptEngine` - a ScriptEngine instance

    - #### addHeader

          void addHeader(boolean mustUnderstand,
                         java.lang.Object content)
                  throws javax.script.ScriptException

      Add a new SOAP header to the message.
      Parameters:
        `mustUnderstand` - the value for the `soapenv:mustUnderstand` attribute
        `content` - the XML for the new header
      Throws:
        `javax.script.ScriptException` - if an error occurs when converting the XML to OM

    - #### getEnvelopeXML

          java.lang.Object getEnvelopeXML()
                                   throws javax.script.ScriptException

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

    - #### setTo

          void setTo(java.lang.String reference)

      This is used to set the value which specifies the receiver of the message.
      Parameters:
        `reference` - specifies the receiver of the message

    - #### setFaultTo

          void setFaultTo(java.lang.String reference)

      This is used to set the value which specifies the receiver of the faults relating to the message.
      Parameters:
        `reference` - specifies the specifies the receiver of the faults relating to the message

    - #### setFrom

          void setFrom(java.lang.String reference)

      This is used to set the value which specifies the sender of the message.
      Parameters:
        `reference` - specifies the sender of the message

    - #### setReplyTo

          void setReplyTo(java.lang.String reference)

      This is used to set the value which specifies the receiver of the replies to the message.
      Parameters:
        `reference` - specifies the receiver of the replies to the message

    - #### setProperty

          void setProperty(java.lang.String key,
                           java.lang.Object value,
                           java.lang.String scope)

      Add a new property to the message.
      Parameters:
        `key` - unique identifier of property
        `value` - value of property
        `scope` - scope of the property

    - #### removeProperty

          void removeProperty(java.lang.String key,
                              java.lang.String scope)

      Remove property from the message.
      Parameters:
        `key` - unique identifier of property
        `scope` - scope of the property

    - #### setPayloadJSON

          void setPayloadJSON(java.lang.Object jsonPayload)
                       throws javax.script.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:
        `javax.script.ScriptException` - in case of creating a JSON object out of the javascript native object.

Copyright © 2005-2020 Apache Software Foundation. All Rights Reserved.