Example usage for io.vertx.core.http HttpServerOptions setHost

List of usage examples for io.vertx.core.http HttpServerOptions setHost

Introduction

In this page you can find the example usage for io.vertx.core.http HttpServerOptions setHost.

Prototype

@Override
    public HttpServerOptions setHost(String host) 

Source Link

Usage

From source file:com.dinstone.vertx.verticle.HttpManageVerticle.java

License:Apache License

private HttpServerOptions getRestHttpServerOptions() {
    HttpServerOptions serverOptions = null;
    try {/*from w w w  . ja v a 2  s  . c  o  m*/
        serverOptions = applicationContext.getBean("restHttpServerOptions", HttpServerOptions.class);
    } catch (Exception e) {
        // ignore
    }
    if (serverOptions == null) {
        serverOptions = new HttpServerOptions();
    }

    serverOptions.setIdleTimeout(manageProperties.getIdleTimeout());
    serverOptions.setPort(manageProperties.getPort());

    if (manageProperties.getHost() != null) {
        serverOptions.setHost(manageProperties.getHost());
    }
    return serverOptions;
}

From source file:com.dinstone.vertx.verticle.HttpRestVerticle.java

License:Apache License

private HttpServerOptions getRestHttpServerOptions() {
    HttpServerOptions serverOptions = null;
    try {//from  w  w w  .j  a va 2 s  .com
        serverOptions = applicationContext.getBean("restHttpServerOptions", HttpServerOptions.class);
    } catch (Exception e) {
        // ignore
    }
    if (serverOptions == null) {
        serverOptions = new HttpServerOptions();
    }

    serverOptions.setIdleTimeout(restProperties.getIdleTimeout());
    serverOptions.setPort(restProperties.getPort());

    if (restProperties.getHost() != null) {
        serverOptions.setHost(restProperties.getHost());
    }
    return serverOptions;
}

From source file:io.gravitee.am.gateway.vertx.VertxHttpServerFactory.java

License:Apache License

@Override
public HttpServer getObject() throws Exception {
    HttpServerOptions options = new HttpServerOptions();

    // Binding port
    options.setPort(httpServerConfiguration.getPort());
    options.setHost(httpServerConfiguration.getHost());

    // Netty pool buffers must be enabled by default
    options.setUsePooledBuffers(true);/*from  ww w .  j  ava 2s .  co  m*/

    if (httpServerConfiguration.isSecured()) {
        options.setSsl(httpServerConfiguration.isSecured());
        options.setUseAlpn(httpServerConfiguration.isAlpn());

        if (httpServerConfiguration.isClientAuth()) {
            options.setClientAuth(ClientAuth.REQUIRED);
        }

        if (httpServerConfiguration.getTrustStorePath() != null) {
            options.setTrustStoreOptions(new JksOptions().setPath(httpServerConfiguration.getTrustStorePath())
                    .setPassword(httpServerConfiguration.getTrustStorePassword()));
        }

        if (httpServerConfiguration.getKeyStorePath() != null) {
            options.setKeyStoreOptions(new JksOptions().setPath(httpServerConfiguration.getKeyStorePath())
                    .setPassword(httpServerConfiguration.getKeyStorePassword()));
        }
    }

    // Customizable configuration
    options.setCompressionSupported(httpServerConfiguration.isCompressionSupported());
    options.setIdleTimeout(httpServerConfiguration.getIdleTimeout());
    options.setTcpKeepAlive(httpServerConfiguration.isTcpKeepAlive());

    return vertx.createHttpServer(options);
}

From source file:org.eclipse.hono.adapter.http.AbstractVertxBasedHttpProtocolAdapter.java

License:Open Source License

/**
 * Gets the options to use for creating the TLS secured http server.
 * <p>/*ww  w.  j a  v  a 2s. co m*/
 * Subclasses may override this method in order to customize the server.
 * <p>
 * This method returns default options with the host and port being set to the corresponding values
 * from the <em>config</em> properties and using a maximum chunk size of 4096 bytes.
 * 
 * @return The http server options.
 */
protected HttpServerOptions getHttpServerOptions() {

    HttpServerOptions options = new HttpServerOptions();
    options.setHost(getConfig().getBindAddress()).setPort(getConfig().getPort(getPortDefaultValue()))
            .setMaxChunkSize(4096);
    addTlsKeyCertOptions(options);
    addTlsTrustOptions(options);
    return options;
}

From source file:org.eclipse.hono.adapter.http.AbstractVertxBasedHttpProtocolAdapter.java

License:Open Source License

/**
 * Gets the options to use for creating the insecure http server.
 * <p>/*w w  w  .j a  v  a2 s .  com*/
 * Subclasses may override this method in order to customize the server.
 * <p>
 * This method returns default options with the host and port being set to the corresponding values
 * from the <em>config</em> properties and using a maximum chunk size of 4096 bytes.
 * 
 * @return The http server options.
 */
protected HttpServerOptions getInsecureHttpServerOptions() {

    HttpServerOptions options = new HttpServerOptions();
    options.setHost(getConfig().getInsecurePortBindAddress())
            .setPort(getConfig().getInsecurePort(getInsecurePortDefaultValue())).setMaxChunkSize(4096);
    return options;
}

From source file:se.liquidbytes.jel.web.WebserverVerticle.java

License:Apache License

/**
 * Method should be called when verticle should start up
 *
 * @param future Future for reporting back success or failure of execution
 *//*www .j a  v a2  s.c  o m*/
@Override
public void start(Future<Void> future) {

    // If no API should be exposed, and thus the client won't work either, then don't start the webserver.
    if (Settings.get("skipapi").equals("true")) {
        logger.info("No API will be exposed according to the settings provided during application startup.");
        future.complete();
        return;
    }

    systemApi = new SystemApi(vertx);
    pluginApi = new PluginApi(vertx);
    adapterApi = new AdapterApi(vertx);
    siteApi = new SiteApi(vertx);
    userApi = new UserApi(vertx);
    deviceApi = new DeviceApi(vertx);

    HttpServerOptions options = new HttpServerOptions();
    options.setHost(SystemInfo.getIP());
    options.setPort(Integer.parseInt(config.getString("port")));

    server = vertx.createHttpServer(options);
    server.requestHandler(createRouter()::accept);
    server.listen(result -> {
        if (result.succeeded()) {
            logger.info(String.format("Jel REST-API now listening on %s port %d.", options.getHost(),
                    options.getPort()));
            future.complete();
        } else {
            future.fail(result.cause());
        }
    });
}

From source file:suonos.httpserver.VertxHttpServer.java

License:Apache License

@Override
public void run() {
    HttpServerOptions opts = new HttpServerOptions();
    opts.setHost(host);
    opts.setPort(port);//w w w  .  j  ava 2s  .c o m
    opts.setCompressionSupported(true);

    staticFileHandler.setContextPath("/res");
    server = vertx.createHttpServer(opts);

    webApp.routes().addRouteHandler("/res/:path*", staticFileHandler);
    server.requestHandler(new VertxRequestHandler(vertx, webApp));
    server.listen();
}