0

I pass a reference third-party system and this system return me some parameters but I not understand What are the parameters. It is my controller with POST method

@Controller
@RequestMapping("/success")
public class SuccessController {



     @RequestMapping(value = "/eventlogs/logs", method = RequestMethod.POST)
        public String logs(@RequestParam("Approved") String json) {
            System.out.println("Received POST request:" + json);

            return "success";
        }
    }

But I not understand how type parameters I get/ I my example I wait parameter "Approved" and type String
But How can I get raw response in my method? for example like this

@Controller
@RequestMapping("/success")
public class SuccessController {

        @RequestMapping(value = "/eventlogs/logs", method = RequestMethod.POST)
        public String logs(HttpResponse response) {
    System.out.println("Received POST request:" + response.get("p1"));
    System.out.println("Received POST request:" + response.get("p2"));
    System.out.println("Received POST request:" + response.get("p3"));
    ....
            return "success";
        }
    }

I know that third-party system set to my method many parameters and I do not want write something like

public String logs(@RequestParam("p1") String p1, @RequestParam("p2") int p2, @RequestParam("p3") boolean p3 .......)

I want something like JavaEE servlet's method

@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
            throws ServletException, IOException {
 resp.get(......)
        super.doPost(req, resp);
    }
user5620472
  • 2,722
  • 8
  • 44
  • 97

1 Answers1

1

You can set the HttpServletRequest (not HttpServletResponse) as parameter:

@Controller
@RequestMapping("/success")
public class SuccessController {

    @RequestMapping(value = "/eventlogs/logs", method = RequestMethod.POST)
    public String logs(HttpServletRequest req) {
        System.out.println("Received POST request:" + req.getParameter("..."));
....
        return "success";
    }
}

To know all the parameters sent in a request, use HttpServletRequest#getParameterNames or HttpServletRequest#getParameterMap to evaluate each parameter and its value or values.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • A better plan is to not use HttpServletRequest and use org.springframework.web.context.request.WebRequest instead so you are not tied to the native servlet/portlet API. – DwB Feb 24 '16 at 05:40
  • @DwB after some research I've found something better and closed this question as a duplicate. Sadly, since this is the accepted answer I can't delete it. – Luiggi Mendoza Feb 24 '16 at 05:45