Search in sources :

Example 11 with OptionMap

use of org.xnio.OptionMap in project undertow by undertow-io.

the class ProgramaticAutobahnServer method run.

public void run() {
    Xnio xnio = Xnio.getInstance();
    try {
        XnioWorker worker = xnio.createWorker(OptionMap.builder().set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
        OptionMap serverOptions = OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
        DefaultByteBufferPool pool = new DefaultByteBufferPool(true, 8192);
        HttpOpenListener openListener = new HttpOpenListener(pool);
        ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
        AcceptingChannel<StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
        server.resumeAccepts();
        final ServletContainer container = ServletContainer.Factory.newInstance();
        DeploymentInfo builder = new DeploymentInfo().setClassLoader(ProgramaticAutobahnServer.class.getClassLoader()).setContextPath("/").setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war").addFilter(new FilterInfo("filter", JsrWebSocketFilter.class)).addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(pool).setWorker(worker).setDispatchToWorkerThread(true).addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/")).addExtension(new PerMessageDeflateHandshake()));
        DeploymentManager manager = container.addDeployment(builder);
        manager.deploy();
        openListener.setRootHandler(manager.start());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) DeploymentManager(io.undertow.servlet.api.DeploymentManager) XnioWorker(org.xnio.XnioWorker) InetSocketAddress(java.net.InetSocketAddress) ServerEndpointConfigImpl(io.undertow.websockets.jsr.ServerEndpointConfigImpl) StreamConnection(org.xnio.StreamConnection) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Xnio(org.xnio.Xnio) JsrWebSocketFilter(io.undertow.websockets.jsr.JsrWebSocketFilter) OptionMap(org.xnio.OptionMap) ServletContainer(io.undertow.servlet.api.ServletContainer) PerMessageDeflateHandshake(io.undertow.websockets.extensions.PerMessageDeflateHandshake) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) FilterInfo(io.undertow.servlet.api.FilterInfo)

Example 12 with OptionMap

use of org.xnio.OptionMap in project undertow by undertow-io.

the class MCMPHandler method checkHostUp.

/**
     * Check whether a host is up.
     *
     * @param scheme      the scheme
     * @param host        the host
     * @param port        the port
     * @param exchange    the http server exchange
     * @param callback    the ping callback
     */
protected void checkHostUp(final String scheme, final String host, final int port, final HttpServerExchange exchange, final NodePingUtil.PingCallback callback) {
    // TODO
    final XnioSsl xnioSsl = null;
    final OptionMap options = OptionMap.builder().set(Options.TCP_NODELAY, true).getMap();
    try {
        // http, ajp and maybe more in future
        if ("ajp".equalsIgnoreCase(scheme) || "http".equalsIgnoreCase(scheme)) {
            final URI uri = new URI(scheme, null, host, port, "/", null, null);
            NodePingUtil.pingHttpClient(uri, callback, exchange, container.getClient(), xnioSsl, options);
        } else {
            final InetSocketAddress address = new InetSocketAddress(host, port);
            NodePingUtil.pingHost(address, exchange, callback, options);
        }
    } catch (URISyntaxException e) {
        callback.failed();
    }
}
Also used : XnioSsl(org.xnio.ssl.XnioSsl) InetSocketAddress(java.net.InetSocketAddress) OptionMap(org.xnio.OptionMap) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 13 with OptionMap

use of org.xnio.OptionMap in project wildfly by wildfly.

the class EJBClientDescriptorMetaDataProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // we only process top level deployment units
    if (deploymentUnit.getParent() != null) {
        return;
    }
    final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = deploymentUnit.getAttachment(Attachments.EJB_CLIENT_METADATA);
    // no explicit EJB client configuration in this deployment, so nothing to do
    if (ejbClientDescriptorMetaData == null) {
        return;
    }
    // profile and remoting-ejb-receivers cannot be used together
    checkDescriptorConfiguration(ejbClientDescriptorMetaData);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (module == null) {
        return;
    }
    // install the descriptor based EJB client context service
    final ServiceName ejbClientContextServiceName = EJBClientContextService.DEPLOYMENT_BASE_SERVICE_NAME.append(deploymentUnit.getName());
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    // create the service
    final EJBClientContextService service = new EJBClientContextService();
    // add the service
    final ServiceBuilder<EJBClientContextService> serviceBuilder = serviceTarget.addService(ejbClientContextServiceName, service);
    if (appclient) {
        serviceBuilder.addDependency(EJBClientContextService.APP_CLIENT_URI_SERVICE_NAME, URI.class, service.getAppClientUri());
    }
    serviceBuilder.addDependency(EJBClientConfiguratorService.SERVICE_NAME, EJBClientConfiguratorService.class, service.getConfiguratorServiceInjector());
    final Injector<RemotingProfileService> profileServiceInjector = new Injector<RemotingProfileService>() {

        final Injector<EJBTransportProvider> injector = service.getLocalProviderInjector();

        boolean injected = false;

        public void inject(final RemotingProfileService value) throws InjectionException {
            final EJBTransportProvider provider = value.getLocalTransportProviderInjector().getOptionalValue();
            if (provider != null) {
                injected = true;
                injector.inject(provider);
            }
        }

        public void uninject() {
            if (injected) {
                injected = false;
                injector.uninject();
            }
        }
    };
    final String profile = ejbClientDescriptorMetaData.getProfile();
    final ServiceName profileServiceName;
    if (profile != null) {
        profileServiceName = RemotingProfileService.BASE_SERVICE_NAME.append(profile);
        serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, profileServiceInjector);
        serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, service.getProfileServiceInjector());
    } else {
        // if descriptor defines list of ejb-receivers instead of profile then we create internal ProfileService for this
        // application which contains defined receivers
        profileServiceName = ejbClientContextServiceName.append(INTERNAL_REMOTING_PROFILE);
        final Map<String, RemotingProfileService.ConnectionSpec> map = new HashMap<>();
        final RemotingProfileService profileService = new RemotingProfileService(Collections.emptyList(), map);
        final ServiceBuilder<RemotingProfileService> profileServiceBuilder = serviceTarget.addService(profileServiceName, profileService);
        if (ejbClientDescriptorMetaData.isLocalReceiverExcluded() != Boolean.TRUE) {
            final Boolean passByValue = ejbClientDescriptorMetaData.isLocalReceiverPassByValue();
            profileServiceBuilder.addDependency(passByValue == Boolean.TRUE ? LocalTransportProvider.BY_VALUE_SERVICE_NAME : LocalTransportProvider.BY_REFERENCE_SERVICE_NAME, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
        }
        final Collection<EJBClientDescriptorMetaData.RemotingReceiverConfiguration> receiverConfigurations = ejbClientDescriptorMetaData.getRemotingReceiverConfigurations();
        for (EJBClientDescriptorMetaData.RemotingReceiverConfiguration receiverConfiguration : receiverConfigurations) {
            final String connectionRef = receiverConfiguration.getOutboundConnectionRef();
            final long connectTimeout = receiverConfiguration.getConnectionTimeout();
            final Properties channelCreationOptions = receiverConfiguration.getChannelCreationOptions();
            final OptionMap optionMap = getOptionMapFromProperties(channelCreationOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
            final InjectedValue<AbstractOutboundConnectionService> injector = new InjectedValue<>();
            profileServiceBuilder.addDependency(AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionRef), AbstractOutboundConnectionService.class, injector);
            final RemotingProfileService.ConnectionSpec connectionSpec = new RemotingProfileService.ConnectionSpec(connectionRef, injector, optionMap, connectTimeout);
            map.put(connectionRef, connectionSpec);
        }
        profileServiceBuilder.install();
        serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, profileServiceInjector);
        serviceBuilder.addDependency(profileServiceName, RemotingProfileService.class, service.getProfileServiceInjector());
    }
    // these items are the same no matter how we were configured
    final String deploymentNodeSelectorClassName = ejbClientDescriptorMetaData.getDeploymentNodeSelector();
    if (deploymentNodeSelectorClassName != null) {
        final DeploymentNodeSelector deploymentNodeSelector;
        try {
            deploymentNodeSelector = module.getClassLoader().loadClass(deploymentNodeSelectorClassName).asSubclass(DeploymentNodeSelector.class).getConstructor().newInstance();
        } catch (Exception e) {
            throw EjbLogger.ROOT_LOGGER.failedToCreateDeploymentNodeSelector(e, deploymentNodeSelectorClassName);
        }
        service.setDeploymentNodeSelector(deploymentNodeSelector);
    }
    final long invocationTimeout = ejbClientDescriptorMetaData.getInvocationTimeout();
    service.setInvocationTimeout(invocationTimeout);
    // clusters
    final Collection<EJBClientDescriptorMetaData.ClusterConfig> clusterConfigs = ejbClientDescriptorMetaData.getClusterConfigs();
    if (!clusterConfigs.isEmpty()) {
        final List<EJBClientCluster> clientClusters = new ArrayList<>(clusterConfigs.size());
        AuthenticationContext clustersAuthenticationContext = AuthenticationContext.empty();
        for (EJBClientDescriptorMetaData.ClusterConfig clusterConfig : clusterConfigs) {
            MatchRule defaultRule = MatchRule.ALL.matchAbstractType("ejb", "jboss");
            AuthenticationConfiguration defaultAuthenticationConfiguration = AuthenticationConfiguration.EMPTY;
            final EJBClientCluster.Builder clientClusterBuilder = new EJBClientCluster.Builder();
            final String clusterName = clusterConfig.getClusterName();
            clientClusterBuilder.setName(clusterName);
            defaultRule = defaultRule.matchProtocol("cluster");
            defaultRule = defaultRule.matchUrnName(clusterName);
            final long maxAllowedConnectedNodes = clusterConfig.getMaxAllowedConnectedNodes();
            clientClusterBuilder.setMaximumConnectedNodes(maxAllowedConnectedNodes);
            final String clusterNodeSelectorClassName = clusterConfig.getNodeSelector();
            if (clusterNodeSelectorClassName != null) {
                final ClusterNodeSelector clusterNodeSelector;
                try {
                    clusterNodeSelector = module.getClassLoader().loadClass(clusterNodeSelectorClassName).asSubclass(ClusterNodeSelector.class).getConstructor().newInstance();
                } catch (Exception e) {
                    throw EjbLogger.ROOT_LOGGER.failureDuringLoadOfClusterNodeSelector(clusterNodeSelectorClassName, clusterName, e);
                }
                clientClusterBuilder.setClusterNodeSelector(clusterNodeSelector);
            }
            final Properties clusterChannelCreationOptions = clusterConfig.getChannelCreationOptions();
            final OptionMap clusterChannelCreationOptionMap = getOptionMapFromProperties(clusterChannelCreationOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
            final Properties clusterConnectionOptions = clusterConfig.getConnectionOptions();
            final OptionMap clusterConnectionOptionMap = getOptionMapFromProperties(clusterConnectionOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
            final long clusterConnectTimeout = clusterConfig.getConnectTimeout();
            clientClusterBuilder.setConnectTimeoutMilliseconds(clusterConnectTimeout);
            final String clusterSecurityRealm = clusterConfig.getSecurityRealm();
            final String clusterUserName = clusterConfig.getUserName();
            CallbackHandler callbackHandler = getCallbackHandler(phaseContext.getServiceRegistry(), clusterUserName, clusterSecurityRealm);
            if (callbackHandler != null) {
                defaultAuthenticationConfiguration = defaultAuthenticationConfiguration.useCallbackHandler(callbackHandler);
            }
            if (clusterConnectionOptionMap != null) {
                RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(clusterConnectionOptionMap, defaultAuthenticationConfiguration);
            }
            clustersAuthenticationContext = clustersAuthenticationContext.with(defaultRule, defaultAuthenticationConfiguration);
            final Collection<EJBClientDescriptorMetaData.ClusterNodeConfig> clusterNodeConfigs = clusterConfig.getClusterNodeConfigs();
            for (EJBClientDescriptorMetaData.ClusterNodeConfig clusterNodeConfig : clusterNodeConfigs) {
                MatchRule nodeRule = MatchRule.ALL.matchAbstractType("ejb", "jboss");
                AuthenticationConfiguration nodeAuthenticationConfiguration = AuthenticationConfiguration.EMPTY;
                final String nodeName = clusterNodeConfig.getNodeName();
                nodeRule = nodeRule.matchProtocol("node");
                nodeRule = nodeRule.matchUrnName(nodeName);
                final Properties channelCreationOptions = clusterNodeConfig.getChannelCreationOptions();
                final Properties connectionOptions = clusterNodeConfig.getConnectionOptions();
                final OptionMap connectionOptionMap = getOptionMapFromProperties(connectionOptions, EJBClientDescriptorMetaDataProcessor.class.getClassLoader());
                final long connectTimeout = clusterNodeConfig.getConnectTimeout();
                final String securityRealm = clusterNodeConfig.getSecurityRealm();
                final String userName = clusterNodeConfig.getUserName();
                CallbackHandler nodeCallbackHandler = getCallbackHandler(phaseContext.getServiceRegistry(), userName, securityRealm);
                if (nodeCallbackHandler != null) {
                    nodeAuthenticationConfiguration = nodeAuthenticationConfiguration.useCallbackHandler(nodeCallbackHandler);
                }
                if (connectionOptionMap != null) {
                    RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(connectionOptionMap, nodeAuthenticationConfiguration);
                }
                clustersAuthenticationContext = clustersAuthenticationContext.with(0, nodeRule, nodeAuthenticationConfiguration);
            }
            final EJBClientCluster clientCluster = clientClusterBuilder.build();
            clientClusters.add(clientCluster);
        }
        service.setClientClusters(clientClusters);
        service.setClustersAuthenticationContext(clustersAuthenticationContext);
    }
    // install the service
    serviceBuilder.install();
    EjbLogger.DEPLOYMENT_LOGGER.debugf("Deployment unit %s will use %s as the EJB client context service", deploymentUnit, ejbClientContextServiceName);
    // attach the service name of this EJB client context to the deployment unit
    phaseContext.addDeploymentDependency(ejbClientContextServiceName, EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE);
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_CLIENT_CONTEXT_SERVICE_NAME, ejbClientContextServiceName);
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_REMOTING_PROFILE_SERVICE_NAME, profileServiceName);
}
Also used : AbstractOutboundConnectionService(org.jboss.as.remoting.AbstractOutboundConnectionService) InjectedValue(org.jboss.msc.value.InjectedValue) CallbackHandler(javax.security.auth.callback.CallbackHandler) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) HashMap(java.util.HashMap) EJBClientContextService(org.jboss.as.ejb3.remote.EJBClientContextService) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ArrayList(java.util.ArrayList) MatchRule(org.wildfly.security.auth.client.MatchRule) Properties(java.util.Properties) DeploymentNodeSelector(org.jboss.ejb.client.DeploymentNodeSelector) ClusterNodeSelector(org.jboss.ejb.client.ClusterNodeSelector) EJBClientDescriptorMetaData(org.jboss.as.ee.metadata.EJBClientDescriptorMetaData) Injector(org.jboss.msc.inject.Injector) RemotingProfileService(org.jboss.as.ejb3.remote.RemotingProfileService) EJBClientCluster(org.jboss.ejb.client.EJBClientCluster) AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) ServiceTarget(org.jboss.msc.service.ServiceTarget) InjectionException(org.jboss.msc.inject.InjectionException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBTransportProvider(org.jboss.ejb.client.EJBTransportProvider) ServiceName(org.jboss.msc.service.ServiceName) OptionMap(org.xnio.OptionMap) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 14 with OptionMap

use of org.xnio.OptionMap in project wildfly by wildfly.

the class RemotingProfileAdd method createChannelOptionMap.

private OptionMap createChannelOptionMap(final OperationContext context, final ModelNode channelCreationOptionsNode) throws OperationFailedException {
    final OptionMap optionMap;
    if (channelCreationOptionsNode.isDefined()) {
        final OptionMap.Builder optionMapBuilder = OptionMap.builder();
        final ClassLoader loader = this.getClass().getClassLoader();
        for (final Property optionProperty : channelCreationOptionsNode.asPropertyList()) {
            final String name = optionProperty.getName();
            final ModelNode propValueModel = optionProperty.getValue();
            final String type = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE.resolveModelAttribute(context, propValueModel).asString();
            final String optionClassName = this.getClassNameForChannelOptionType(type);
            final String fullyQualifiedOptionName = optionClassName + "." + name;
            final Option option = Option.fromString(fullyQualifiedOptionName, loader);
            final String value = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE.resolveModelAttribute(context, propValueModel).asString();
            optionMapBuilder.set(option, option.parseValue(value, loader));
        }
        optionMap = optionMapBuilder.getMap();
    } else {
        optionMap = OptionMap.EMPTY;
    }
    return optionMap;
}
Also used : OptionMap(org.xnio.OptionMap) Option(org.xnio.Option) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 15 with OptionMap

use of org.xnio.OptionMap in project undertow by undertow-io.

the class Undertow method start.

public synchronized void start() {
    UndertowLogger.ROOT_LOGGER.debugf("starting undertow server %s", this);
    xnio = Xnio.getInstance(Undertow.class.getClassLoader());
    channels = new ArrayList<>();
    try {
        if (internalWorker) {
            worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_IO_THREADS, ioThreads).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, workerThreads).set(Options.WORKER_TASK_MAX_THREADS, workerThreads).set(Options.TCP_NODELAY, true).set(Options.CORK, true).addAll(workerOptions).getMap());
        }
        OptionMap socketOptions = OptionMap.builder().set(Options.WORKER_IO_THREADS, worker.getIoThreadCount()).set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).set(Options.BALANCING_TOKENS, 1).set(Options.BALANCING_CONNECTIONS, 2).set(Options.BACKLOG, 1000).addAll(this.socketOptions).getMap();
        OptionMap serverOptions = OptionMap.builder().set(UndertowOptions.NO_REQUEST_TIMEOUT, 60 * 1000).addAll(this.serverOptions).getMap();
        ByteBufferPool buffers = new DefaultByteBufferPool(directBuffers, bufferSize, -1, 4);
        listenerInfo = new ArrayList<>();
        for (ListenerConfig listener : listeners) {
            UndertowLogger.ROOT_LOGGER.debugf("Configuring listener with protocol %s for interface %s and port %s", listener.type, listener.host, listener.port);
            final HttpHandler rootHandler = listener.rootHandler != null ? listener.rootHandler : this.rootHandler;
            if (listener.type == ListenerType.AJP) {
                AjpOpenListener openListener = new AjpOpenListener(buffers, serverOptions);
                openListener.setRootHandler(rootHandler);
                ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener);
                OptionMap socketOptionsWithOverrides = OptionMap.builder().addAll(socketOptions).addAll(listener.overrideSocketOptions).getMap();
                AcceptingChannel<? extends StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), acceptListener, socketOptionsWithOverrides);
                server.resumeAccepts();
                channels.add(server);
                listenerInfo.add(new ListenerInfo("ajp", server.getLocalAddress(), null, openListener));
            } else {
                OptionMap undertowOptions = OptionMap.builder().set(UndertowOptions.BUFFER_PIPELINED_DATA, true).addAll(serverOptions).getMap();
                if (listener.type == ListenerType.HTTP) {
                    HttpOpenListener openListener = new HttpOpenListener(buffers, undertowOptions);
                    openListener.setRootHandler(rootHandler);
                    ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener);
                    OptionMap socketOptionsWithOverrides = OptionMap.builder().addAll(socketOptions).addAll(listener.overrideSocketOptions).getMap();
                    AcceptingChannel<? extends StreamConnection> server = worker.createStreamConnectionServer(new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), acceptListener, socketOptionsWithOverrides);
                    server.resumeAccepts();
                    channels.add(server);
                    listenerInfo.add(new ListenerInfo("http", server.getLocalAddress(), null, openListener));
                } else if (listener.type == ListenerType.HTTPS) {
                    OpenListener openListener;
                    HttpOpenListener httpOpenListener = new HttpOpenListener(buffers, undertowOptions);
                    httpOpenListener.setRootHandler(rootHandler);
                    boolean http2 = serverOptions.get(UndertowOptions.ENABLE_HTTP2, false);
                    if (http2) {
                        AlpnOpenListener alpn = new AlpnOpenListener(buffers, undertowOptions, httpOpenListener);
                        if (http2) {
                            Http2OpenListener http2Listener = new Http2OpenListener(buffers, undertowOptions);
                            http2Listener.setRootHandler(rootHandler);
                            alpn.addProtocol(Http2OpenListener.HTTP2, http2Listener, 10);
                            alpn.addProtocol(Http2OpenListener.HTTP2_14, http2Listener, 7);
                        }
                        openListener = alpn;
                    } else {
                        openListener = httpOpenListener;
                    }
                    ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener);
                    XnioSsl xnioSsl;
                    if (listener.sslContext != null) {
                        xnioSsl = new UndertowXnioSsl(xnio, OptionMap.create(Options.USE_DIRECT_BUFFERS, true), listener.sslContext);
                    } else {
                        xnioSsl = new UndertowXnioSsl(xnio, OptionMap.create(Options.USE_DIRECT_BUFFERS, true), JsseSslUtils.createSSLContext(listener.keyManagers, listener.trustManagers, new SecureRandom(), OptionMap.create(Options.USE_DIRECT_BUFFERS, true)));
                    }
                    OptionMap socketOptionsWithOverrides = OptionMap.builder().addAll(socketOptions).addAll(listener.overrideSocketOptions).getMap();
                    AcceptingChannel<SslConnection> sslServer = xnioSsl.createSslConnectionServer(worker, new InetSocketAddress(Inet4Address.getByName(listener.host), listener.port), (ChannelListener) acceptListener, socketOptionsWithOverrides);
                    sslServer.resumeAccepts();
                    channels.add(sslServer);
                    listenerInfo.add(new ListenerInfo("https", sslServer.getLocalAddress(), listener.sslContext, openListener));
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) ByteBufferPool(io.undertow.connector.ByteBufferPool) AlpnOpenListener(io.undertow.server.protocol.http.AlpnOpenListener) HttpHandler(io.undertow.server.HttpHandler) ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) InetSocketAddress(java.net.InetSocketAddress) Http2OpenListener(io.undertow.server.protocol.http2.Http2OpenListener) AlpnOpenListener(io.undertow.server.protocol.http.AlpnOpenListener) AjpOpenListener(io.undertow.server.protocol.ajp.AjpOpenListener) OpenListener(io.undertow.server.OpenListener) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) SecureRandom(java.security.SecureRandom) Http2OpenListener(io.undertow.server.protocol.http2.Http2OpenListener) StreamConnection(org.xnio.StreamConnection) AjpOpenListener(io.undertow.server.protocol.ajp.AjpOpenListener) OptionMap(org.xnio.OptionMap) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) AcceptingChannel(org.xnio.channels.AcceptingChannel)

Aggregations

OptionMap (org.xnio.OptionMap)34 InetSocketAddress (java.net.InetSocketAddress)10 Test (org.junit.Test)10 TestHttpClient (io.undertow.testutils.TestHttpClient)9 HttpResponse (org.apache.http.HttpResponse)8 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)7 ChannelListener (org.xnio.ChannelListener)7 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)6 IOException (java.io.IOException)6 ModelNode (org.jboss.dmr.ModelNode)5 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)4 HttpHandler (io.undertow.server.HttpHandler)4 HttpGet (org.apache.http.client.methods.HttpGet)4 StreamConnection (org.xnio.StreamConnection)4 XnioSsl (org.xnio.ssl.XnioSsl)4 AjpIgnore (io.undertow.testutils.AjpIgnore)3 HttpPost (org.apache.http.client.methods.HttpPost)3 StringEntity (org.apache.http.entity.StringEntity)3 ServiceName (org.jboss.msc.service.ServiceName)3 XnioWorker (org.xnio.XnioWorker)3