Search code examples
restrequesthttp-headersliferay-7request-headers

Liferay 7.2 Rest Service read headers of request


I have Liferay 7.2.

I created a module rest.

I created a method GET

I want to read headers of incoming request. I need to read authentication bearer token. how can i do that?

This is my example code

@GET
@Path("/get-request-headers")
            
public String jsonGetRequestHeaders() throws Exception {

String authtoken = ?????;

return authtoken;
}

Solution

  • I found the solution:

        @GET
        @Path("/get-request-headers")
                    
        public String jsonGetRequestHeaders(
          @HeaderParam("Authorization") String token
        ) throws Exception {
        
        String authtoken = token;
        
        return authtoken;
        }