Andrej Koelewijn

  • Home
  • About
  • Departments
    • cloud
    • java
    • mobile
    • open standards
    • oracle
    • oss
    • other
    • soa
    • software development
    • tablet
    • Uncategorized
    • web
  • Subscribe via RSS

Response transformers on Mule outbound endpoints

October 18th, 2009  |  Published in oss, soa  |  1 Comment

A coworker found a message on the mule-user mailing list that said that you have to apply response transformers on inbound endpoints, not on outbound endpoints. Sounds a bit weird to me, at least not very intuitive. Time for a test.

Response transformer in a pass-through-router

Here’s the mule config:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:http="http://www.mulesource.org/schema/mule/http/2.2" xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
	xmlns:scripting="http://www.mulesource.org/schema/mule/scripting/2.2"
	xsi:schemaLocation="

http://www.mulesource.org/schema/mule/scripting/2.2

http://www.mulesource.org/schema/mule/scripting/2.2/mule-scripting.xsd

http://www.mulesource.org/schema/mule/core/2.2

http://www.mulesource.org/schema/mule/core/2.2/mule.xsd

http://www.mulesource.org/schema/mule/http/2.2

http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd

http://www.mulesource.org/schema/mule/vm/2.2

http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">

  <scripting:transformer name="xTransformer">
    <scripting:script engine="groovy">
      <![CDATA[
	  payload + "x"
      ]]>
    </scripting:script>
  </scripting:transformer>

  <byte-array-to-string-transformer name="byteArrayToString" />

  <model name="sync-multicast-example">

    <service name="s1">
      <inbound>
        <http:inbound-endpoint host="localhost" port="11110" path="response-transformer-example" synchronous="true"
          name="s1.inbound.http"  />
      </inbound>
      <outbound>
        <pass-through-router>
          <http:outbound-endpoint host="localhost" port="11110" path="service1" synchronous="true"
          name="s1.outbound.http.1" responseTransformer-refs="byteArrayToString xTransformer" />
        </pass-through-router>
      </outbound>
    </service>

    <service name="service1">
      <inbound>
        <http:inbound-endpoint host="localhost" port="11110" path="service1" synchronous="true"
          name="service1.inbound.http"  />
      </inbound>
      <scripting:component>
        <scripting:script engine="groovy">
          <![CDATA[
          String s = "Service 1 result"
          return s
          ]]>
        </scripting:script>
      </scripting:component>
    </service>

  </model>
</mule>

Here’s how i start Mule:

#!/bin/bash
export MULE_HOME=/home/akoelewijn/programs/mule-standalone-2.2.1/
$MULE_HOME/bin/mule -config ./mule-config.xml

And here’s my test file:

#!/bin/bash
echo "<hello>World</echo>" | \
  curl -X POST -d @- http://localhost:11110/response-transformer-example

This results in the following:

Service 1 resultx

The result seems fine, the response transformer is called, and an x is appended to the result of calling service1. Maybe the problem has to do with chaining routers? Lets try that.

Response transformer in a chaining router

Here’s the mule config:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:http="http://www.mulesource.org/schema/mule/http/2.2" xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
	xmlns:scripting="http://www.mulesource.org/schema/mule/scripting/2.2"
	xsi:schemaLocation="

http://www.mulesource.org/schema/mule/scripting/2.2

http://www.mulesource.org/schema/mule/scripting/2.2/mule-scripting.xsd

http://www.mulesource.org/schema/mule/core/2.2

http://www.mulesource.org/schema/mule/core/2.2/mule.xsd

http://www.mulesource.org/schema/mule/http/2.2

http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd

http://www.mulesource.org/schema/mule/vm/2.2

