Rules of injection
package test; import java.util.HashMap; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @Path("injection/{id}") public class InjectedResource { ObjectMapper mapper = new ObjectMapper(); // Injection onto field @DefaultValue("q") @QueryParam("p") private String p; private int id; private String header; @GET public Response sendResponse() { HashMap<String, Object> hm = new HashMap<String, Object>(); hm.put("p", p); hm.put("id", id); hm.put("header", header); try { return Response.status(Response.Status.OK) .entity(mapper.writeValueAsString(hm)).build(); } catch (JsonProcessingException e) { e.printStackTrace(); return Response.status(Response.Status.BAD_REQUEST).entity("Error") .build(); } } // Injection onto constructor parameter public InjectedResource(@PathParam("id") int id) { this.id = id; } //Header Injection using bean setter method @HeaderParam("X-header") public void setHeader(String header) { this.header = header; } }