commit | author | age
|
9c7249
|
1 |
/* |
678b07
|
2 |
mini-server - Ein minimalistischer HTTP-Server |
U |
3 |
Copyright (C) 2021 Ulrich Hilger |
9c7249
|
4 |
|
678b07
|
5 |
This program is free software: you can redistribute it and/or modify |
U |
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
9c7249
|
9 |
|
678b07
|
10 |
This program is distributed in the hope that it will be useful, |
U |
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
9c7249
|
14 |
|
678b07
|
15 |
You should have received a copy of the GNU Affero General Public License |
U |
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
9c7249
|
17 |
*/ |
U |
18 |
|
|
19 |
package de.uhilger.minsrv.handler; |
|
20 |
|
|
21 |
import com.sun.net.httpserver.HttpExchange; |
|
22 |
import com.sun.net.httpserver.HttpHandler; |
|
23 |
import de.uhilger.minsrv.App; |
|
24 |
import java.io.IOException; |
|
25 |
import java.io.OutputStream; |
|
26 |
import java.util.logging.Logger; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
8abbcf
|
30 |
* @author Ulrich Hilger |
9c7249
|
31 |
*/ |
U |
32 |
public class StopServerHandler implements HttpHandler { |
|
33 |
|
|
34 |
@Override |
|
35 |
public void handle(HttpExchange exchange) throws IOException { |
|
36 |
Logger.getLogger(StopServerHandler.class.getName()).info(exchange.getRequestURI().toString()); |
|
37 |
String response = "Server stopped"; |
|
38 |
exchange.sendResponseHeaders(200, response.length()); |
|
39 |
OutputStream os = exchange.getResponseBody(); |
|
40 |
os.write(response.getBytes()); |
|
41 |
os.flush(); |
|
42 |
os.close(); |
|
43 |
Logger.getLogger(StopServerHandler.class.getName()).info("stopping app."); |
|
44 |
App.stop(); |
|
45 |
//exchange.getHttpContext().getServer().stop(5); |
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
} |