get Header in jersey from a GET request


From a js page (in angular) I call a REST request, GET method, were I would to pass an header, this is the function that I call from the REST request:

        allstaffworking: function(_getstaff){
            var currentToken = _GetToken();

            var Headers = {
                token: currentToken.stringtoken


            if (currentToken !== null) {
                        method : 'GET',  
                        headers: Headers,
                        url : REST_URL+'staff/working'
                    }).then(function successCallback(response) {  
                    }, function errorCallback(response) {  
               }  else {
                console.log("NON SEI LOGGATO!!!");

Whithout headers: Headers, it works, but I want to pass an important json string: {"idtokenStaff":11,"staffType":{"idstaffType":2,"type":"Dipendente"},"tokenStaff":"88d08m8ve4n8i71k796vajkd01"} in the Headers. I don’t know How I can take this string in Jersey. This is java file in with I have the REST method:

public class StaffController {  

BaseDao sDao =  new StaffDaoImpl();
StaffDao stfDao =  new StaffDaoImpl();
TokenStaffDao tsDao = new TokenStaffDaoImpl();
TokenStaff ts = new TokenStaff();

 public List<Staff> getStaff()  

  List<Staff> listOfStaff=sDao.getAll(Staff.class);
  return listOfStaff;  

    public List<Staff> getWStaff(@HeaderParam("token") String token) throws JSONException  

        JSONObject jsonObj = new JSONObject(token);

    Boolean id = tsDao.getExistence(jsonObj.getInt("idtokenStaff"));
    if (id){
        List<Staff> listOfWStaff=stfDao.getAllW();
        return listOfWStaff;  
        return null;

Taking header from: @HeaderParam("token") String token. How Can I take the element of the header?


A bit late to answer this, but you can also use @Context annotation to get httpheaders.

public List<Staff> getWStaff(@Context HttpHeaders httpHeaders) {
   String token = httpHeaders.getHeaderString("token");
    JSONObject jsonObj = new JSONObject(token);

Answered By – priteshbaviskar

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.