All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.factoryfx.jetty.HttpServerConnector Maven / Gradle / Ivy

package io.github.factoryfx.jetty;

import org.eclipse.jetty.server.NetworkTrafficServerConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.ssl.SslContextFactory;


public class HttpServerConnector {

    private final String host;
    private final int port;
    private final SslContextFactory sslContextFactory;

    private  NetworkTrafficServerConnector connector;

    public HttpServerConnector(String host, int port, SslContextFactory sslContextFactory) {
        this.host = host;
        this.port = port;
        this.sslContextFactory= sslContextFactory;
    }

    public void addToServer(Server server) {
        if (sslContextFactory!=null){
            connector = new NetworkTrafficServerConnector(server,sslContextFactory);
        } else {
            connector = new NetworkTrafficServerConnector(server);
        }

        connector.setPort(port);
        connector.setReuseAddress(true);
        connector.setHost(host);
        server.addConnector(connector);
        server.manage(connector);
        if (server.isStarted()) {
            try {
                connector.start();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy