Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command line option -server.bindaddress #1102

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}