diff --git a/src/adservice-v2/src/main/java/org/daocloud/springcloud/adservice/controller/HelloWorld.java b/src/adservice-v2/src/main/java/org/daocloud/springcloud/adservice/controller/HelloWorld.java index 821ace3bee..4f07435dec 100644 --- a/src/adservice-v2/src/main/java/org/daocloud/springcloud/adservice/controller/HelloWorld.java +++ b/src/adservice-v2/src/main/java/org/daocloud/springcloud/adservice/controller/HelloWorld.java @@ -36,29 +36,29 @@ public HelloWorld(Environment environment) { } @RequestMapping("/") - public Mono helloWorld(){ + public Mono helloWorld() { return Mono.just("adservice-springcloud: hello world!"); } @RequestMapping("/test1") - public Mono test1(){ + public Mono test1() { return Mono.just("This is a test 1 API."); } @RequestMapping("/test2") - public Mono test2(){ + public Mono test2() { return Mono.just("This is a test 2 API."); } @GetMapping("/dynamic-config") - public Mono dynamicConfig(){ + public Mono dynamicConfig() { return Mono.just(config); } @RequestMapping("/timeout/{timeout}") - public Mono helloWorld(@PathVariable long timeout) throws InterruptedException{ + public Mono helloWorld(@PathVariable long timeout) throws InterruptedException { Thread.sleep(timeout); - return Mono.just("timeout:"+timeout); + return Mono.just("timeout:" + timeout); } // @PostMapping("/method") @@ -67,8 +67,8 @@ public Mono helloWorld(@PathVariable long timeout) throws InterruptedExc // } @RequestMapping("/method") - public Mono method(ServerHttpRequest request){ - return Mono.just("method:"+request.getMethodValue()); + public Mono method(ServerHttpRequest request) { + return Mono.just("method:" + request.getMethodValue()); } @RequestMapping("/hostname") @@ -76,42 +76,42 @@ public Mono hostname() throws UnknownHostException { InetAddress localHost = InetAddress.getLocalHost(); String hostName = localHost.getHostName(); - return Mono.just("hostname:"+hostName); + return Mono.just("hostname:" + hostName); } @RequestMapping("/ip") public Mono ip() throws UnknownHostException { InetAddress localHost = InetAddress.getLocalHost(); String address = localHost.getHostAddress(); - return Mono.just("ip address:"+address); + return Mono.just("ip address:" + address); } - @RequestMapping({"/path/**","/path**"}) - public Mono path(ServerHttpRequest request){ - return Mono.just("path:"+ request.getPath()); + @RequestMapping({"/path/**", "/path**"}) + public Mono path(ServerHttpRequest request) { + return Mono.just("path:" + request.getPath()); } @RequestMapping("/set-retry-count/{limit}") - public Mono retryCount(@PathVariable long limit){ + public Mono retryCount(@PathVariable long limit) { HelloWorld.limit = limit; count = new AtomicLong(); - return Mono.just("retry-count-limit:"+limit); + return Mono.just("retry-count-limit:" + limit); } @RequestMapping("/retry") - public Mono retry(ServerHttpResponse response){ - if (limit <1 || count.addAndGet(1) % limit ==0){ + public Mono retry(ServerHttpResponse response) { + if (limit < 1 || count.addAndGet(1) % limit == 0) { count = new AtomicLong(); - return Mono.just("retry:"+"success"); + return Mono.just("retry:" + "success"); } response.setStatusCode(HttpStatus.SERVICE_UNAVAILABLE); - return Mono.just("retry fai,count is:"+ count.get()); + return Mono.just("retry fai,count is:" + count.get()); } @RequestMapping("/request-header") - public Mono>> requestHeader(ServerHttpRequest request, @RequestParam(required = false) List header){ - if (CollectionUtils.isEmpty(header)){ + public Mono>> requestHeader(ServerHttpRequest request, @RequestParam(required = false) List header) { + if (CollectionUtils.isEmpty(header)) { return Mono.empty(); } Map> headers = new HashMap<>(); @@ -122,8 +122,8 @@ public Mono>> requestHeader(ServerHttpRequest request, @ } @RequestMapping("/response-header") - public Mono>> responseHeader(ServerHttpResponse response, @RequestParam(required = false) List header){ - if (CollectionUtils.isEmpty(header)){ + public Mono>> responseHeader(ServerHttpResponse response, @RequestParam(required = false) List header) { + if (CollectionUtils.isEmpty(header)) { return Mono.empty(); } Map> headers = new HashMap<>(); @@ -134,8 +134,8 @@ public Mono>> responseHeader(ServerHttpResponse response } @RequestMapping("/cookie-set") - public Mono cookieSet(ServerHttpResponse response,Cookie cookie){ - if (cookie == null){ + public Mono cookieSet(ServerHttpResponse response, Cookie cookie) { + if (cookie == null) { return Mono.empty(); } ResponseCookie responseCookie = ResponseCookie.from(cookie.getName(), cookie.getValue()) @@ -149,4 +149,10 @@ public Mono cookieSet(ServerHttpResponse response,Cookie cookie){ response.addCookie(responseCookie); return Mono.just(cookie.toString()); } + + @GetMapping("/status/{statusCode}") + public Mono getHttpStatus(ServerHttpResponse response, @PathVariable String statusCode) { + response.setStatusCode(HttpStatus.valueOf(Integer.parseInt(statusCode))); + return Mono.just("ok"); + } }