The HTTP gateway

The HTTP gateway is an example of a gateway that processes both the request and response in a synchronous manner, waiting for a reply from the target ESB service before sending back the response, to the external client, using the same connection as the incoming request. The MessageComposer is responsible for handling the transformation of the messages in both directions.

A minimal configuration is as follows:

<service category="Chapter6Sample"
         description="A template for Chapter6"
         name="Chapter6Service">
  <listeners>
    <http-gateway name="Http"/>
  </listeners>

This code will expose an HTTP endpoint at http://<host>:<port>/<deployment.esb>/http/Chapter6Sample/Chapter6Service where host and port are the default values of the web server, typically localhost and 8080.

Here is a complete list of configuration options that can be used with this listener:

<http-gateway name="Http" urlPattern="/*">
  <property name="allowedPorts" value="8080,8081"/>
  <property name="payloadAs" value="STRING"/>
  <property name="synchronousTimeout" value="30000"/>
</http-gateway>

The urlPattern attribute will override the default URL value used by the ESB, for example the previous attribute will result in the gateway being mapped to http://<host>:<port>/<deployment.esb>/http/*, in other words, any location which starts with the above URL ('*' not included).

If the web server has been configured to expose web deployments on multiple ports then the allowedPorts attribute can be used to specify which ports are allowed to expose the gateway. For example with the previous urlPattern and allowedPorts our HTTP endpoint will now be exposed through the following endpoints, assuming that the web server is configured to handle requests on each:

http://<host>:8080/<.esbname>/http

http://<host>:8081/<.esbname>/http

The behavior of the gateway is synchronous by default, causing the client to block until a response is received. The gateway will wait for a response from the target ESB service, until one has been received or until a specified timeout has been exceeded. This timeout value can be configured through the synchronousTimeout property, which by default is 30,000 milliseconds or 30 seconds.

If asynchronous behavior is required then it can be configured as follows:

<http-gateway name="Http">
  <asyncResponse statusCode="202">
    <payload classpathResource="/202-static-response.xml"
             content-type="text/xml"
             characterEncoding="UTF-8" />
  </asyncResponse>
</http-gateway>

The statusCode attribute and payload configuration are optional, by default the gateway will respond to an asynchronous request with a status code of 200 (OK) and a zero length payload, in which case all that is required is to specify an empty asyncResponse element as follows.

<http-gateway name="Http">
  <asyncResponse/>
</http-gateway>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset