SlideShare a Scribd company logo
1 of 15
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

What's hot

Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scalab0ris_1
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web ServiceHoan Vu Tran
 
Designing a RESTful web service
Designing a RESTful web serviceDesigning a RESTful web service
Designing a RESTful web serviceFilip Blondeel
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 
Rest presentation
Rest  presentationRest  presentation
Rest presentationsrividhyau
 
WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0Jeffrey West
 
Restful webservices
Restful webservicesRestful webservices
Restful webservicesKong King
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection apiMatthieu Aubry
 
RESTful web
RESTful webRESTful web
RESTful webAlvin Qi
 
Json to hive_schema_generator
Json to hive_schema_generatorJson to hive_schema_generator
Json to hive_schema_generatorPayal Jain
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India
 

What's hot (20)

Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
So various polymorphism in Scala
So various polymorphism in ScalaSo various polymorphism in Scala
So various polymorphism in Scala
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
REST & RESTful Web Service
REST & RESTful Web ServiceREST & RESTful Web Service
REST & RESTful Web Service
 
Designing a RESTful web service
Designing a RESTful web serviceDesigning a RESTful web service
Designing a RESTful web service
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
Introduction to JAX-RS
Introduction to JAX-RSIntroduction to JAX-RS
Introduction to JAX-RS
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0WebLogic Developer Webcast 1: JPA 2.0
WebLogic Developer Webcast 1: JPA 2.0
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 
RESTful web
RESTful webRESTful web
RESTful web
 
Json to hive_schema_generator
Json to hive_schema_generatorJson to hive_schema_generator
Json to hive_schema_generator
 
Rest web services
Rest web servicesRest web services
Rest web services
 
L18 REST API Design
L18 REST API DesignL18 REST API Design
L18 REST API Design
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
 
Rest and Rails
Rest and RailsRest and Rails
Rest and Rails
 

Viewers also liked

Survey of restful web services frameworks
Survey of restful web services frameworksSurvey of restful web services frameworks
Survey of restful web services frameworksVijay Prasad Gupta
 
็Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...
็Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...็Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...
็Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...IMC Institute
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RSArun Gupta
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondSam Brannen
 
IoT and WoT (Internet of Things and Web of Things)
IoT and WoT (Internet of Things and Web of Things)IoT and WoT (Internet of Things and Web of Things)
IoT and WoT (Internet of Things and Web of Things)Jonathan Jeon
 
Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Pece Nikolovski
 

Viewers also liked (6)

Survey of restful web services frameworks
Survey of restful web services frameworksSurvey of restful web services frameworks
Survey of restful web services frameworks
 
็Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...
็Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...็Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...
็Hand-on Exercise: Java Web Services using Eclipse + Tomcat & NetBeans + Glas...
 
RESTful Web services using JAX-RS
RESTful Web services using JAX-RSRESTful Web services using JAX-RS
RESTful Web services using JAX-RS
 
JUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyondJUnit 5 - from Lambda to Alpha and beyond
JUnit 5 - from Lambda to Alpha and beyond
 
IoT and WoT (Internet of Things and Web of Things)
IoT and WoT (Internet of Things and Web of Things)IoT and WoT (Internet of Things and Web of Things)
IoT and WoT (Internet of Things and Web of Things)
 
Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0
 

Similar to Developing RESTful WebServices using Jersey

JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuseejlp12
 
CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!Dan Allen
 
Jax ws
Jax wsJax ws
Jax wsF K
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actionsAren Zomorodian
 
03 form-data
03 form-data03 form-data
03 form-datasnopteck
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface pptTaha Malampatti
 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all detailsgogijoshiajmer
 
Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Saltmarch Media
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
 
Java Technology
Java TechnologyJava Technology
Java Technologyifnu bima
 
Rest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerRest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerKumaraswamy M
 
JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup Sagara Gunathunga
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)Talha Ocakçı
 

Similar to Developing RESTful WebServices using Jersey (20)

JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuse
 
CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!CDI, Seam & RESTEasy: You haven't seen REST yet!
CDI, Seam & RESTEasy: You haven't seen REST yet!
 
Ws rest
Ws restWs rest
Ws rest
 
Jax ws
Jax wsJax ws
Jax ws
 
Web Technologies - forms and actions
Web Technologies -  forms and actionsWeb Technologies -  forms and actions
Web Technologies - forms and actions
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
03 form-data
03 form-data03 form-data
03 form-data
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Jersey
JerseyJersey
Jersey
 
Ppt on web development and this has all details
Ppt on web development and this has all detailsPpt on web development and this has all details
Ppt on web development and this has all details
 
Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0Building RESTful Services with WCF 4.0
Building RESTful Services with WCF 4.0
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
Java Technology
Java TechnologyJava Technology
Java Technology
 
Rest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swaggerRest with java (jax rs) and jersey and swagger
Rest with java (jax rs) and jersey and swagger
 
JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup JavaEE and RESTful development - WSO2 Colombo Meetup
JavaEE and RESTful development - WSO2 Colombo Meetup
 
Android and REST
Android and RESTAndroid and REST
Android and REST
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 

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/