【发布时间】:2019-11-20 19:40:35
【问题描述】:
我希望在spring-boot 中为我的 webhook 编写 Rest Controller 代码。我正在使用简单的操作创建一个 google 操作。
- 这是一个样板:https://github.com/actions-on-google/dialogflow-webhook-boilerplate-java/blob/master/src/main/java/com/example/ActionsServlet.java。
-
我也想这样做,只是在
spring-boot。我想将 JSON 正文作为输入进行操作,但不知道该怎么做。@RestController public class indexController extends HttpServlet { @Autowired private App actionsApp; //handle all incoming requests to URI "/" // @GetMapping("/") // public String sayHello() { // return "Hi there, this is a Spring Boot application";} private static final Logger LOG = LoggerFactory.getLogger(MyActionsApp.class); //handles post requests at URI /googleservice @PostMapping(path = "/", consumes = "application/json", produces = "application/json") public ResponseEntity<String> getPost(@RequestBody String payload, @RequestHeader String header, HttpServletResponse response) throws IOException { //Not sure what to do here. System.out.println(jsonData); return ResponseEntity.ok(HttpStatus.OK); try { //writeResponse(response, jsonResponse); //String med request body og object that has all request header entries String jsonResponse = actionsApp.handleRequest(body, listAllHeaders(header)).get(); return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED); } catch ( InterruptedException e) { System.out.println("Something wrong happened, interupted"); } catch ( ExecutionException e) { System.out.println("Something wrong happened, execution error"); }}
【问题讨论】:
-
对我来说,你想要达到的目标并不是很清楚。
标签: java azure spring-boot docker google-home