Skip to content

Commit

Permalink
disable shutdown listener for Hop Server, fixes apache#3367
Browse files Browse the repository at this point in the history
  • Loading branch information
hansva committed Nov 17, 2023
1 parent da53373 commit 4c6fc9b
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions engine/src/main/java/org/apache/hop/www/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@

package org.apache.hop.www;

import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.Servlet;
import org.apache.hop.core.Const;
import org.apache.hop.core.HopEnvironment;
import org.apache.hop.core.encryption.Encr;
Expand Down Expand Up @@ -61,27 +71,14 @@
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.glassfish.jersey.servlet.ServletContainer;

import javax.servlet.Servlet;
import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class WebServer {

public static final int PORT = 80;
public static final int SHUTDOWN_PORT = 8079;
private static final int DEFAULT_DETECTION_TIMER = 20000;
private static final Class<?> PKG = WebServer.class; // For Translator

private ILogChannel log;
private IVariables variables;
public static final int PORT = 80;
public static final int SHUTDOWN_PORT = 8079;

private Server server;

private PipelineMap pipelineMap;
Expand All @@ -98,38 +95,6 @@ public class WebServer {

private SslConfiguration sslConfig;

private static class MonitorThread extends Thread {

private ServerSocket socket;
private Server server;

public MonitorThread(Server server, String hostname, int shutdownPort) {
this.server = server;
setDaemon(true);
setName("StopMonitor");
try {
socket = new ServerSocket(shutdownPort, 1, InetAddress.getByName(hostname));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public void run() {
Socket accept;
try {
accept = socket.accept();
BufferedReader reader = new BufferedReader(new InputStreamReader(accept.getInputStream()));
reader.readLine();
server.stop();
accept.close();
socket.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

public WebServer(
ILogChannel log,
PipelineMap pipelineMap,
Expand Down Expand Up @@ -216,6 +181,10 @@ public Server getServer() {
return server;
}

public void setServer(Server server) {
this.server = server;
}

public void startServer() throws Exception {
server = new Server();

Expand Down Expand Up @@ -328,8 +297,9 @@ public void startServer() throws Exception {

// Start execution
createListeners();
Thread monitor = new MonitorThread(server, hostname, shutdownPort);
monitor.start();
// Temp disable shutdown listener #3367
// Thread monitor = new MonitorThread(server, hostname, shutdownPort);
// monitor.start();
server.start();
}

Expand Down Expand Up @@ -382,9 +352,11 @@ private void createListeners() {
connector.setHost(hostname);
connector.setName(BaseMessages.getString(PKG, "WebServer.Log.HopHTTPListener", hostname));
log.logBasic(BaseMessages.getString(PKG, "WebServer.Log.CreateListener", hostname, "" + port));
log.logBasic(
BaseMessages.getString(
PKG, "WebServer.Log.CreateShutDownListener", hostname, "" + shutdownPort));

// Temp disable shutdown listener #3367
// log.logBasic(
// BaseMessages.getString(
// PKG, "WebServer.Log.CreateShutDownListener", hostname, "" + shutdownPort));

server.setConnectors(new Connector[] {connector});
}
Expand Down Expand Up @@ -541,10 +513,6 @@ public void setPort(int port) {
this.port = port;
}

public void setServer(Server server) {
this.server = server;
}

/**
* Gets variables
*
Expand Down Expand Up @@ -587,4 +555,36 @@ private boolean supportGraphicEnvironment() {
}
return false;
}

private static class MonitorThread extends Thread {

private ServerSocket socket;
private Server server;

public MonitorThread(Server server, String hostname, int shutdownPort) {
this.server = server;
setDaemon(true);
setName("StopMonitor");
try {
socket = new ServerSocket(shutdownPort, 1, InetAddress.getByName(hostname));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public void run() {
Socket accept;
try {
accept = socket.accept();
BufferedReader reader = new BufferedReader(new InputStreamReader(accept.getInputStream()));
reader.readLine();
server.stop();
accept.close();
socket.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}

0 comments on commit 4c6fc9b

Please sign in to comment.