@ApiResponses({ @ApiResponse(code = 200, response = String.class, message = "authenticated user"), @ApiResponse(code = 403, response = String.class, message = "unauthenticated user") }) @RequestMapping(value = "bookings", method = POST, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> book(@RequestAttribute String customerId) { if (!customers.contains(customerId)) { throw new InvocationException(FORBIDDEN, "No such customer with id " + customerId); } return ResponseEntity.ok(String.format("{\n" + " \"body\": \"Flight booked with id %s for customer %s\"\n" + "}", UUID.randomUUID().toString(), customerId)); }
@ApiResponses({ @ApiResponse(code = 200, response = String.class, message = "authenticated user"), @ApiResponse(code = 403, response = String.class, message = "unauthenticated user"), @ApiResponse(code = 400, response = String.class, message = "insufficient account balance") }) @RequestMapping(value = "payments", method = POST, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> pay(@RequestAttribute String customerId) { if ("anonymous".equals(customerId)) { throw new InvocationException(FORBIDDEN, "No such customer with id " + customerId); } if (balance < 800) { throw new InvocationException(BAD_REQUEST, "Not enough balance in account of customer " + customerId); } balance -= 800; return ResponseEntity.ok(String.format("{\n" + " \"body\": \"Payment made for customer %s and remaining balance is %d\"\n" + "}", customerId, balance)); }
@ApiResponses({ @ApiResponse(code = 200, response = String.class, message = "authenticated user"), @ApiResponse(code = 403, response = String.class, message = "unauthenticated user") }) @RequestMapping(value = "reservations", method = POST, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> reserve(@RequestAttribute String customerId) { if (!customers.contains(customerId)) { throw new InvocationException(FORBIDDEN, "No such customer with id " + customerId); } return ResponseEntity.ok(String.format("{\n" + " \"body\": \"Hotel reserved with id %s for customer %s\"\n" + "}", UUID.randomUUID().toString(), customerId)); }
@GetMapping("/**") public ResponseEntity<Object> supplier( @RequestAttribute("org.springframework.web.servlet.HandlerMapping.pathWithinHandlerMapping") String path, @RequestHeader HttpHeaders headers, @RequestParam(required = false) boolean purge) { Route route = output(path); String channel = route.getChannel(); if (bindings.getOutputs().contains(channel)) { Message<Collection<Object>> polled = poll(channel, route.getKey(), !purge); if (routes.contains(route.getKey()) || !polled.getPayload().isEmpty() || route.getKey() == null) { return convert(polled, headers); } } route = input(path); channel = route.getChannel(); if (!bindings.getInputs().contains(channel)) { return ResponseEntity.notFound().build(); } String body = route.getKey(); body = body.contains("/") ? body.substring(body.lastIndexOf("/") + 1) : body; path = path.replaceAll("/" + body, ""); return string(path, body, headers); }
@GetMapping("/") public String list(@RequestAttribute Connection dbconn, Model model) throws SQLException { String dbname = (String) servletContext.getAttribute("dbname"); model.addAttribute("dbname", dbname); model.addAttribute("proxyHistories", ProxyHistory.getList(dbconn)); return "index"; }
@GetMapping("/proxy-history/{logContext}/{messageRef}") public String detail(@RequestAttribute Connection dbconn, Model model, @PathVariable String logContext, @PathVariable int messageRef) throws SQLException { model.addAttribute("logContext", logContext); model.addAttribute("messageRef", messageRef); ProxyHistory proxyHistory = ProxyHistory.getDetail(dbconn, logContext, messageRef); if (Objects.isNull(proxyHistory)) { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); return "proxy-history-not-found"; } model.addAttribute("proxyHistory", ProxyHistory.getDetail(dbconn, logContext, messageRef)); model.addAttribute("charsetNames", AppContext.getAvailableCharsetNames()); return "proxy-history"; }
@PostMapping("/proxy-history/{logContext}/{messageRef}") public String updateCharset(@RequestAttribute Connection dbconn, Model model, @PathVariable String logContext, @PathVariable int messageRef, @RequestParam String requestCharset, @RequestParam String responseCharset) throws SQLException { ProxyHistory.updateCharset(dbconn, logContext, messageRef, requestCharset, responseCharset); // TODO affected row check return "redirect:/proxy-history/{logContext}/{messageRef}"; }
@ResponseHeaders({@ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class)}) @PostMapping(path = "/responseEntity") @Override public ResponseEntity<Date> responseEntity(InvocationContext c1, @RequestAttribute("date") Date date) { return super.responseEntity(c1, date); }
@ResponseHeaders({@ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class)}) @RequestMapping(path = "/responseEntity", method = RequestMethod.POST) @Override public ResponseEntity<Date> responseEntity(InvocationContext c1, @RequestAttribute("date") Date date) { return super.responseEntity(c1, date); }
@ResponseHeaders({@ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class)}) @RequestMapping(path = "/responseEntity", method = RequestMethod.POST) public ResponseEntity<Date> responseEntity(InvocationContext c1, @RequestAttribute("date") Date date) { HttpHeaders headers = new HttpHeaders(); headers.add("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString()); InvocationContext c2 = ContextUtils.getInvocationContext(); headers.add("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString()); return new ResponseEntity<Date>(date, headers, HttpStatus.ACCEPTED); }
@ResponseHeaders({@ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class)}) @RequestMapping(path = "/responseEntity", method = RequestMethod.PATCH) public ResponseEntity<Date> responseEntityPATCH(InvocationContext c1, @RequestAttribute("date") Date date) { HttpHeaders headers = new HttpHeaders(); headers.add("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString()); InvocationContext c2 = ContextUtils.getInvocationContext(); headers.add("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString()); return new ResponseEntity<Date>(date, headers, HttpStatus.ACCEPTED); }
@Override protected void initParameterAnnotationMgr() { super.initParameterAnnotationMgr(); parameterAnnotationMgr.register(CookieValue.class, new CookieValueAnnotationProcessor()); parameterAnnotationMgr.register(PathVariable.class, new PathVariableAnnotationProcessor()); parameterAnnotationMgr.register(RequestBody.class, new RequestBodyAnnotationProcessor()); parameterAnnotationMgr.register(RequestHeader.class, new RequestHeaderAnnotationProcessor()); parameterAnnotationMgr.register(RequestParam.class, new RequestParamAnnotationProcessor()); parameterAnnotationMgr.register(RequestAttribute.class, new RequestAttributeAnnotationProcessor()); parameterAnnotationMgr.register(RequestPart.class, new RequestPartAnnotationProcessor()); }
@RequestMapping( path = "usingRequestMapping/{targetName}", method = {RequestMethod.POST}, consumes = {"text/plain", "application/*"}, produces = {"text/plain", "application/*"}) public String usingRequestMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word, @RequestAttribute String form) { return String.format("%s %s %s %s %s", srcUser.name, header, targetName, word, form); }
@GetMapping( path = "usingGetMapping/{targetName}", consumes = {"text/plain", "application/*"}, produces = {"text/plain", "application/*"}) public String usingGetMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word, @RequestAttribute String form) { return String.format("%s %s %s %s %s", srcUser.name, header, targetName, word, form); }
@PutMapping( path = "usingPutMapping/{targetName}", consumes = {"text/plain", "application/*"}, produces = {"text/plain", "application/*"}) public String usingPutMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word, @RequestAttribute String form) { return String.format("%s %s %s %s %s", srcUser.name, header, targetName, word, form); }
@PostMapping( path = "usingPostMapping/{targetName}", consumes = {"text/plain", "application/*"}, produces = {"text/plain", "application/*"}) public String usingPostMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word, @RequestAttribute String form) { return String.format("%s %s %s %s %s", srcUser.name, header, targetName, word, form); }
@PatchMapping( path = "usingPatchMapping/{targetName}", consumes = {"text/plain", "application/*"}, produces = {"text/plain", "application/*"}) public String usingPatchMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word, @RequestAttribute String form) { return String.format("%s %s %s %s %s", srcUser.name, header, targetName, word, form); }
@DeleteMapping( path = "usingDeleteMapping/{targetName}", consumes = {"text/plain", "application/*"}, produces = {"text/plain", "application/*"}) public String usingDeleteMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word, @RequestAttribute String form) { return String.format("%s %s %s %s %s", srcUser.name, header, targetName, word, form); }
@RequestMapping(value = "/eliminar", method = RequestMethod.DELETE) public String eliminar(@RequestAttribute("Valoracion") Valoracion valoracion) { FachadaIntegracion<Valoracion> fachadaIntegracion = FachadaIntegracion.newInstance(Valoracion.class); fachadaIntegracion.baja(valoracion.getId()); return "valoracion-eliminada"; }
@RequestMapping(value = "/usableResource", method = POST, consumes = APPLICATION_FORM_URLENCODED_VALUE) public ResponseEntity<String> postUsableResource( @RequestAttribute(name = "hello") String who, @RequestAttribute(name = "response") String response) { return ResponseEntity.ok("hello " + who + ", with response " + response); }
@ApiResponses({ @ApiResponse(code = 200, response = String.class, message = "authenticated user"), @ApiResponse(code = 403, response = String.class, message = "unauthenticated user") }) @RequestMapping(value = "bookings", method = PUT, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> cancel(@RequestAttribute String customerId) { if (!customers.contains(customerId)) { throw new InvocationException(FORBIDDEN, "No such customer with id " + customerId); } return ResponseEntity.ok(String.format("Flight booking cancelled with id %s for customer %s", UUID.randomUUID().toString(), customerId)); }
@ApiResponses({ @ApiResponse(code = 200, response = String.class, message = "authenticated user"), @ApiResponse(code = 403, response = String.class, message = "unauthenticated user") }) @RequestMapping(value = "payments", method = PUT, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> refund(@RequestAttribute String customerId) { if ("anonymous".equals(customerId)) { throw new InvocationException(FORBIDDEN, "No such customer with id " + customerId); } balance += 800; return ResponseEntity.ok(String.format("Payment refunded for customer %s and remaining balance is %d", customerId, balance)); }
@ApiResponses({ @ApiResponse(code = 200, response = String.class, message = "authenticated user"), @ApiResponse(code = 403, response = String.class, message = "unauthenticated user") }) @RequestMapping(value = "reservations", method = PUT, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> cancel(@RequestAttribute String customerId) { if (!customers.contains(customerId)) { throw new InvocationException(FORBIDDEN, "No such customer with id " + customerId); } return ResponseEntity.ok(String.format("Hotel reservation cancelled with id %s for customer %s", UUID.randomUUID().toString(), customerId)); }
@ApiResponses({ @ApiResponse(code = 200, response = String.class, message = "authenticated user"), @ApiResponse(code = 403, response = String.class, message = "unauthenticated user") }) @RequestMapping(value = "rentals", method = POST, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> rent(@RequestAttribute String customerId) { log.info("Received car rental request from customer {}", customerId); if (!customers.contains(customerId)) { log.info("No such customer {}", customerId); throw new InvocationException(FORBIDDEN, "No such customer with id " + customerId); } if ("snail".equals(customerId)) { try { log.info("Encountered extremely slow customer {}", customerId); int timeout = delay; delay = 0; TimeUnit.SECONDS.sleep(timeout); log.info("Finally served the extremely slow customer {}", customerId); } catch (InterruptedException e) { return new ResponseEntity<>("Interrupted", INTERNAL_SERVER_ERROR); } } return ResponseEntity.ok(String.format("{\n" + " \"body\": \"Car rented with id %s for customer %s\"\n" + "}", UUID.randomUUID().toString(), customerId)); }
@ApiResponses({ @ApiResponse(code = 200, response = String.class, message = "authenticated user"), @ApiResponse(code = 403, response = String.class, message = "unauthenticated user") }) @RequestMapping(value = "rentals", method = PUT, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = TEXT_PLAIN_VALUE) public ResponseEntity<String> cancel(@RequestAttribute String customerId) { if (!customers.contains(customerId)) { throw new InvocationException(FORBIDDEN, "No such customer with id " + customerId); } return ResponseEntity.ok(String.format("Car rental cancelled with id %s for customer %s", UUID.randomUUID().toString(), customerId)); }
@GetMapping public String logoutPrompt(@RequestAttribute(name = "redirectUri", required = false) URI redirectUri, @RequestAttribute(name = "state", required = false) State state, Model model) { model.addAttribute("redirectUri", redirectUri); model.addAttribute("state", state); return "logout"; }
@RequestMapping("/logout") @Authorize public String logout(@RequestAttribute(USER_CONTEXT_KEY) UserContext userContext, HttpServletResponse response) throws UserApiException { LogoutReq logoutReq = new LogoutReq(); logoutReq.setAccessToken(userContext.getAccessToken()); accountApi.logout(logoutReq); userContextProcessor.destroy(userContext, response); return "redirect:/"; }
@GetMapping(path = "/**") @ResponseBody public Object get( @RequestAttribute(required = false, name = "org.springframework.cloud.function.web.flux.constants.WebRequestConstants.function") Function<Flux<?>, Flux<?>> function, @RequestAttribute(required = false, name = "org.springframework.cloud.function.web.flux.constants.WebRequestConstants.supplier") Supplier<Flux<?>> supplier, @RequestAttribute(required = false, name = "org.springframework.cloud.function.web.flux.constants.WebRequestConstants.argument") String argument) { if (function != null) { return value(function, argument); } return supplier(supplier); }
@PostMapping(path = "/uploadWithoutAnnotation", produces = MediaType.TEXT_PLAIN_VALUE) public String fileUploadWithoutAnnotation(MultipartFile file1, MultipartFile file2, @RequestAttribute("name") String name) { return super.fileUpload(file1, file2, name); }
@PostMapping(path = "/addDate") @Override public Date addDate(@RequestAttribute("date") Date date, @QueryParam("seconds") long seconds) { return super.addDate(date, seconds); }
@PostMapping(path = "/add") @Override public int add(@RequestAttribute("a") int a, @RequestAttribute("b") int b) { return super.add(a, b); }
@RequestMapping(path = "/uploadWithoutAnnotation", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) public String fileUploadWithoutAnnotation(MultipartFile file1, MultipartFile file2, @RequestAttribute("name") String name) { return super.fileUpload(file1, file2, name); }
@RequestMapping(path = "/addDate", method = RequestMethod.POST) @Override public Date addDate(@RequestAttribute("date") Date date, @QueryParam("seconds") long seconds) { return super.addDate(date, seconds); }
@RequestMapping(path = "/add", method = RequestMethod.POST) @Override public int add(@RequestAttribute("a") int a, @RequestAttribute("b") int b) { return super.add(a, b); }
@RequestMapping(path = "/addDate", method = RequestMethod.POST) public Date addDate(@RequestAttribute("date") Date date, @QueryParam("seconds") long seconds) { return new Date(date.getTime() + seconds * 1000); }
@RequestMapping(path = "/add", method = RequestMethod.POST) public int add(@RequestAttribute("a") int a, @RequestAttribute("b") int b) { return a + b; }
@Override protected String getAnnotationParameterName(Object annotation) { return ((RequestAttribute) annotation).name(); }
@RequestMapping(value = "/faultyResource", method = POST, consumes = APPLICATION_FORM_URLENCODED_VALUE) public ResponseEntity<String> postFaultyResource(@RequestParam(name = "foo") String foo, @RequestAttribute(name = "hello") String hello) { throw new RuntimeException("no such resource"); }