## Apache Synapse

## Introduction

Apache Synapse supports standard XPath functions and variables through its underlying XPath engine. Apart from standard XPath functions, there are several custom XPath functions and variables defined by Synapse to retrieve various message context properties.

## Contents

- Functions
  - get-property
  - base64Encode
  - base64Decode
  - url-encode
- Variables
  - axis2
  - trp
  - ctx
  - url
  - body
  - header

## Custom Functions

### get-property function

Get property function retrieves a property from the message context at the given scope. If the scope is not specified, property is retrieved from the default synapse scope.

Syntax:

get-property(String scope, String propertyName) get-property(String propertyName)

#### Supported Scopes

- default
- axis2
- transport
- registry
- system

#### Default scope

Message context properties residing in Synapse scope can be retrieved from the default scope. These are the properties directly set on the Synapse MessageContext instance. Apart from user defined properties, following special properties can also be retrieved from the default scope.

Name | Return Value
To | Incoming URL as a String or empty string if a To address is not defined.
From | From address as a String or empty string if a From address is not defined
Action | SOAP Action header value as a String or empty string if a Action is not defined
FaultTo | SOAP FautTo header value as a String or empty string if a FaultTo address is not defined
ReplyTo | ReplyTo header value as a String or empty string if a ReplyTo address is not defined
MessageID | A unique identifier (UUID) for the message as a String . This id is guaranteed to be unique.
FAULT | TRUE if the message has a fault or empty string if message doesn't have a fault
MESSAGE_FORMAT | Returns pox, get, soap11, soap12 depending on the message. If a message type is unknown this returns soap12
OperationName | Operation name corresponding to the message.

#### Axis2 scope

Message context properties residing in axis2 scope can be retrieved from the axis2 scope. These are the properties set on the underlying Axis2 MessageContext object.

#### Transport scope

Message context properties residing in transport scope can be retrieved from the transport scope. These are the transport headers set on the MessageContext.

#### Registry scope

Properties residing in registry can be retrieved from the registry scope.

#### System scope

Java System properties can be retrieved from the system scope.

### base64Encode function

Returns the base64 encoded value of the argument.

Syntax:

base64Encode(String value)

### base64Decode function

Returns the base64 decoded value of the argument.

Syntax:

base64Decode(String value)

### url-encode function

Returns the URL encoded value of the argument.

Syntax:

url-encode(String value)

## Variables

There are several XPath variables supported by Synapse. These are used for accessing various properties from the message context

- $axis2
- $trp
- $ctx
- $url
- $body
- $header

These XPath variables get the properties at various scopes.

#### $ctx

Variable prefix for accessing the MessageContext properties in default scope.

i.e To get the property named 'foo' at the default scope use the following XPath expression

$ctx:foo

#### $axis2

Variable prefix for accessing the axis2 MessageContext properties

i.e. To get the property named 'messageType' use the following XPath expression

$axis2:messageType

#### $trp

Variable prefix for accessing transport headers of the message

i.e. To get the transport header named Content-Type use the following XPath expression

$trp:Content-Type

#### $url

Variable prefix for accessing URL parameters of the message

i.e. To get the URL parameter named 'bar' use the following XPth expression

$url:bar

#### $body

Get the message body

#### $header

Get the soap header