Skip to content

Commit

Permalink
Merge pull request #212 from brharrington/k3-close-wait
Browse files Browse the repository at this point in the history
fix 404 handler for admin
  • Loading branch information
brharrington committed Dec 18, 2015
2 parents 9b234f3 + 44cdfe1 commit 52e82ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.netflix.karyon.admin.AdminServer;
import com.netflix.karyon.admin.HttpServerConfig;
import com.netflix.karyon.admin.SimpleHttpServer;
import com.netflix.karyon.admin.rest.AdminServerFallback;
import com.sun.net.httpserver.HttpHandler;

import javax.inject.Singleton;
Expand Down Expand Up @@ -57,6 +58,13 @@ protected SimpleHttpServer getAdminServer(
return new SimpleHttpServer(config, handlers);
}

@Provides
@Singleton
@AdminServerFallback
protected HttpHandler provideFallback() {
return new NotFoundHandler();
}

@Override
protected void configure() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2015 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.iep.karyon3;

import com.google.common.base.Charsets;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import java.io.IOException;
import java.io.OutputStream;

public class NotFoundHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
exchange.getResponseHeaders().set("Content-Type", "text/plain");
exchange.sendResponseHeaders(404, 0);
try (OutputStream out = exchange.getResponseBody()) {
String msg = "Resource '" + exchange.getRequestURI().getPath() + "' not found.\n";
out.write(msg.getBytes(Charsets.UTF_8));
}
}
}

0 comments on commit 52e82ad

Please sign in to comment.