Restful web service is built on top of HTTP protocol. We can say Restful web service is a type of Servlet. I am saying Restful web service is built on top of HTTP protocol because it support all HTTP operations. Initially this was porposed by Roy Fielding who was the main driver of HTTP.
The supported operations of a Restful web service are descrive below:
You can find number of implementations of JAX-RS. One most popular implementation is RestEasy.This is developed by JBoss community. The RestEasy is comes in two flaver, If you are using JBoss AS 7 then there is no need to add any distribution file for RestEasy. If you are using older version of JBoss, then you have to confugure the RestEasy.
For older version of JBoss, developer have to download a jar file named "resteasy-jaxrs-2.3.0.GA". You can foud this in <>.
Configuration:
@PUT - Indicates that the annotated method responds to HTTP PUT requests
When using this with the Resteasy client framework, you must put your @*Param annotations on either fields or getter methods.
@FormParam - Binds the value(s) of a form parameter contained within a request entity body to a resource method parameter. Values are URL decoded unless this is disabled using the
The type
If the type is not one of those listed in 4 above then the first value (lexically) of the parameter is used.
Note that, whilst the annotation target permits use on fields and methods, this annotation is only required to be supported on resource method parameters.
The supported operations of a Restful web service are descrive below:
- GET
- POST
- DELETE
- PUT
You can find number of implementations of JAX-RS. One most popular implementation is RestEasy.This is developed by JBoss community. The RestEasy is comes in two flaver, If you are using JBoss AS 7 then there is no need to add any distribution file for RestEasy. If you are using older version of JBoss, then you have to confugure the RestEasy.
For older version of JBoss, developer have to download a jar file named "resteasy-jaxrs-2.3.0.GA". You can foud this in <
Configuration:
- After download extract the file and copy all jar files from lib directory to your application.
- Modify our Web configuration file(web.xml) file. Add the following lines:
- Annotate your POGO for Restful web service.
- Deploy the application in JBoss AS.
Resteasy Web Service Annotations:
@Path - Identifies the URI path that a resource class or class method will serve requests for. Paths are relative. For an annotated class the base URI is the application path, see
ApplicationPath
. For an annotated method the base URI is the effective URI of the containing class. For the purposes of absolutizing a path against the base URI , a leading '/' in a path is ignored and base URIs are treated as if they ended in '/'
@GET - Indicates that the annotated method responds to HTTP GET requests.
@POST - Indicates that the annotated method responds to HTTP POST requests.
@DELETE - Indicates that the annotated method responds to HTTP DELETE requests
@PUT - Indicates that the annotated method responds to HTTP PUT requests
@Form - This can be used as a value object for incoming/outgoing request/responses. You can re-use @*Param annotations on fields/methods of the parameter to unmarshall from the request or marshall to the response depending if you're using server-side JAX-RS or the Resteasy client framework
When using this on the server side, you must put your @*Param annotations on either fields or setter methods. When using this with the Resteasy client framework, you must put your @*Param annotations on either fields or getter methods.
@FormParam - Binds the value(s) of a form parameter contained within a request entity body to a resource method parameter. Values are URL decoded unless this is disabled using the
Encoded
annotation. A default value can be specified using the DefaultValue
annotation. If the request entity body is absent or is an unsupported media type, the default value is used.The type
T
of the annotated parameter must either: - Be a primitive type
- Have a constructor that accepts a single
String
argument - Have a static method named
valueOf
orfromString
that accepts a singleString
argument (see, for example,Integer.valueOf(String)
) - Be
List
,Set
orSortedSet
, whereT
satisfies 2 or 3 above. The resulting collection is read-only.
If the type is not one of those listed in 4 above then the first value (lexically) of the parameter is used.
Note that, whilst the annotation target permits use on fields and methods, this annotation is only required to be supported on resource method parameters.