Sunday, January 5, 2014

Using JBoss ESB to Access REST services

 
jboss esbJBoss ESB has a lot of pre-defined actions which can be used to proxy request to other services/protocols. One interesting one is the HttpRouter which allows the invocation of external (ESB unaware) Http endpoints from an ESB action pipeline. This action uses Apache Commons HttpClient under the covers.

In this short tutorial we will see, how to proxy your REST service invocations with JBoss ESB.

jboss esb httprouter
Supposing you have defined a REST service with the following GET method:

01.package sample;
02. 
03.import javax.ws.rs.*;
04. 
05.@Path("tutorial")
06.public class HelloWorld
07.{
08. 
09.@GET
10.@Path("helloworld")
11.public String helloworld() {
12.return "Hello World!";
13.}
14.}
In order to invoke this REST service we will configure an HttpRouter action in a basic  jboss-esb.xml file:
01.xml version "1.0" encoding "UTF-8"?>
03. 
04.<providers>
05.<jms-provider name="JBossMQ" connection-factory="ConnectionFactory">
06.<jms-bus busid="quickstartGwChannel">
07.<jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_helloworld_Request_gw"
08./>
09.</jms-bus>
10.<jms-bus busid="quickstartEsbChannel">
11.<jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_helloworld_Request_esb"
12./>
13.</jms-bus>
14. 
15.</jms-provider>
16.</providers>
17. 
18.<services>
19. 
20.<service category="FirstServiceESB" name="SimpleListener" description="Hello World">
21.<listeners>
22.<jms-listener name="JMS-Gateway" busidref="quickstartGwChannel" is-gateway="true" />
23.<jms-listener name="helloWorld" busidref="quickstartEsbChannel" />
24.</listeners>
25. 
26.<actions mep="OneWay">
27. 
28.
29.<action name="httprouter"  class="org.jboss.soa.esb.actions.routing.http.HttpRouter">
30.<property name="endpointUrl" value="http://localhost:8080/rest/tutorial/helloworld">
31.<http-client-property name="file" value="/ht.props"/>
32.</property>
33. 
34.<property name="method" value="GET"/>   
35.<property name="responseType" value="STRING"/>
36. 
37.</action>    
38. 
39.<action name="action2" class="org.jboss.soa.esb.actions.SystemPrintln">
40.<property name="printfull" value="false"/>
41.</action>
42. 
43.<action name="testStore" class="org.jboss.soa.esb.actions.TestMessageStore"/>
44. 
45.</actions>
46.</service>
47.</services>
48. 
49.</jbossesb>
Note: this action requires a file named ht.props at the root of the .esb archive which  contains client's http connection properties. Including a property file is optional, however it s is generally used for fine tuning the http connection. For example, here are two properties you might include in your ht.props file:

max-connections-per-host=100
max-total-connections=100

You might add a bit more of complexity to your service by passing Header parameters to your REST service:
1.@Path("callService")
2.public String callService(@HeaderParam("parameter1") String parameter1) {
3....
4.}
Header parameters will be sent using the "header" element, inside the "property" section:
01.<action name="httprouter"  class="org.jboss.soa.esb.actions.routing.http.HttpRouter">
02.<property name="endpointUrl" value="http://localhost:8080/rest/tutorial/callService">
03.<http-client-property name="file" value="/ht.props"/>
04.</property>
05. 
06.<property name="method" value="GET"/>   
07.<property name="responseType" value="STRING"/>
08. 
09.<property name="headers">
10.<header name="parameter1" value="blahval" ></header>
11.</property>
12. 
13.</action>
For your reference, here's the list of properties supported by the HttpRouter action:
 <
PropertyDescriptionRequired
unwrap
Setting this to true (the default) will extract the message payload from the Message object before sending. false will send the serialized Message as either XML or Base64 encoded JavaSerialized object, based on the MessageType.
No
endpointUrl
The endpoint to which the message will be forwarded.
Yes
http-client-property
The HttpRouter uses the HttpClientFactory to create and configure the HttpClient instance. You can specify the configuration of the factory by using the file property which will point to a properties file on the local file system, classpath or URI based. 
No
method
Currently only supports GET and POST.
Yes
responseType
Specifies in what form the response should be sent back. Either STRING or BYTES. Default value is STRING.
No
headers
To be added to the request. Supports multiple
elements.
No
MappedHeaderList
A comma separated list of header names that should be propagated to the target endpoint. 
No
Top Programming Sites

6 comments:

oakleyses said...

