org.xnio.OptionMap Java Examples

The following examples show how to use org.xnio.OptionMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: e-commerce-microservice   Author: xebialabs   File: WebConfigurerTest.java    License: Apache License 2.0 7 votes vote down vote up
@Test
public void testCustomizeServletContainer() {
    env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    UndertowServletWebServerFactory container = new UndertowServletWebServerFactory();
    webConfigurer.customize(container);
    assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
    assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8");
    assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8");
    if (container.getDocumentRoot() != null) {
        assertThat(container.getDocumentRoot().getPath()).isEqualTo(FilenameUtils.separatorsToSystem("build/www"));
    }

    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull();
}
 
Example #2
Source Project: lams   Author: lamsfoundation   File: UndertowClient.java    License: GNU General Public License v2.0 6 votes vote down vote up
public IoFuture<ClientConnection> connect(InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    ClientProvider provider = getClientProvider(uri);
    final FutureResult<ClientConnection> result = new FutureResult<>();
    provider.connect(new ClientCallback<ClientConnection>() {
        @Override
        public void completed(ClientConnection r) {
            result.setResult(r);
        }

        @Override
        public void failed(IOException e) {
            result.setException(e);
        }
    }, bindAddress, uri, worker, ssl, bufferPool, options);
    return result.getIoFuture();
}
 
Example #3
Source Project: cubeai   Author: cube-ai   File: WebConfigurerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomizeServletContainer() {
    env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
    assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8");
    assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8");
    if (container.getDocumentRoot() != null) {
        assertThat(container.getDocumentRoot().getPath()).isEqualTo(FilenameUtils.separatorsToSystem("target/www"));
    }

    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull();
}
 
Example #4
Source Project: lams   Author: lamsfoundation   File: HttpServerConnection.java    License: GNU General Public License v2.0 6 votes vote down vote up
public HttpServerConnection(StreamConnection channel, final ByteBufferPool bufferPool, final HttpHandler rootHandler, final OptionMap undertowOptions, final int bufferSize, final ConnectorStatisticsImpl connectorStatistics) {
    super(channel, bufferPool, rootHandler, undertowOptions, bufferSize);
    if (channel instanceof SslChannel) {
        sslSessionInfo = new ConnectionSSLSessionInfo(((SslChannel) channel), this);
    }
    this.responseConduit = new HttpResponseConduit(channel.getSinkChannel().getConduit(), bufferPool, this);

    fixedLengthStreamSinkConduit = new ServerFixedLengthStreamSinkConduit(responseConduit, false, false);
    readDataStreamSourceConduit = new ReadDataStreamSourceConduit(channel.getSourceChannel().getConduit(), this);
    //todo: do this without an allocation
    addCloseListener(new CloseListener() {
        @Override
        public void closed(ServerConnection connection) {
            if(connectorStatistics != null) {
                connectorStatistics.decrementConnectionCount();
            }
            responseConduit.freeBuffers();
        }
    });
}
 
