Skip to content

Commit

Permalink
Merge pull request #29 from Accelerator96/daocloud
Browse files Browse the repository at this point in the history
add for test
  • Loading branch information
Frapschen authored Sep 18, 2023
2 parents 8c204eb + dced3bc commit c9dabf8
Showing 1 changed file with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ public HelloWorld(Environment environment) {
}

@RequestMapping("/")
public Mono<String> helloWorld(){
public Mono<String> helloWorld() {
return Mono.just("adservice-springcloud: hello world!");
}

@RequestMapping("/test1")
public Mono<String> test1(){
public Mono<String> test1() {
return Mono.just("This is a test 1 API.");
}

@RequestMapping("/test2")
public Mono<String> test2(){
public Mono<String> test2() {
return Mono.just("This is a test 2 API.");
}

@GetMapping("/dynamic-config")
public Mono<String> dynamicConfig(){
public Mono<String> dynamicConfig() {
return Mono.just(config);
}

@RequestMapping("/timeout/{timeout}")
public Mono<String> helloWorld(@PathVariable long timeout) throws InterruptedException{
public Mono<String> helloWorld(@PathVariable long timeout) throws InterruptedException {
Thread.sleep(timeout);
return Mono.just("timeout:"+timeout);
return Mono.just("timeout:" + timeout);
}

// @PostMapping("/method")
Expand All @@ -67,51 +67,51 @@ public Mono<String> helloWorld(@PathVariable long timeout) throws InterruptedExc
// }

@RequestMapping("/method")
public Mono<String> method(ServerHttpRequest request){
return Mono.just("method:"+request.getMethodValue());
public Mono<String> method(ServerHttpRequest request) {
return Mono.just("method:" + request.getMethodValue());
}

@RequestMapping("/hostname")
public Mono<String> 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<String> 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<String> path(ServerHttpRequest request){
return Mono.just("path:"+ request.getPath());
@RequestMapping({"/path/**", "/path**"})
public Mono<String> path(ServerHttpRequest request) {
return Mono.just("path:" + request.getPath());
}

@RequestMapping("/set-retry-count/{limit}")
public Mono<String> retryCount(@PathVariable long limit){
public Mono<String> 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<String> retry(ServerHttpResponse response){
if (limit <1 || count.addAndGet(1) % limit ==0){
public Mono<String> 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<Map<String,List<String>>> requestHeader(ServerHttpRequest request, @RequestParam(required = false) List<String> header){
if (CollectionUtils.isEmpty(header)){
public Mono<Map<String, List<String>>> requestHeader(ServerHttpRequest request, @RequestParam(required = false) List<String> header) {
if (CollectionUtils.isEmpty(header)) {
return Mono.empty();
}
Map<String, List<String>> headers = new HashMap<>();
Expand All @@ -122,8 +122,8 @@ public Mono<Map<String,List<String>>> requestHeader(ServerHttpRequest request, @
}

@RequestMapping("/response-header")
public Mono<Map<String,List<String>>> responseHeader(ServerHttpResponse response, @RequestParam(required = false) List<String> header){
if (CollectionUtils.isEmpty(header)){
public Mono<Map<String, List<String>>> responseHeader(ServerHttpResponse response, @RequestParam(required = false) List<String> header) {
if (CollectionUtils.isEmpty(header)) {
return Mono.empty();
}
Map<String, List<String>> headers = new HashMap<>();
Expand All @@ -134,8 +134,8 @@ public Mono<Map<String,List<String>>> responseHeader(ServerHttpResponse response
}

@RequestMapping("/cookie-set")
public Mono<String> cookieSet(ServerHttpResponse response,Cookie cookie){
if (cookie == null){
public Mono<String> cookieSet(ServerHttpResponse response, Cookie cookie) {
if (cookie == null) {
return Mono.empty();
}
ResponseCookie responseCookie = ResponseCookie.from(cookie.getName(), cookie.getValue())
Expand All @@ -149,4 +149,10 @@ public Mono<String> cookieSet(ServerHttpResponse response,Cookie cookie){
response.addCookie(responseCookie);
return Mono.just(cookie.toString());
}

@GetMapping("/status/{statusCode}")
public Mono<String> getHttpStatus(ServerHttpResponse response, @PathVariable String statusCode) {
response.setStatusCode(HttpStatus.valueOf(Integer.parseInt(statusCode)));
return Mono.just("ok");
}
}

0 comments on commit c9dabf8

Please sign in to comment.