Skip to content

Commit

Permalink
Add command line option -server.bindaddress
Browse files Browse the repository at this point in the history
This allows to specify the binding address of the fls in
addition to the port. If nothing is specified the wildcard
0.0.0.0 is used, that assumes to listen on all available
addresses.

Usage:
-server.bindaddress=192.168.123.123

This should also work with ipv6 addresses, however I cannot
test this at the moment.
  • Loading branch information
Jens Schmidt committed Jun 29, 2022
1 parent 8467b7d commit 15c8f23
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.passage.lic.jrtty
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.passage.lic.jetty;singleton:=true
Bundle-Version: 0.1.200.qualifier
Bundle-Version: 0.1.300.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.passage.lic.internal.jetty;

import java.net.InetSocketAddress;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
Expand All @@ -21,6 +22,7 @@
import org.eclipse.jetty.server.Server;
import org.eclipse.passage.lic.internal.jetty.i18n.Messages;
import org.eclipse.passage.lic.internal.net.connect.Port;
import org.eclipse.passage.lic.internal.net.connect.BindAddress;

public final class JettyServer {

Expand All @@ -33,12 +35,14 @@ public JettyServer(Supplier<JettyHandler> handler) {
this.handler = handler;
}

public void launch(Port port) throws JettyException {
public void launch(BindAddress listen, Port port) throws JettyException {
try {
server = Optional.of(new Server(port.get().get()));
InetSocketAddress address = InetSocketAddress.createUnresolved(listen.get().get(),
port.get().get());
server = Optional.of(new Server(address));
server.get().setHandler(handler.get());
server.get().start();
log.info(String.format(Messages.started, port.get().get()));
log.info(String.format(Messages.started, address));
} catch (Exception e) {
logAndRethrow(e, Messages.error_onstart);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ArSysOp - initial API and implementation
###############################################################################

server_started=Server started on port %s \n
server_started=Server started on address:port %s \n
server_stopped=Server stopped \n
server_already_running=Server is already running \n
server_not_running=No running server found \n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@
import org.eclipse.passage.lic.equinox.access.LicenseProtection;
import org.eclipse.passage.lic.internal.jetty.JettyException;
import org.eclipse.passage.lic.internal.jetty.JettyServer;
import org.eclipse.passage.lic.internal.net.connect.BindAddress;
import org.eclipse.passage.lic.internal.net.connect.Port;

final class ServerHandles extends Command {

private final Logger log = LogManager.getLogger(getClass());
private final JettyServer server;
private final Port port;
private final LicenseProtection license = new LicenseProtection();
private final BindAddress listen;
private final Port port;

ServerHandles(JettyServer server, String name) {
super(new Scope.Of(name), new Handlers().get());
this.server = server;
this.listen = new BindAddress("0.0.0.0"); //$NON-NLS-1$
this.port = new Port(8090);
}

Expand All @@ -40,7 +43,7 @@ public void start() {
return;
}
try {
server.launch(port);
server.launch(listen, port);
} catch (JettyException e) {
log.error("failed to launch Jetty server", e); //$NON-NLS-1$
}
Expand All @@ -62,16 +65,18 @@ public void restart() {

public void state() {
try {
String where = port.get().map(i -> i.toString()).orElse("-"); //$NON-NLS-1$
System.out.println(server.state() + " on port " + where); //$NON-NLS-1$
String listen = this.listen.get().orElse("-"); //$NON-NLS-1$
String port = this.port.get().map(i -> i.toString()).orElse("-"); //$NON-NLS-1$
System.out.println(server.state() + " listen on " + listen + " on port " + port); //$NON-NLS-1$ //$NON-NLS-2$
} catch (JettyException e) {
log.error("failed to report state of Jetty server", e); //$NON-NLS-1$
}
}

public ServerHandles(Scope scope, String[] names, JettyServer server, Port port) {
public ServerHandles(Scope scope, String[] names, JettyServer server, BindAddress listen, Port port) {
super(scope, names);
this.server = server;
this.listen = listen;
this.port = port;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2022, 2022 IILS mbH
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IILS mbH - implementation to specify server listen address
*******************************************************************************/
package org.eclipse.passage.lic.internal.net.connect;

import java.util.Optional;

/**
* @since 2.5
*/
public final class BindAddress extends CliParameter<String> {

/**
* @since 2.5
*/
public BindAddress() {
super("0.0.0.0"); //$NON-NLS-1$
}

public BindAddress(String lazy) {
super(lazy);
}

public BindAddress(String[] sources, String lazy) {
super(sources, lazy);
}

@Override
public String key() {
return "server.bindaddress"; //$NON-NLS-1$
}

@Override
protected Optional<String> parse(String value) {
return Optional.of(value);
}

}

0 comments on commit 15c8f23

Please sign in to comment.