MULE ESB REST Web Services
• Creating a JAX-RS resource
• Deploying a JAX-RS resource
• Consuming a REST resource
• JSON capabilities in Mule
What is REST?
• REpresentational State Transfer (REST)
• Architectural style for a well-designed (RESTful) hypertext application
• Design of the Web supports the REST architectural style
• REST applies to client–server architecture:
- resources are found on a server
- client requests a "representation" of a resource’s current state
• Every resource has a URI (similar to web pages)
• REST methods are conceptual and general, but use same names as methods in HTTP:
- GET | PUT | POST | DELETE
JAX-RS
• Annotation-based API for creating RESTful services
• Maps a POJO to a resource
• Part of J2EE
• There are a number of implementations:
- Jersey
- Restlet
- RESTEasy (JBoss project)
• Jersey is Oracle’s reference implementation:
- used by Mule
JAX-RS Annotations
• Specify path of resource (the resource’s URI):
- @Path placed on class or method
• Specify REST method (request type):
- @GET|@PUT|@POST|@DELETE placed on method
• Specify return MIME type (e.g. text/html or application/json):
- @Produces placed on method
• Specify accepted request types:
- @Consumes placed on method
• Specify parameters:
- @PathParam gets parameter from URI
- @QueryParam gets parameter from query string (?x=1&y=2)
- @HeaderParam gets parameter from HTTP header
Creating JAX-RS Resource
• import javax.ws.rs.GET;
• import javax.ws.rs.Path;
• import javax.ws.rs.PathParam;
• import javax.ws.rs.Produces;
• @Path("/")
• public class HelloRestComponent {
• @GET
• @Produces("text/plain")
• @Path("/greeting/{name}")
• public String greet(@PathParam("name") String input)
• {
• return "Hello "+ input;
• }
• }
Creating JAX-RS Resource
http://localhost:8080/{endpointpath}/{classpath}/{methodpath}/{value}
Deploying Jersey Resource
Consuming a RESTful Web Service
JSON Support
• Jersey:
- Specify @Produces/@Consumes (application/json)
• JSON module:
- uses Jackson to support binding JSON data to objects
- JSON to Object transformer:
∙ set returnClass attribute
∙ JSON engine can be configured with jsonConfig attribute
- Object to JSON transformer:
∙ a map of JSON object attributes can be configured using mapper-ref attribute, usually default is enough
• Querying JSON payloads with JSONPath:
- similar to how XPath can query XML documents
Resources
• Using Mule with Web Services documentation
http://www.mulesoft.org/documentation/display/current/Using+Mule+with+Web+
Services
• REST Component Reference documentation
http://www.mulesoft.org/documentation/display/current/REST+Component+Reference
• Creating a JAX-RS resource
• Deploying a JAX-RS resource
• Consuming a REST resource
• JSON capabilities in Mule
What is REST?
• REpresentational State Transfer (REST)
• Architectural style for a well-designed (RESTful) hypertext application
• Design of the Web supports the REST architectural style
• REST applies to client–server architecture:
- resources are found on a server
- client requests a "representation" of a resource’s current state
• Every resource has a URI (similar to web pages)
• REST methods are conceptual and general, but use same names as methods in HTTP:
- GET | PUT | POST | DELETE
JAX-RS
• Annotation-based API for creating RESTful services
• Maps a POJO to a resource
• Part of J2EE
• There are a number of implementations:
- Jersey
- Restlet
- RESTEasy (JBoss project)
• Jersey is Oracle’s reference implementation:
- used by Mule
JAX-RS Annotations
• Specify path of resource (the resource’s URI):
- @Path placed on class or method
• Specify REST method (request type):
- @GET|@PUT|@POST|@DELETE placed on method
• Specify return MIME type (e.g. text/html or application/json):
- @Produces placed on method
• Specify accepted request types:
- @Consumes placed on method
• Specify parameters:
- @PathParam gets parameter from URI
- @QueryParam gets parameter from query string (?x=1&y=2)
- @HeaderParam gets parameter from HTTP header
Creating JAX-RS Resource
• import javax.ws.rs.GET;
• import javax.ws.rs.Path;
• import javax.ws.rs.PathParam;
• import javax.ws.rs.Produces;
• @Path("/")
• public class HelloRestComponent {
• @GET
• @Produces("text/plain")
• @Path("/greeting/{name}")
• public String greet(@PathParam("name") String input)
• {
• return "Hello "+ input;
• }
• }
Creating JAX-RS Resource
http://localhost:8080/{endpointpath}/{classpath}/{methodpath}/{value}
Deploying Jersey Resource
Consuming a RESTful Web Service
JSON Support
• Jersey:
- Specify @Produces/@Consumes (application/json)
• JSON module:
- uses Jackson to support binding JSON data to objects
- JSON to Object transformer:
∙ set returnClass attribute
∙ JSON engine can be configured with jsonConfig attribute
- Object to JSON transformer:
∙ a map of JSON object attributes can be configured using mapper-ref attribute, usually default is enough
• Querying JSON payloads with JSONPath:
- similar to how XPath can query XML documents
Resources
• Using Mule with Web Services documentation
http://www.mulesoft.org/documentation/display/current/Using+Mule+with+Web+
Services
• REST Component Reference documentation
http://www.mulesoft.org/documentation/display/current/REST+Component+Reference
It is excellent blog Thank you porovide importent information and i am searching for same information to save my time
ReplyDeletethis is very for all of us .
ios Online Training Bangalore