You are on page 1of 2

009_PARAM ANNOTAIONS

THIS PROJECT IS JUST TO DEMONSTRATE THE PARAM ANNOTATION...& THUS IT DOES NOT
MAKE ANY CHANGES IN THE EXISTING MESSAGE SERVICE PROECT CLASSES..INSTEAD WE
WILL CREATE A NEW CALSS TO TASTE IT

VARIOUS PARAM ANNOTATIONS


1) @PathParam => Path Value
2) @QueryParam => Query parameter in key value format
3) @MatrixParam =? Same as query parameter except the difference of ‘?’ in
case of qyery parame & ‘;’ in case of MatrixParam
4) @HeaderParam => If any additional data is set in header section along with
request then that is retrieved using this
5) @CookieParam => If cookie value is set and we want to use it, the n we can
use it by using this CookieParam
6) @FormParam = > not very oftenely used...
but if an HTML form is submitting its SUBMIT BUTTON
click to a REST API then we can use this annotation to retrieve the data.

1. InjectDemo Class for demonstrating the param annotations is as below:-

package com.module;

import javax.ws.rs.Consumes;
import javax.ws.rs.CookieParam;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/injectDemo")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public class InjectDemoResource{

@GET
@Path("/annotations")
public String GetParamUsingAnnotations(@MatrixParam("param")
String MatrixParam , @HeaderParam("customHeader") String header,
@CookieParam("name") String cookie){
return "Gitesh says : MATRIX PARAM => "+MatrixParam +" &
HEADER VALUE => "+header+" & COOKIE VALUE (if set then) =>
"+cookie;
}

//MATRIX PARAM => very similar to QUERY PARAM... but they use
';' instaed of '?'
//eg: /messages;param=value
//HEADER PARAM => when we send the data in the header section
along with the request..then the header pram is used to handle that
data
// these header values can play a big role when it comes to
authorization and security
//like you can send the session ID and all that things using
these fields
//where customHeader is just an example name of the header and
it will read its value and return us

//COOKIE PARAM => using the cookie value


// if there is any value on the cookie then it will return us
that value...by using cookie name in param
}

2. Following is the POSTMAN Screenshot

You might also like