Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from visioncritical/hostconfig
Browse files Browse the repository at this point in the history
Added option to define/restrict host instead of using wildcard
  • Loading branch information
matt-richardson authored Sep 5, 2016
2 parents a422664 + 45b40a0 commit 15cb332
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ public void initializeGoApplicationAccessor(GoApplicationAccessor goApplicationA
if (pipelineListener == null) {
PluginConfig pluginConfig = new PluginConfig();
int port = pluginConfig.getPort();
String host = pluginConfig.getHost();

//org.java_websocket.WebSocketImpl.DEBUG = true;
PipelineWebSocketServer s;
try {
LOGGER.info("Starting WebSocket server started on port: " + port);
s = new PipelineWebSocketServer(port);
if (pluginConfig.isHostSet()) {
s = new PipelineWebSocketServer(host, port);
} else {
s = new PipelineWebSocketServer(port);
}
s.start();
LOGGER.info("WebSocket server started on port: " + s.getPort());
pipelineListener = new WebSocketPipelineListener(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public PipelineWebSocketServer(int port)
throws UnknownHostException {
super(new InetSocketAddress(port));
}

public PipelineWebSocketServer(String host, int port)
throws UnknownHostException {
super(new InetSocketAddress(host, port));
}

public void onOpen(WebSocket conn, ClientHandshake handshake) {
LOGGER.debug(conn.getRemoteSocketAddress().getAddress().getHostAddress() + " connected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class PluginConfig {
private static Logger LOGGER = Logger.getLoggerFor(GoNotificationPlugin.class);
private static final String PLUGIN_CONF = "gocd-websocket-notifier.conf";
private int port = 8887;
private String host = "";

public PluginConfig() {
String userHome = System.getProperty("user.home");
Expand All @@ -22,9 +23,16 @@ public PluginConfig() {
if (config.hasPath("port")) {
setPort(config.getInt("port"));
}
if (config.hasPath("host")) {
setHost(config.getString("host"));
}
}
}

public int getPort() { return port; }
public void setPort(int port) { this.port = port; }

public String getHost() { return host; }
public void setHost(String host) { this.host = host; }
public boolean isHostSet() { return !host.isEmpty(); }
}

0 comments on commit 15cb332

Please sign in to comment.