Example #5
Source Project: wildfly-core   Author: wildfly   File: RemoteOutboundConnectionAdd.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
void installRuntimeService(final OperationContext context, final ModelNode operation, final ModelNode fullModel) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    final String connectionName = address.getLastElement().getValue();
    final String outboundSocketBindingRef = RemoteOutboundConnectionResourceDefinition.OUTBOUND_SOCKET_BINDING_REF.resolveModelAttribute(context, operation).asString();
    final ServiceName outboundSocketBindingDependency = context.getCapabilityServiceName(OUTBOUND_SOCKET_BINDING_CAPABILITY_NAME, outboundSocketBindingRef, OutboundSocketBinding.class);
    final OptionMap connOpts = ConnectorUtils.getOptions(context, fullModel.get(CommonAttributes.PROPERTY));
    final String username = RemoteOutboundConnectionResourceDefinition.USERNAME.resolveModelAttribute(context, fullModel).asStringOrNull();
    final String securityRealm = fullModel.hasDefined(CommonAttributes.SECURITY_REALM) ? fullModel.require(CommonAttributes.SECURITY_REALM).asString() : null;
    final String authenticationContext = fullModel.hasDefined(CommonAttributes.AUTHENTICATION_CONTEXT) ? fullModel.require(CommonAttributes.AUTHENTICATION_CONTEXT).asString() : null;
    final String protocol = authenticationContext != null ? null : RemoteOutboundConnectionResourceDefinition.PROTOCOL.resolveModelAttribute(context, operation).asString();

    // create the service
    final ServiceName serviceName = OUTBOUND_CONNECTION_CAPABILITY.getCapabilityServiceName(connectionName);
    final ServiceName aliasServiceName = RemoteOutboundConnectionService.REMOTE_OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionName);
    final ServiceName deprecatedName = AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionName);

    final ServiceBuilder<?> builder = context.getServiceTarget().addService(serviceName);
    final Consumer<RemoteOutboundConnectionService> serviceConsumer = builder.provides(deprecatedName, aliasServiceName);
    final Supplier<OutboundSocketBinding> osbSupplier = builder.requires(outboundSocketBindingDependency);
    final Supplier<SecurityRealm> srSupplier = securityRealm != null ? SecurityRealm.ServiceUtil.requires(builder, securityRealm) : null;
    final Supplier<AuthenticationContext> acSupplier = authenticationContext != null ? builder.requires(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, authenticationContext, AuthenticationContext.class)) : null;
    builder.requires(RemotingServices.SUBSYSTEM_ENDPOINT);
    builder.setInstance(new RemoteOutboundConnectionService(serviceConsumer, osbSupplier, srSupplier, acSupplier, connOpts, username, protocol));
    builder.install();
}
 
Example #6
Source Project: TeamDojo   Author: otto-de   File: WebConfigurerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomizeServletContainer() {
    env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    UndertowServletWebServerFactory container = new UndertowServletWebServerFactory();
    webConfigurer.customize(container);
    assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
    assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8");
    assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8");
    if (container.getDocumentRoot() != null) {
        assertThat(container.getDocumentRoot().getPath()).isEqualTo(FilenameUtils.separatorsToSystem("build/www"));
    }

    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull();
}
 
Example #7
Source Project: wildfly-core   Author: wildfly   File: OptionAttributeDefinition.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings("unchecked")
public OptionMap.Builder resolveOption(final ExpressionResolver context, final ModelNode model, OptionMap.Builder builder) throws OperationFailedException {
    ModelNode value = resolveModelAttribute(context, model);
    if (value.isDefined()) {
        if (getType() == ModelType.INT) {
            builder.set((Option<Integer>) option, value.asInt());
        } else if (getType() == ModelType.LONG) {
            builder.set(option, value.asLong());
        } else if (getType() == ModelType.BOOLEAN) {
            builder.set(option, value.asBoolean());
        } else if (optionType.isEnum()) {
            builder.set(option, option.parseValue(value.asString(), option.getClass().getClassLoader()));
        }else if (option.getClass().getSimpleName().equals("SequenceOption")) {
            builder.setSequence(option, value.asString().split("\\s*,\\s*"));
        } else if (getType() == ModelType.STRING) {
            builder.set(option, value.asString());
        } else {
            throw new OperationFailedException("Don't know how to handle: " + option + " with value: " + value);
        }
    }
    return builder;
}
 
Example #8
Source Project: jhipster-microservices-example   Author: oktadeveloper   File: WebConfigurerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomizeServletContainer() {
    env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
    assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8");
    assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8");
    if (container.getDocumentRoot() != null) {
        assertThat(container.getDocumentRoot().getPath()).isEqualTo(FilenameUtils.separatorsToSystem("target/www"));
    }

    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull();
}
 