louis vuitton handbags, oakley sunglasses, louboutin, longchamp outlet, nike shoes, louis vuitton outlet stores, chanel handbags, burberry outlet, prada outlet, jordan shoes, tiffany and co, michael kors outlet, tory burch outlet, louis vuitton outlet, longchamp handbags, nike free, true religion jeans, michael kors outlet, kate spade outlet, polo ralph lauren outlet, tiffany and co, prada handbags, polo ralph lauren outlet, michael kors outlet, michael kors outlet, longchamp handbags, oakley sunglasses, ray ban sunglasses, kate spade handbags, burberry outlet, louis vuitton outlet, louboutin outlet, louboutin, coach factory outlet, air max, air max, coach outlet, gucci outlet, christian louboutin shoes, michael kors outlet, coach purses, ray ban sunglasses, michael kors outlet, louis vuitton, coach outlet store online, true religion jeans, oakley sunglasses cheap

oakleyses said...

ralph lauren, lululemon, air max, hollister, north face, nike air max, polo lacoste, vanessa bruno, timberland, vans pas cher, louboutin, louis vuitton, oakley pas cher, air max pas cher, nike roshe run, air max, true religion outlet, barbour, sac longchamp, air force, hollister, sac louis vuitton, nike free, polo ralph lauren, nike trainers, louis vuitton uk, nike roshe, sac hermes, longchamp, michael kors, sac burberry, sac guess, mulberry, new balance pas cher, converse pas cher, sac louis vuitton, hogan outlet, nike tn, north face, true religion outlet, ray ban pas cher, michael kors, air jordan, nike blazer, nike free pas cher, michael kors pas cher, abercrombie and fitch, ray ban sunglasses

oakleyses said...

mac cosmetics, mont blanc, marc jacobs, canada goose outlet, nike huarache, vans shoes, soccer jerseys, hollister, giuseppe zanotti, beats by dre, abercrombie and fitch, longchamp, insanity workout, celine handbags, bottega veneta, ghd, nfl jerseys, north face outlet, chi flat iron, ugg boots, birkin bag, ugg australia, canada goose, herve leger, ugg pas cher, rolex watches, valentino shoes, canada goose uk, canada goose, ferragamo shoes, canada goose, ugg boots, uggs outlet, north face jackets, soccer shoes, asics running shoes, new balance shoes, p90x, lululemon outlet, canada goose jackets, mcm handbags, instyler, babyliss pro, ugg, wedding dresses, jimmy choo outlet, reebok outlet, nike roshe run

oakleyses said...

parajumpers, karen millen, air max, converse, pandora charms, moncler, louboutin, moncler, links of london, lancel, juicy couture outlet, oakley, hollister, pandora charms, supra shoes, thomas sabo, canada goose, gucci, wedding dresses, timberland boots, swarovski crystal, air max, coach outlet store online, moncler, ray ban, canada goose, moncler, ugg, louis vuitton, swarovski, hollister, montre homme, moncler, hollister clothing store, ralph lauren, rolex watches, moncler outlet, moncler, iphone 6 cases, baseball bats, juicy couture outlet, toms shoes, vans, pandora jewelry, ugg, converse shoes

Zheng junxai5 said...

zhengjx20160721
michael kors outlet clearance
jordan retro 4
kobe 8
coach factory outlet online
rolex watches
nike free uk
coach factory outlet
air max
kate spade handbags
louis vuitton outlet stores
cheap ray ban sunglasses
kd 8
ralph lauren polo
air jordan 4
jordan 6s
air jordan homme
michael kors outlet clearance
rolex watches
louis vuitton handbags
designer handbags
coach outlet online
cheap basketball shoes
oakley canada
kate spade outlet
louis vuitton bags
cheap jordans
toms wedges
longchamp handbags
ralph lauren home
coach outlet
louis vuitton outlet
michael kors outlet
kate spade outlet
nike air max uk
michael kors outlet
louis vuitton outlet stores
montblanc pen
true religion outlet

raybanoutlet001 said...

fitflops sale
cheap air jordans
huarache shoes
nike huarache sale
cheap jordans
air jordan shoes
michael kors handbags
cheap jordans online
michael kors outlet
michael kors outlet
nike huarache
michael kors handbags,michael kors handbags clearance,michael kors clearance
nfl jerseys from china
true religion store
nmd adidas store
air jordan shoes
adidas yeezy boost
michael kors outlet online
http://www.outlettiffanyand.co
tiffany and co outlet
adidas stan smith
tiffany jewelry
http://www.oakleystoreonline.us.org
ugg outlet