http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">

  <scripting:transformer name="xTransformer">
    <scripting:script engine="groovy">
      <![CDATA[
	  payload + "x"
      ]]>
    </scripting:script>
  </scripting:transformer>

  <byte-array-to-string-transformer name="byteArrayToString" />

  <model name="sync-multicast-example">

    <service name="s1">
      <inbound>
        <http:inbound-endpoint host="localhost" port="11110" path="chaining-response-transformer-example" synchronous="true"
          name="s1.inbound.http"  />
      </inbound>
      <outbound>
        <chaining-router>
          <http:outbound-endpoint host="localhost" port="11110" path="service1" synchronous="true"
          name="s1.outbound.http.1" responseTransformer-refs="byteArrayToString xTransformer"/>
          <http:outbound-endpoint host="localhost" port="11110" path="service2" synchronous="true"
          name="s1.outbound.http.2" responseTransformer-refs="byteArrayToString xTransformer"/>
        </chaining-router>
      </outbound>
    </service>

    <service name="service1">
      <inbound>
        <http:inbound-endpoint host="localhost" port="11110" path="service1" synchronous="true"
          name="service1.inbound.http"  />
      </inbound>
      <scripting:component>
        <scripting:script engine="groovy">
          <![CDATA[
          String s = "Service 1 result"
          return s
          ]]>
        </scripting:script>
      </scripting:component>
    </service>

    <service name="service2">
      <inbound>
        <http:inbound-endpoint host="localhost" port="11110" path="service2" synchronous="true"
          name="service2.inbound.http" transformer-refs="byteArrayToString" />
      </inbound>
      <scripting:component>
        <scripting:script engine="groovy">
          <![CDATA[
          log.info("payload: ${payload}")
          String s = "Service 2 result"
          return payload + s
          ]]>
        </scripting:script>
      </scripting:component>
    </service>

  </model>
</mule>

The result of calling http://localhost:11110/chaining-response-transformer-example with curl:

Service 1 resultxService 2 resultx

Again, the response transformers seem to work fine. As far as i can tell, there’s no reason not to use response transformers on outbound endpoints.

Share and Enjoy:
  • del.icio.us
  • Google Bookmarks
  • DZone
  • SphereIt
  • StumbleUpon
  • Technorati
  • LinkedIn
  • HackerNews
  • PDF
  • Digg
  • Facebook
  • FriendFeed
  • Posterous
  • Tumblr
  • Twitter
  • RSS

View Comments

Feed Trackback Address
  1. Andy E. says:

    May 9th, 2010 at 6:26 am (#)

    Thanks, appreciate this post. Used the examples to do some debugging in mule w/ regard to returning specific HTTP response codes depending upon transformer errors.

Leave a Response

blog comments powered by Disqus

Tags

bi bpel camel cep css dsl esb esper google governance grails groovy gtalk html5 innovation internet ipad ivy java javascript jaxrs jersey jigsaw jquery linkeddata linux maven middleware mule noiv openoffice openweb oracle osgi oss plsql rdbms rest soa sql sun tablet web 2.0 xmpp yql

Archives

  • August 2010
  • June 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Recent Posts

  • Nice Java Decompiler tool: JD
  • VMware Player: The virtual machine is busy.
  • Adding a maven repository for installing features to ServiceMix
  • Upgrade Apache Camel in ServiceMix to version 2.3.0
  • A composite Rest service using Apache Camel

Categories

  • cloud
  • java
  • mobile
  • open standards
  • oracle
  • oss
  • other
  • soa
  • software development
  • tablet
  • Uncategorized
  • web

Recent Comments

  • Buddhika on Using google talk from java example
  • Anonymous on A composite Rest service using Apache Camel
  • Guest on How to find true cause of com.sun.star.uno.RuntimeException?
  • Absent Code attribute in method that is not native or abstract « Gooder Code - web development blog, php, java, asp.net, html, javascript on Absent Code attribute in method that is not native or abstract
  • Rmfume on Oracle best thing that could happen to JavaFX?
Buzz
andrkoel: RT @monkchips: James Governor's Monkchips » Day of The Dead: Web Drives Strong Demand for Java Skills http://monk.ly/d4UlND
9:17 PM Sep 03, 2010, comment
andrkoel: RT @monkchips: In which my business partner @sogrady explains Why You Should Pay Attention to Node.Js http://monk.ly/a4aGIP serverside # ...
3:06 PM Sep 03, 2010, comment
andrkoel: RT @stilkov: http://bit.ly/cDdqgl - AWS Identity and Access Management — I'd hate to have to compete against Amazon's Cloud offerings
8:47 AM Sep 03, 2010, comment
andrkoel: Twitter for ipad is nice, but i still think i need a tool to summarize all info, something like feedly or flipboard is the future
8:36 AM Sep 02, 2010, comment
andrkoel: Trying out the new twitter for ipad... Curious how the panels work.
8:32 AM Sep 02, 2010, comment
 


©2010 Andrej Koelewijn
Powered by WordPress using the Gridline Lite theme by Graph Paper Press.