Example #9
Source Project: wildfly-core   Author: wildfly   File: ChannelServer.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void addChannelOpenListener(final String channelName, final OpenListener openListener) throws ServiceRegistrationException {
    registration = endpoint.registerService(channelName, new OpenListener() {
        public void channelOpened(final Channel channel) {
            if (openListener != null) {
                openListener.channelOpened(channel);
            }
        }

        public void registrationTerminated() {
            if (openListener != null) {
                openListener.registrationTerminated();
            }
        }
    }, OptionMap.EMPTY);

}
 
Example #10
Source Project: wildfly-core   Author: wildfly   File: DomainTestConnection.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
Channel openChannel(final Connection connection) throws IOException {
    final IoFuture<Channel> future = connection.openChannel(DEFAULT_CHANNEL_SERVICE_TYPE, OptionMap.EMPTY);
    future.await(10L, TimeUnit.SECONDS);
    if (future.getStatus() == IoFuture.Status.WAITING) {
        future.cancel();
        throw ProtocolLogger.ROOT_LOGGER.channelTimedOut();
    }
    final Channel channel = future.get();
    channel.addCloseHandler(new CloseHandler<Channel>() {
        @Override
        public void handleClose(final Channel old, final IOException e) {
            synchronized (ChannelStrategy.this) {
                if(ChannelStrategy.this.channel == old) {
                    ChannelStrategy.this.handler.handleClose(old, e);
                    ChannelStrategy.this.channel = null;
                }
            }
            handler.handleChannelClosed(old, e);
        }
    });
    return channel;
}
 
Example #11
Source Project: light-4j   Author: networknt   File: DefaultConfigLoader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This is a public method that is used to test the connectivity in the integration test to ensure that the
 * light-config-server can be connected with the default bootstrap.truststore. There is no real value for
 * this method other than that.
 *
 * @return String of OK
 */
