diff --git a/bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF index 54f156ea8..452234d56 100644 --- a/bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/JettyServer.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/JettyServer.java index 044b27385..3d8f03182 100644 --- a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/JettyServer.java +++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/JettyServer.java @@ -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; @@ -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 { @@ -33,12 +35,14 @@ public JettyServer(Supplier 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); } diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.properties b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.properties index 4cf3ae0f8..1507e553d 100644 --- a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.properties +++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.properties @@ -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 diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/ServerHandles.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/ServerHandles.java index 7e08d4ddb..b68ce9735 100644 --- a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/ServerHandles.java +++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/ServerHandles.java @@ -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); } @@ -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$ } @@ -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; } diff --git a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/connect/BindAddress.java b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/connect/BindAddress.java new file mode 100644 index 000000000..af52b201b --- /dev/null +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/connect/BindAddress.java @@ -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 { + + /** + * @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 parse(String value) { + return Optional.of(value); + } + +}