Having the remote Jetty server feature remotely using an HTTP request is not recommended because it provides a potential security risk. In most cases, there should be enough SSH for the hosting server and run the appropriate command to shut down the corresponding instance of the Jetty server.
The main idea is to start a separate thread as part of the Jetty startup code (so there is no need to sleep, as required in one of the answers mentioned in the comments), which will serve as a service flow for processing shutdown requests. In this thread, the ServerSocket can be bound to the local host and assigned port, and when the expected message is expected, it will call server.stop() .
This blog post gives a detailed discussion using the above approach.
01es
source share