public static String getConfigServerHealth(String host, String path) {
    String result = null;
    try {
        final CountDownLatch latch = new CountDownLatch(1);
        ClientConnection connection = client.connect(new URI(host), Http2Client.WORKER, client.createXnioSsl(createBootstrapContext()), Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
        final AtomicReference<ClientResponse> reference = new AtomicReference<>();
        try {
            final ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath(path);
            request.getRequestHeaders().put(Headers.HOST, host);
            connection.sendRequest(request, client.createClientCallback(reference, latch));
            latch.await(1000, TimeUnit.MILLISECONDS);
        } finally {
            // here the connection is closed after one request. It should be used for in frequent
            // request as creating a new connection is costly with TLS handshake and ALPN.
            IoUtils.safeClose(connection);
        }
        int statusCode = reference.get().getResponseCode();
        String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
        if (statusCode >= 300) {
            logger.error("Failed to load configs from config server" + statusCode + ":" + body);
            throw new Exception("Failed to load configs from config server: " + statusCode);
        } else {
            result = body;
        }
    } catch (Exception e) {
        logger.error("Exception while calling config server:", e);
    }
    return result;
}
 
Example #12
Source Project: quarkus-http   Author: quarkusio   File: ModClusterProxyServer.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws IOException {
    final XnioWorker worker = Xnio.getInstance().createWorker(OptionMap.EMPTY);
    final Undertow server;

    final ModCluster modCluster = ModCluster.builder(worker).build();
    try {
        if (chost == null) {
            // We are going to guess it.
            chost = java.net.InetAddress.getLocalHost().getHostName();
            System.out.println("Using: " + chost + ":" + cport);
        }

        modCluster.start();

        // Create the proxy and mgmt handler
        final HttpHandler proxy = modCluster.createProxyHandler();
        final MCMPConfig config = MCMPConfig.webBuilder()
                .setManagementHost(chost)
                .setManagementPort(cport)
                .enableAdvertise()
                .getParent()
                .build();

        final HttpHandler mcmp = config.create(modCluster, proxy);

        server = Undertow.builder()
                .addHttpListener(cport, chost)
                .addHttpListener(pport, phost)
                .setHandler(mcmp)
                .build();
        server.start();

        // Start advertising the mcmp handler
        modCluster.advertise(config);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #13
Source Project: lams   Author: lamsfoundation   File: ProxyProtocolReadListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
ProxyProtocolReadListener(StreamConnection streamConnection, OpenListener openListener, UndertowXnioSsl ssl, ByteBufferPool bufferPool, OptionMap sslOptionMap) {
    this.streamConnection = streamConnection;
    this.openListener = openListener;
    this.ssl = ssl;
    this.bufferPool = bufferPool;
    this.sslOptionMap = sslOptionMap;
    if (bufferPool.getBufferSize() < MAX_HEADER_LENGTH) {
        throw UndertowMessages.MESSAGES.bufferPoolTooSmall(MAX_HEADER_LENGTH);
    }
}
 
Example #14
Source Project: cubeai   Author: cube-ai   File: WebConfigurerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomizeServletContainer() {
    env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
    assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8");
    assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8");

    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull();
}
 
Example #15
Source Project: wildfly-core   Author: wildfly   File: EndpointConfigFactory.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public static OptionMap populate(final ExpressionResolver resolver, final ModelNode model) throws OperationFailedException {
    OptionMap.Builder builder = OptionMap.builder()
    .set(Options.TCP_NODELAY, Boolean.TRUE)
    .set(Options.REUSE_ADDRESSES, true)
    .addAll(OptionList.resolveOptions(resolver, model, RemotingSubsystemRootResource.OPTIONS));

    return builder.getMap();
}
 
Example #16
Source Project: lams   Author: lamsfoundation   File: Http2OpenListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Http2OpenListener(final ByteBufferPool pool, final OptionMap undertowOptions, String protocol) {
    this.undertowOptions = undertowOptions;
    this.bufferPool = pool;
    PooledByteBuffer buf = pool.allocate();
    this.bufferSize = buf.getBuffer().remaining();
    buf.close();
    connectorStatistics = new ConnectorStatisticsImpl();
    statisticsEnabled = undertowOptions.get(UndertowOptions.ENABLE_STATISTICS, false);
    this.protocol = protocol;
}
 
Example #17
Source Project: lams   Author: lamsfoundation   File: WebSocketClient.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Deprecated
public static IoFuture<WebSocketChannel> connect(XnioWorker worker, XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap optionMap, InetSocketAddress bindAddress, final URI uri, WebSocketVersion version, WebSocketClientNegotiation clientNegotiation, Set<ExtensionHandshake> clientExtensions) {
    return connectionBuilder(worker, bufferPool, uri)
            .setSsl(ssl)
            .setOptionMap(optionMap)
            .setBindAddress(bindAddress)
            .setVersion(version)
            .setClientNegotiation(clientNegotiation)
            .setClientExtensions(clientExtensions)
            .connect();
}
 
Example #18
Source Project: lams   Author: lamsfoundation   File: NodePingUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Try to open a socket connection to given address.
 *
 * @param address     the socket address
 * @param exchange    the http servers exchange
 * @param callback    the ping callback
 * @param options     the options
 */
static void pingHost(InetSocketAddress address, HttpServerExchange exchange, PingCallback callback, OptionMap options) {

    final XnioIoThread thread = exchange.getIoThread();
    final XnioWorker worker = thread.getWorker();
    final HostPingTask r = new HostPingTask(address, worker, callback, options);
    // Schedule timeout task
    scheduleCancelTask(exchange.getIoThread(), r, 5, TimeUnit.SECONDS);
    exchange.dispatch(exchange.isInIoThread() ? SameThreadExecutor.INSTANCE : thread, r);
}
 
Example #19
Source Project: cubeai   Author: cube-ai   File: WebConfigurerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testUndertowHttp2Enabled() {
    props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue();
}
 
Example #20
Source Project: wildfly-core   Author: wildfly   File: RemotingSubsystemAdd.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {

    // WFCORE-4510 -- the effective endpoint configuration is from the root subsystem resource,
    // not from the placeholder configuration=endpoint child resource.
    ModelNode endpointModel = resource.getModel();
    String workerName = WORKER.resolveModelAttribute(context, endpointModel).asString();

    final OptionMap map = EndpointConfigFactory.populate(context, endpointModel);

    // create endpoint
    final String nodeName = WildFlySecurityManager.getPropertyPrivileged(RemotingExtension.NODE_NAME_PROPERTY, null);

    // In case of a managed server the subsystem endpoint might already be installed {@see DomainServerCommunicationServices}
    if (context.getProcessType() == ProcessType.DOMAIN_SERVER) {
        final ServiceController<?> controller = context.getServiceRegistry(false).getService(RemotingServices.SUBSYSTEM_ENDPOINT);
        if (controller != null) {
            // if installed, just skip the rest
            return;
        }
    }

    final CapabilityServiceBuilder<?> builder = context.getCapabilityServiceTarget().addCapability(REMOTING_ENDPOINT_CAPABILITY);
    final Consumer<Endpoint> endpointConsumer = builder.provides(REMOTING_ENDPOINT_CAPABILITY);
    final Supplier<XnioWorker> workerSupplier = builder.requiresCapability(IO_WORKER_CAPABILITY_NAME, XnioWorker.class, workerName);
    builder.setInstance(new EndpointService(endpointConsumer, workerSupplier, nodeName, EndpointService.EndpointType.SUBSYSTEM, map));
    builder.install();
}
 
Example #21
Source Project: wildfly-core   Author: wildfly   File: NativeManagementAddHandler.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private static OptionMap createConnectorOptions(final NativeInterfaceCommonPolicy commonPolicy) throws OperationFailedException {
    Builder builder = OptionMap.builder();

    builder.addAll(NativeManagementServices.CONNECTION_OPTIONS);
    builder.addAll(commonPolicy.getConnectorOptions());

    return builder.getMap();
}
 
Example #22
Source Project: tutorials   Author: eugenp   File: WebConfigurerTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testUndertowHttp2Enabled() {
    props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0);
    UndertowServletWebServerFactory container = new UndertowServletWebServerFactory();
    webConfigurer.customize(container);
    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue();
}
 
Example #23
Source Project: cubeai   Author: cube-ai   File: WebConfigurerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testUndertowHttp2Enabled() {
    props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue();
}
 
Example #24
Source Project: cubeai   Author: cube-ai   File: WebConfigurerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomizeServletContainer() {
    env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
    assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8");
    assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8");

    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull();
}
 
Example #25
public AbstractChannelOpenListenerService(final Supplier<Endpoint> endpointSupplier,
                                          final Supplier<ManagementChannelRegistryService> registrySupplier,
                                          final String channelName, final OptionMap optionMap) {
    this.endpointSupplier = endpointSupplier;
    this.registrySupplier = registrySupplier;
    this.channelName = channelName;
    this.optionMap = optionMap;
}
 
Example #26
Source Project: jhipster   Author: jhipster   File: UndertowSSLConfigurationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testUndertowSSLConfigurationOK() {
    //Prepare
    UndertowServletWebServerFactory undertowServletWebServerFactory = new UndertowServletWebServerFactory();

    //Execute
    UndertowSSLConfiguration undertowSSLConfiguration = new UndertowSSLConfiguration(undertowServletWebServerFactory);

    //Verify
    Undertow.Builder builder = Undertow.builder();
    undertowServletWebServerFactory.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "socketOptions");
    assertThat(undertowServletWebServerFactory).isNotNull();
    assertThat(serverOptions.getMap().get(UndertowOptions.SSL_USER_CIPHER_SUITES_ORDER)).isTrue();
}
 
Example #27
Source Project: java-technology-stack   Author: codeEngraver   File: UndertowXhrTransport.java    License: MIT License 5 votes vote down vote up
public UndertowXhrTransport(OptionMap optionMap) throws IOException {
	Assert.notNull(optionMap, "OptionMap is required");
	this.optionMap = optionMap;
	this.httpClient = UndertowClient.getInstance();
	this.worker = Xnio.getInstance().createWorker(optionMap);
	this.bufferPool = new DefaultByteBufferPool(false, 1024, -1, 2);
}
 
Example #28
Source Project: wildfly-core   Author: wildfly   File: NativeManagementAddHandler.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected List<ServiceName> installServices(OperationContext context, NativeInterfaceCommonPolicy commonPolicy, ModelNode model) throws OperationFailedException {
    populateHostControllerInfo(hostControllerInfo, context, model);

    final ServiceTarget serviceTarget = context.getServiceTarget();

    final boolean onDemand = context.isBooting();
    NativeManagementServices.installRemotingServicesIfNotInstalled(serviceTarget, hostControllerInfo.getLocalHostName(), context.getServiceRegistry(false), onDemand);

    OptionMap options = createConnectorOptions(commonPolicy);

    final ServiceName nativeManagementInterfaceBinding = context.getCapabilityServiceName("org.wildfly.network.interface",
            hostControllerInfo.getNativeManagementInterface(), NetworkInterfaceBinding.class);

    final String securityRealm = commonPolicy.getSecurityRealm();
    final String saslAuthenticationFactory = commonPolicy.getSaslAuthenticationFactory();
    if (saslAuthenticationFactory == null && securityRealm == null) {
        ROOT_LOGGER.nativeManagementInterfaceIsUnsecured();
    }

    ServiceName securityRealmName = securityRealm != null ? SecurityRealm.ServiceUtil.createServiceName(securityRealm) : null;
    ServiceName saslAuthenticationFactoryName = saslAuthenticationFactory != null ? context.getCapabilityServiceName(
            SASL_AUTHENTICATION_FACTORY_CAPABILITY, saslAuthenticationFactory, SaslAuthenticationFactory.class) : null;
    String sslContext = commonPolicy.getSSLContext();
    ServiceName sslContextName = sslContext != null ? context.getCapabilityServiceName(SSL_CONTEXT_CAPABILITY, sslContext, SSLContext.class) : null;

    NativeManagementServices.installManagementWorkerService(serviceTarget, context.getServiceRegistry(false));
    ManagementRemotingServices.installDomainConnectorServices(context, serviceTarget, ManagementRemotingServices.MANAGEMENT_ENDPOINT,
            nativeManagementInterfaceBinding, hostControllerInfo.getNativeManagementPort(), options, securityRealmName, saslAuthenticationFactoryName, sslContextName);
    return Arrays.asList(REMOTING_BASE.append("server", MANAGEMENT_CONNECTOR), nativeManagementInterfaceBinding);
}
 
Example #29
Source Project: lams   Author: lamsfoundation   File: ModClusterContainer.java    License: GNU General Public License v2.0 5 votes vote down vote up
ModClusterContainer(final ModCluster modCluster, final XnioSsl xnioSsl, final UndertowClient client, OptionMap clientOptions) {
    this.xnioSsl = xnioSsl;
    this.client = client;
    this.modCluster = modCluster;
    this.clientOptions = clientOptions;
    this.healthChecker = modCluster.getHealthChecker();
    this.proxyClient = new ModClusterProxyClient(null, this);
    this.removeBrokenNodesThreshold = removeThreshold(modCluster.getHealthCheckInterval(), modCluster.getRemoveBrokenNodes());
}
 
Example #30
Source Project: tutorials   Author: eugenp   File: WebConfigurerTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testUndertowHttp2Enabled() {
    props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0);
    UndertowServletWebServerFactory container = new UndertowServletWebServerFactory();
    webConfigurer.customize(container);
    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue();
}