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, Object content)`
    `Object` | `getEnvelopeXML()`
    `Object` | `getJsonText()` Get the Message Payload as a text.
    `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` | `jsonObject(org.apache.synapse.MessageContext messageContext)` Get the JSON object representation of the JSON message body of the request.
    `void` | `removeProperty(String key, String scope)` Remove property from the message.
    `void` | `setFaultTo(String reference)`
    `void` | `setFrom(String 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` | `setPayloadJSON(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, String scope)` Add a new property to the message.
    `void` | `setReplyTo(String reference)`
    `void` | `setScriptEngine(ScriptEngine scriptEngine)` Set a script engine.
    `void` | `setTo(String reference)` Helpers to set EPRs from a script string.

    - ### 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

          Object getPayloadXML()
                        throws 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:
        `ScriptException` - in-case of an error in getting the XML representation of SOAP Body payload

    - #### setPayloadXML

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

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

    - #### getPayloadJSON

          Object getPayloadJSON()

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

    - #### getJsonText

          Object getJsonText()

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

    - #### getPayloadText

          String getPayloadText()

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

    - #### setJsonObject

          boolean setJsonObject(org.apache.synapse.MessageContext messageContext,
                                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,
                              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

          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(ScriptEngine scriptEngine)

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

    - #### addHeader

          void addHeader(boolean mustUnderstand,
                         Object content)
                  throws ScriptException

      Throws:
        `ScriptException`

    - #### getEnvelopeXML

          Object getEnvelopeXML()
                         throws ScriptException

      Throws:
        `ScriptException`

    - #### setTo

          void setTo(String reference)

      Helpers to set EPRs from a script string.

    - #### setFaultTo

          void setFaultTo(String reference)

    - #### setFrom

          void setFrom(String reference)

    - #### setReplyTo

          void setReplyTo(String reference)

    - #### setProperty

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

      Add a new property to the message.
      Parameters:
        `key` - unique identifier of property
        `value` - value of property
        `scope` - scope of the property
      Throws:
        `ScriptException` - if an error occurs when converting the XML to OM

    - #### removeProperty

          void removeProperty(String key,
                              String scope)

      Remove property from the message.
      Parameters:
        `key` - unique identifier of property
        `scope` - scope of the property
      Throws:
        `ScriptException` - if an error occurs when converting the XML to OM

    - #### setPayloadJSON

          void setPayloadJSON(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.

Copyright © 2005–2017 Apache Software Foundation. All rights reserved.