2727import org .slf4j .LoggerFactory ;
2828
2929import java .io .IOException ;
30- import java .io .InputStream ;
3130import java .io .OutputStream ;
3231import java .net .InetSocketAddress ;
3332import java .net .URI ;
@@ -123,7 +122,6 @@ private boolean startServerInternal() {
123122 server .setExecutor (serverExecutor );
124123
125124 server .createContext ("/api/deviceinfo" , new DeviceInfoHandler ());
126- server .createContext ("/api/metrics" , new MetricsHandler ());
127125
128126 server .start ();
129127 serverRunning .set (true );
@@ -137,7 +135,7 @@ private boolean startServerInternal() {
137135
138136 private void startSender () {
139137 if (senderRunning .compareAndSet (false , true )) {
140- LOGGER .info ("HttpService sender started, target: {}" , remoteUrl );
138+ LOGGER .debug ("HttpService sender started, target: {}" , remoteUrl );
141139 senderExecutor .execute (this ::sendLoop );
142140 }
143141 }
@@ -258,41 +256,4 @@ private void sendResponse(HttpExchange exchange, int statusCode, String body) {
258256 }
259257 }
260258 }
261-
262- private static class MetricsHandler implements HttpHandler {
263- @ Override
264- public void handle (HttpExchange exchange ) {
265- if (!"POST" .equalsIgnoreCase (exchange .getRequestMethod ())) {
266- sendResponse (exchange , 405 , "{\" error\" :\" Method not allowed\" }" );
267- return ;
268- }
269-
270- try {
271- int contentLength = Integer .parseInt (exchange .getRequestHeaders ().getFirst ("Content-Length" ));
272- if (contentLength > 0 ) {
273- try (InputStream is = exchange .getRequestBody ()) {
274- byte [] body = is .readAllBytes ();
275- LOGGER .debug ("Received metrics payload: {} bytes" , body .length );
276- }
277- }
278- } catch (Exception e ) {
279- LOGGER .debug ("Failed to read metrics payload: {}" , e .getMessage ());
280- }
281-
282- sendResponse (exchange , 200 , "{\" status\" :\" ok\" }" );
283- }
284-
285- private void sendResponse (HttpExchange exchange , int statusCode , String body ) {
286- try {
287- exchange .getResponseHeaders ().set ("Content-Type" , "application/json" );
288- byte [] bytes = body .getBytes (StandardCharsets .UTF_8 );
289- exchange .sendResponseHeaders (statusCode , bytes .length );
290- try (OutputStream os = exchange .getResponseBody ()) {
291- os .write (bytes );
292- }
293- } catch (IOException e ) {
294- LOGGER .debug ("Failed to send response: {}" , e .getMessage ());
295- }
296- }
297- }
298259}
0 commit comments