Skip to content
This repository was archived by the owner on Jul 9, 2022. It is now read-only.

Http outbound gateway

olegz edited this page Jun 5, 2012 · 7 revisions

NOTE: Version 1.0.0.M1 of Sprint Integration Scala DSL provides initial and very basic support for HTTP Outbound Gateway which will be enhanced in subsequence milestones to allow for configuration adequate to its XML counterpart. Please follow https://jira.springsource.org/browse/INTSCALA-26 and https://jira.springsource.org/browse/INTSCALA-20 for the status of these enhancements


Continuation from HTTP Outbound Gateway could be expressed using '-->' operator.

HTTP Outbound Gateway

Root DSL element for HTTP Outbound Gateway is http

http.GET[String]("http://www.google.com/finance/info?q=vmw") 

You may remember from XML configuration that the main two attributes of any HTTP Outbound Gateway are HTTP Method name and Response type, and as you can see form above HTTP Method name is expressed by the actual method you call on http while Response type is expressed by specifying expected return type of HTTP method. The input parameter of the HTTP method is URL.

Quite often you may need to dynamically determine the entire URL or its parts from the data that may come as part of the input Message. You may do so by calling a function or even a whole new Message flow. Here is an example from one of the test cases that shows how it can be done:

val tickerService =
      transform { s: String =>
        s.toLowerCase() match {
          case "vmw" => "VMWare"
          case "orcl" => "Oracle"
          case _ => "vmw"
        }
      }

val httpFlow =
    enrich("company" -> { name: String => tickerService.sendAndReceive[String](name) }) -->
    http.GET[String] { m: Message[String] => "http://www.google.com/finance/info?q=" + m.getPayload() } -->
    handle { quotes: Message[_] => println("QUOTES for " + quotes.getHeaders().get("company") + " : " + quotes) }

httpFlow.send("vmw")
. . .

In the above example we want to print a nicely formated message which contains the full name of the company for which we are getting a stock quote, however we are sending a Message which only contains companies' ticker symbol. So we use the enricher to enrich the message with 'company' header which we are obtaining by calling a whole other message flow. Than in the HTTP Outbound Gateway we are constructing the URL by concatenating static part of the URL expressed as String with dynamic part of the ticker symbol which is the payload of the incoming message.


[Back to Outbound Adapters and Gateways] (https://github.com/SpringSource/spring-integration-dsl-scala/wiki/Outbound-Adapters-and-Gateways)