Home > Blockchain >  Spring boot - Close connection
Spring boot - Close connection

Time:08-19

Is it possible for a spring endpoint to abruptly close connection ?

Ex :

  @GetMapping(/connectionClosedByPeerEndPoint)
  String foo(){
    //Close connection, and send no http response at all
  }

or simply to close connection abrupltly even before reaching the endpoint, like mid http handshake(without FIN signal ?). What conf one would one need to do in order to achieve that.

The purpose of this is nothing.

Thanks in advance.

CodePudding user response:

add to application.properties

server.shutdown=graceful 

or that one:

management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true

CodePudding user response:

You should create ConfigurableApplicationContext in main class and create method that closes it, e.g.:

public class SpringBootApplication {
    private static ConfigurableApplicationContext context;
    public static void main(String[] args) {
        context = SpringApplication.run(SpringBootApplication.class, args);
    }

    public static void finish(){
        context.close();
    }

}

And your code in controller should be next:

@GetMapping("/exit")
    public void exit(){
        SpringBootApplication.finish();
    }
  • Related