WSO2 Enterprise Service Bus has the concept of Proxy Services. Proxy Services are designed to be virtual services that expose an actual service to the outside world. Usually when a request comes to a Proxy Service, it forwards it to an actual service. Response from the actual service is sent to the client.
The above example is the normal behavior of Proxy Services. A Proxy Service is created using an XML configuration. This configuration determines where to send the message, what are the transformations that need to be done prior to sending the message etc. Also a Proxy Service configuration specifies what needs to be done to the actual response message before sending to the client. This XML language is called Apache Synapse language.
Message mediation is the other way WSO2 Enterprise Service Bus handles messages. In message mediation all the messages are sent to the main sequence. Usually messages are filtered and transformed in the main sequence before sending to the actual endpoint.
As with the Proxy Services, users can create a response and send it back from the main sequence.
Here is such a configuration.
There are a Proxy Service and main sequence. Both Proxy Service and main sequence uses a sequence called
response. This sequence creates a response and sends it back to the client.
1. Start WSO2 Enterprise Service Bus with this configuration. You can copy the above configuration into
synapse.xml which is found in the
conf directory and start WSO2 Enterprise Service Bus with
2. Then send a
POST request to the Proxy Service or main sequence.
For invoking the proxy service
For invoking the main sequence, you need to use a URL which is not a Proxy Service.
3. Both Proxy Service and the main sequence executes the
response sequence when a message comes to them. The response sequence is in the request path. So we are transforming the request message to a response message.
4. Response sequence uses the Script Mediator to set a custom payload to the message. Then it removes the
To header. Since we are sending the message back,
To header is not required and not expected by WSO2 Enterprise Service Bus.
All these changes are done to the incoming request message.
5. Now it removes another property called
NO_ENTITY_BODY. If this property is present and if its value is
true WSO2 Enterprise Service Bus will not send the response body. Instead it will just send the headers. In case of a
GET request this property is set. Remove it, in order to send the response body.
6. The property
RESPONSE is set. This property indicates that this is a response message and it needs to be sent back to the client. At this point we are virtually turning the request back to a response. If you use a Send Mediator without setting this property, you can see that our custom message is being sent to the service.
7. Finally we do a send. This send, sends back the created response message.
See the source in the WSO2 library.