Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

Code Block

<?xml version="1.0" encoding="UTF-8"?>
<syn:definitions xmlns:syn="http://ws.apache.org/ns/synapse">
	<syn:registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
		<syn:parameter name="cachableDuration">15000</syn:parameter>
	</syn:registry>
	<syn:proxy name="EchoProxy" transports="https http" startOnLoad="true" trace="disable">
		<syn:target inSequence="response"/>
	</syn:proxy>
	<syn:sequence name="main">
		<syn:sequence key="response"/>
	</syn:sequence>
	<syn:sequence name="fault">
		<syn:log/>
	</syn:sequence>
	<syn:sequence name="response">
		<syn:script language="js">
			mc.setPayloadXML(
			&lt;greeting&gt;Hello World&lt;/greeting&gt;
			);
		</syn:script>
		<syn:header name="To" action="remove"/>
		<syn:property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
		<syn:property name="RESPONSE" value="true"/>
		<syn:send/>
		<syn:log level="full"/>
	</syn:sequence>
</syn:definitions>

...

For invoking the proxy service

Code Block

http://localhost:8280/services/EchoProxy

For invoking the main sequence, you need to use a URL which is not a Proxy Service.

Code Block

http://localhost:8280/services/Response

...

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.

...

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.

...

See the source in the WSO2 library.

Excerpt
hiddentrue

Instructions on generating a simple response.