0% found this document useful (0 votes)
32 views2 pages

Create REST Services with Mule 3.3

This document discusses how to create REST services using Mule ESB 3.3. It shows how to define a REST class annotated with JAX-RS annotations, configure a Mule flow to use the Jersey REST component, and reference the REST class. It also provides an example of using Spring beans within REST classes in Mule.

Uploaded by

jayavardhankoti
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Create REST Services with Mule 3.3

This document discusses how to create REST services using Mule ESB 3.3. It shows how to define a REST class annotated with JAX-RS annotations, configure a Mule flow to use the Jersey REST component, and reference the REST class. It also provides an example of using Spring beans within REST classes in Mule.

Uploaded by

jayavardhankoti
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Creating REST Service Using Mule ESB 3.

3
Creating Rest Services with Mule is very easy as mule provides built-in support for Jersey. Create mule flow in mule studio like this.

First, create a REST class like this and link it to the REST component: view source print?

[Link] [Link]; [Link] [Link]; [Link] [Link]; [Link] [Link]; 05. 06. 07.@Path("restClass") [Link] class RestClass { 09. [Link] Response getExample(@QueryParam("param1")String param1) 11.{ [Link] [Link]([Link]).entity("hello " + param1).build(); 13.} 14. 15.}

This is how the Mule flow xml will look: view source print?
01.<?xml version="1.0" encoding="UTF-8"?> 02. 03.<mule xmlns:jersey="[Link] [Link]:http="[Link] [Link]="[Link] [Link]:doc="[Link] [Link]:spring="[Link] version="CE3.3.1" xmlns:xsi="[Link] xsi:schemaLocation="

[Link]://[Link]/schema/mule/http [Link] [Link]://[Link]/schema/mule/jersey [Link] [Link]://[Link]/schema/beans [Link] [Link]://[Link]/schema/mule/core [Link] "> 12.<flow name="restTestFlow1" doc:name="restTestFlow1"> 13.<http:inbound-endpoint exchange-pattern="request-response" [Link]="localhost" port="8081" doc:name="HTTP"/> 15.<jersey:resources doc:name="REST"> 16.<component class="RestClass"/> 17.</jersey:resources> 18.</flow> 19.</mule>

If you want to use the created spring bean in the rest Component, then first declare the component as a spring bean and then refer it in the jersey-resource using spring-object tag , like this: view source print?
01.<flow name="restTestFlow1" doc:name="restTestFlow1"> 02. 03.<http:inbound-endpoint exchange-pattern="request-response" host="localhost" [Link]="8081" doc:name="HTTP"/> 05.<spring:bean id="testBean" class="TestSpringBean"></spring:bean> 06.<spring:bean id="restClass"> 07.<spring:property name="bean" ref="testBean"></spring:property> 08.</spring:bean> 09. 10.<jersey:resources doc:name="REST"> 11.<component doc:name="rest component"> 12.<spring-object bean="restClass"> 13.</component> 14.</jersey:resources> 15.</flow>

You can use multiple REST classes also , like this: view source print?
1.<jersey:resources doc:name="REST"> 2.<component> 3.<spring-object bean="restService" /> 4.</component> 5.<component> 6.<spring-object bean="restService1" /> 7.</component> 8.</jersey:resources>

Mule Studio throws error "Required attribute class is not defined in component" , you can ignore this error, as it runs perfectly fine.

You might also like