use of org.mobicents.tools.sip.balancer.GracefulShutdown in project load-balancer by RestComm.
the class HttpRequestHandler method messageReceived.
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
Object msg = e.getMessage();
if (msg instanceof WebSocketFrame) {
handleWebSocketFrame(ctx, e);
} else if (msg instanceof HttpRequest) {
request = (HttpRequest) e.getMessage();
Integer apiPort = balancerRunner.balancerContext.lbConfig.getCommonConfiguration().getStatisticPort();
if (apiPort != null) {
try {
URI uri = new URI(request.getUri());
if (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getPort() == apiPort) {
String currUriPath = uri.getPath().toLowerCase();
switch(currUriPath) {
case "/lbnoderegex":
if (addRegex(e))
writeResponse(e, HttpResponseStatus.OK, "Regex set");
else
writeResponse(e, HttpResponseStatus.BAD_REQUEST, "Regex NOT set, use : 127.0.0.1:2006/lbnoderegex?regex=(.*)(\\d+)(.*)&ip=127.0.0.1&port=5060");
return;
case "/lbloglevel":
changeLogLevel(e);
writeResponse(e, HttpResponseStatus.OK, "Log level changed");
return;
case "/lbstat":
writeStatisticResponse(e);
return;
case "/lbinfo":
writeInfoResponse(e);
return;
case "/lbstop":
if (!balancerRunner.balancerContext.securityRequired || (balancerRunner.balancerContext.securityRequired && checkCredentials(e))) {
writeResponse(e, HttpResponseStatus.LOCKED, IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("bye.html")));
new GracefulShutdown(balancerRunner).start();
} else {
writeResponse(e, HttpResponseStatus.UNAUTHORIZED, "Authorization required : Incorrect login or password" + " request example : 127.0.0.1:2006/lbstop?login=daddy&password=123456");
}
return;
default:
writeResponse(e, HttpResponseStatus.INTERNAL_SERVER_ERROR, "Server error");
return;
}
}
} catch (URISyntaxException e1) {
// ignore exception
}
}
}
if (balancerRunner.balancerContext.lbConfig.getHttpConfiguration().getHttpsPort() != null && (((InetSocketAddress) ctx.getChannel().getLocalAddress()).getPort() == balancerRunner.balancerContext.lbConfig.getHttpConfiguration().getHttpPort())) {
// redirect http request send 3xx response
sendRedirectResponse(e, request);
return;
}
if (msg instanceof HttpRequest) {
balancerRunner.balancerContext.httpRequests.incrementAndGet();
balancerRunner.balancerContext.httpRequestsProcessedByMethod.get(request.getMethod().getName()).incrementAndGet();
}
balancerRunner.balancerContext.httpBytesToServer.addAndGet(request.getContent().capacity());
String telestaxHeader = request.headers().get("TelestaxProxy");
if (telestaxHeader != null && telestaxHeader.equalsIgnoreCase("true")) {
balancerRunner.getLatestInvocationContext().balancerAlgorithm.proxyMessage(ctx, e);
} else {
handleHttpRequest(ctx, e);
}
}
Aggregations