0

I have a project where we call a GET method from Java Script : the method called is below :

public
@ResponseBody
Map run( @RequestParam Map map, HttpServletRequest request,   HttpServletResponse response) throws Exception {

}

Now I am writing a Micro service to do the work which is done inside the above method . And the requirement is this method will call the micro-service .The only thing I am stuck with is passing the (HttpServletRequest request, HttpServletResponse response) to the method in micro-service I am calling as they have some data in there which will be used.

My method definition in micro-service looks like :

@POST
@Path("/myPostCall")
public String myPostCall(Map map,HttpServletRequest request,       HttpServletResponse response) throws Exception{
}

Now I am trying to call this by

 RestTemplate abc = new RestTemplate();
abc.postForObject("http://localhost:8008/report/run", report1, String.class);

It gives me 422 error . But If I remove the request,response parameters in micro-service method . it runs good . But I need them too . Because they have data in it . Is there something out of my understanding .

Abhishek Bhandari
  • 585
  • 1
  • 4
  • 14

1 Answers1

0

You can use them as private variables in class as :

@Context 
private HttpServletRequest request;
@Context 
private HttpServletResponse response;

OR

@POST
@Path("/myPostCall")
public String myPostCall(..., @Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
    //do some stuff
}
OO7
  • 2,719
  • 1
  • 16
  • 30