Have looked at other related posts but nothing seemed to work.
Basically I'm trying to figure out how to pass data to my restful spring-boot app.
Here is the curl command I'm using:
$ curl -iX POST -H 'Content-Type: application/json' -d @args.json http://localhost:8080/myapp/dummyApi With args.json contains:
file: args.json:
{ "arg1": "hello", "arg2": 10, "arg3": { "a": "1", "b": "2" } } The api is defined in MyController.java as such:
file: MyController.java
@RestController @RequestMapping("/myapp") public class MyController { //... static class DummyRet { private String foo; public DummyRet(String f) { foo = f; } public String getFoo() { return foo; } public void setFoo(String foo) { this.foo = foo; } } @RequestMapping(value="/dummyApi", method=RequestMethod.POST) public DummyRet dummyApi(@RequestParam(value = "arg1", required = false, defaultValue = "") String arg1, @RequestParam(value = "arg2", required = false, defaultValue = "") Long arg2, @RequestParam(value = "arg3", required = false) Map<String, String> arg3) { LOGGER.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); LOGGER.info("Arguments received:"); LOGGER.info("arg1: " + arg1); LOGGER.info("arg2: " + arg2); LOGGER.info("arg3: " + arg3); LOGGER.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); return new DummyRet("foo"); } //... } The return of the curl command is 200 success (since non of the arguments is required) but the values of args are not reaching over to dummyApi method
$ curl -iX POST -H 'Content-Type: application/json' -d @args.json http://localhost:8080/myapp/dummyApi HTTP/1.1 200 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Sun, 04 Jun 2017 15:37:42 GMT {"foo":"foo"} The server console looks like this:
2017-06-04 18:17:56.818 DEBUG 32258 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/myapp/dummyApi] 2017-06-04 18:17:56.818 DEBUG 32258 --- [nio-8080-exec-7] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /myapp/dummyApi 2017-06-04 18:17:56.818 DEBUG 32258 --- [nio-8080-exec-7] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public com.xx.controllers.MyController$DummyRet com.xx.controllers.MyController.dummyApi(java.lang.String,java.lang.Long,java.util.Map<java.lang.String, java.lang.String>)] 2017-06-04 18:17:56.819 INFO 32258 --- [nio-8080-exec-7] c.p.controllers.MyController : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2017-06-04 18:17:56.819 INFO 32258 --- [nio-8080-exec-7] c.p.controllers.MyController : Arguments received: 2017-06-04 18:17:56.819 INFO 32258 --- [nio-8080-exec-7] c.p.controllers.MyController : arg1: 2017-06-04 18:17:56.819 INFO 32258 --- [nio-8080-exec-7] c.p.controllers.MyController : arg2: null 2017-06-04 18:17:56.819 INFO 32258 --- [nio-8080-exec-7] c.p.controllers.MyController : arg3: null 2017-06-04 18:17:56.819 INFO 32258 --- [nio-8080-exec-7] c.p.controllers.MyController : >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2017-06-04 18:17:56.819 DEBUG 32258 --- [nio-8080-exec-7] m.m.a.RequestResponseBodyMethodProcessor : Written [com.xx.controllers.MyController$DummyRet@c35d46f] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@301ec38b] 2017-06-04 18:17:56.819 DEBUG 32258 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling 2017-06-04 18:17:56.819 DEBUG 32258 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Successfully completed request I hope I haven't left out any of the important details, but please let me know if anything is missing.