Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
RESTful Web services using Java
About Web service


• What is Web service?

• What is WSDL?

• What is SOAP?
WSDL Structure
<definitions>
   <types>
    definition of types........
   </types>
   <message>
    definition of a message....
   </message>
   <portType>
    definition of a port.......
   </portType>
   <binding>
    definition of a binding....
   </binding>
   </definitions>
SOAP Sample
POST /StockQuote HTTP/1.1
SOAPAction: "Some-URI“

<soapenv:Envelope xmlns:soapenv="......">
 <soapenv:Header/>
 <soapenv:Body>
   <it:GetEmployeeName>
     <it:ID>4118830901957010</it:ID>
   </it:GetEmployeeName>
 </soapenv:Body>
</soapenv:Envelope>
Have you ever wondered why
here is so much overhead in
designing a simple web service
like ‘GetEmployeeName’ using
SOAP?
REpresentational State Transfer
                (REST)

• REpresentational State Transfer

• What is JAX-RS?

• What is Jersey?
REST Concepts
• Resources (nouns)
  – Identified by a URI, For example:
    http://www.parts-depot.com/parts

• Uniform interface (verbs)
   – Small fixed set:
   Create, Read, Update, Delete

• State Representations
– data and state transferred between client and server
   XML, JSON, Atom, XHTML, ...
JAX-RS Introduction
• Set of Java APIs for development of
  web services built according to the REST
  principals
• Annotations
• Jersey is the open source , production quality,
  JAX-RS (JSR 311) Reference Implementation
  for building RESTful Web services.
• Jersey Homepage
  https://jersey.dev.java.net/
Use Standard Methods
Sample RESTful Web service
@Path("/helloworld/{name}")
public class HelloworldResource {
  @Context
  private UriInfo context;

    /** Creates a new instance of HelloworldResource */
    public HelloworldResource() {
    }

    /**
     * Retrieves representation of an instance of jaxrstest.HelloworldResource
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    public String sayHello(@PathParam("name") String name,
                           @DefaultValue("HR") @QueryParam("dep") String department) {
       return "Hi "+name+" Welcome to "+ department +" department";
    }

    @GET
    @Path("/sunresource")
    public String testSubResource(){
      return "This is from Sub Resource";
    }

    /**
     * PUT method for updating or creating an instance of HelloworldResource
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("text/plain")
    public void putText(String content) {
       System.out.println("======"+content+"=====");
    }

}
Demo
HTTP Example
Examples on the web
• Google AJAX Search API
  – http://code.google.com/apis/ajaxsearch/
• Amazon S3
  – http://aws.amazon.com/s3
• Services exposing Atom Publishing Protocol or GData
  – i.e. Google apps like Google Calendar
• Accidentally RESTful
  – Flickr, Del.icio.us API
REST Framework alternatives
• Restlet (opensource client and server API)
  – http://www.restlet.org/
• CXF
  – HttpBinding
  – JAX-WS Provider/Dispatch API
• Axis2
  – HttpBinding (WSDL 2.0)
• JAX-RS
For More Information
• BOF-5613 - Jersey: RESTful Web Services Made Easy
• Official JSR Page
  > http://jcp.org/en/jsr/detail?id=311
• JSR Project
  > http://jsr311.dev.java.net/
• Reference Implementation
  > http://jersey.dev.java.net/
• Marc's Blog
  > http://weblogs.java.net/blog/mhadley/
• Paul's Blog
  > http://blogs.sun.com/sandoz/
• Jakub's Blog
  > http://blogs.sun.com/japod/

More Related Content

Developing RESTful WebServices using Jersey

  • 1. RESTful Web services using Java
  • 2. About Web service • What is Web service? • What is WSDL? • What is SOAP?
  • 3. WSDL Structure <definitions> <types> definition of types........ </types> <message> definition of a message.... </message> <portType> definition of a port....... </portType> <binding> definition of a binding.... </binding> </definitions>
  • 4. SOAP Sample POST /StockQuote HTTP/1.1 SOAPAction: "Some-URI“ <soapenv:Envelope xmlns:soapenv="......"> <soapenv:Header/> <soapenv:Body> <it:GetEmployeeName> <it:ID>4118830901957010</it:ID> </it:GetEmployeeName> </soapenv:Body> </soapenv:Envelope>
  • 5. Have you ever wondered why here is so much overhead in designing a simple web service like ‘GetEmployeeName’ using SOAP?
  • 6. REpresentational State Transfer (REST) • REpresentational State Transfer • What is JAX-RS? • What is Jersey?
  • 7. REST Concepts • Resources (nouns) – Identified by a URI, For example: http://www.parts-depot.com/parts • Uniform interface (verbs) – Small fixed set: Create, Read, Update, Delete • State Representations – data and state transferred between client and server XML, JSON, Atom, XHTML, ...
  • 8. JAX-RS Introduction • Set of Java APIs for development of web services built according to the REST principals • Annotations • Jersey is the open source , production quality, JAX-RS (JSR 311) Reference Implementation for building RESTful Web services. • Jersey Homepage https://jersey.dev.java.net/
  • 10. Sample RESTful Web service @Path("/helloworld/{name}") public class HelloworldResource { @Context private UriInfo context; /** Creates a new instance of HelloworldResource */ public HelloworldResource() { } /** * Retrieves representation of an instance of jaxrstest.HelloworldResource * @return an instance of java.lang.String */ @GET @Produces("text/plain") public String sayHello(@PathParam("name") String name, @DefaultValue("HR") @QueryParam("dep") String department) { return "Hi "+name+" Welcome to "+ department +" department"; } @GET @Path("/sunresource") public String testSubResource(){ return "This is from Sub Resource"; } /** * PUT method for updating or creating an instance of HelloworldResource * @param content representation for the resource * @return an HTTP response with content of the updated or created resource. */ @PUT @Consumes("text/plain") public void putText(String content) { System.out.println("======"+content+"====="); } }
  • 11. Demo
  • 13. Examples on the web • Google AJAX Search API – http://code.google.com/apis/ajaxsearch/ • Amazon S3 – http://aws.amazon.com/s3 • Services exposing Atom Publishing Protocol or GData – i.e. Google apps like Google Calendar • Accidentally RESTful – Flickr, Del.icio.us API
  • 14. REST Framework alternatives • Restlet (opensource client and server API) – http://www.restlet.org/ • CXF – HttpBinding – JAX-WS Provider/Dispatch API • Axis2 – HttpBinding (WSDL 2.0) • JAX-RS
  • 15. For More Information • BOF-5613 - Jersey: RESTful Web Services Made Easy • Official JSR Page > http://jcp.org/en/jsr/detail?id=311 • JSR Project > http://jsr311.dev.java.net/ • Reference Implementation > http://jersey.dev.java.net/ • Marc's Blog > http://weblogs.java.net/blog/mhadley/ • Paul's Blog > http://blogs.sun.com/sandoz/ • Jakub's Blog > http://blogs.sun.com/japod/