Search in sources :

Example 31 with OptionMap

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

the class HttpsListenerService method startListening.

@Override
protected void startListening(XnioWorker worker, InetSocketAddress socketAddress, ChannelListener<AcceptingChannel<StreamConnection>> acceptListener) throws IOException {
    SSLContext sslContext = sslContextSupplier.get();
    Builder builder = OptionMap.builder().addAll(commonOptions);
    builder.addAll(socketOptions);
    builder.set(Options.USE_DIRECT_BUFFERS, true);
    if (cipherSuites != null) {
        String[] cipherList = CipherSuiteSelector.fromString(cipherSuites).evaluate(sslContext.getSupportedSSLParameters().getCipherSuites());
        builder.setSequence((Option<Sequence<String>>) HttpsListenerResourceDefinition.ENABLED_CIPHER_SUITES.getOption(), cipherList);
    }
    OptionMap combined = builder.getMap();
    XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), combined, sslContext);
    sslServer = xnioSsl.createSslConnectionServer(worker, socketAddress, (ChannelListener) acceptListener, combined);
    sslServer.resumeAccepts();
    UndertowLogger.ROOT_LOGGER.listenerStarted("HTTPS", getName(), NetworkUtils.formatIPAddressForURI(socketAddress.getAddress()), socketAddress.getPort());
}
Also used : ChannelListener(org.xnio.ChannelListener) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) Builder(org.xnio.OptionMap.Builder) OptionMap(org.xnio.OptionMap) SSLContext(javax.net.ssl.SSLContext) Sequence(org.xnio.Sequence) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl)

Example 32 with OptionMap

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

the class ListenerAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = context.getCurrentAddress();
    final PathAddress parent = address.getParent();
    final String name = context.getCurrentAddressValue();
    final String bindingRef = ListenerResourceDefinition.SOCKET_BINDING.resolveModelAttribute(context, model).asString();
    final String workerName = ListenerResourceDefinition.WORKER.resolveModelAttribute(context, model).asString();
    final String bufferPoolName = ListenerResourceDefinition.BUFFER_POOL.resolveModelAttribute(context, model).asString();
    final boolean enabled = ListenerResourceDefinition.ENABLED.resolveModelAttribute(context, model).asBoolean();
    final boolean peerHostLookup = ListenerResourceDefinition.RESOLVE_PEER_ADDRESS.resolveModelAttribute(context, model).asBoolean();
    final boolean secure = ListenerResourceDefinition.SECURE.resolveModelAttribute(context, model).asBoolean();
    OptionMap listenerOptions = OptionList.resolveOptions(context, model, ListenerResourceDefinition.LISTENER_OPTIONS);
    OptionMap socketOptions = OptionList.resolveOptions(context, model, ListenerResourceDefinition.SOCKET_OPTIONS);
    String serverName = parent.getLastElement().getValue();
    final ServiceName listenerServiceName = UndertowService.listenerName(name);
    final ListenerService service = createService(name, serverName, context, model, listenerOptions, socketOptions);
    if (peerHostLookup) {
        service.addWrapperHandler(new HandlerWrapper() {

            @Override
            public HttpHandler wrap(HttpHandler handler) {
                return new PeerNameResolvingHandler(handler);
            }
        });
    }
    service.setEnabled(enabled);
    if (secure) {
        service.addWrapperHandler(MarkSecureHandler.WRAPPER);
    }
    List<String> disallowedMethods = ListenerResourceDefinition.DISALLOWED_METHODS.unwrap(context, model);
    if (!disallowedMethods.isEmpty()) {
        final Set<HttpString> methodSet = new HashSet<>();
        for (String i : disallowedMethods) {
            methodSet.add(new HttpString(i.trim()));
        }
        service.addWrapperHandler(new HandlerWrapper() {

            @Override
            public HttpHandler wrap(HttpHandler handler) {
                return new DisallowedMethodsHandler(handler, methodSet);
            }
        });
    }
    final ServiceName socketBindingServiceName = context.getCapabilityServiceName(ListenerResourceDefinition.SOCKET_CAPABILITY, bindingRef, SocketBinding.class);
    final ServiceName workerServiceName = context.getCapabilityServiceName(ListenerResourceDefinition.IO_WORKER_CAPABILITY, workerName, XnioWorker.class);
    final ServiceName bufferPoolServiceName = context.getCapabilityServiceName(ListenerResourceDefinition.IO_BUFFER_POOL_CAPABILITY, bufferPoolName, Pool.class);
    final ServiceBuilder<? extends UndertowListener> serviceBuilder = context.getServiceTarget().addService(listenerServiceName, service);
    serviceBuilder.addDependency(workerServiceName, XnioWorker.class, service.getWorker()).addDependency(socketBindingServiceName, SocketBinding.class, service.getBinding()).addDependency(bufferPoolServiceName, (Injector) service.getBufferPool()).addDependency(UndertowService.SERVER.append(serverName), Server.class, service.getServerService()).addAliases(ListenerResourceDefinition.LISTENER_CAPABILITY.getCapabilityServiceName(name));
    configureAdditionalDependencies(context, serviceBuilder, model, service);
    serviceBuilder.install();
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) HttpHandler(io.undertow.server.HttpHandler) DisallowedMethodsHandler(io.undertow.server.handlers.DisallowedMethodsHandler) PeerNameResolvingHandler(io.undertow.server.handlers.PeerNameResolvingHandler) HttpString(io.undertow.util.HttpString) HandlerWrapper(io.undertow.server.HandlerWrapper) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) OptionMap(org.xnio.OptionMap) HashSet(java.util.HashSet) HttpString(io.undertow.util.HttpString)

Example 33 with OptionMap

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

the class AjpListenerAdd method createService.

@Override
ListenerService createService(String name, final String serverName, final OperationContext context, ModelNode model, OptionMap listenerOptions, OptionMap socketOptions) throws OperationFailedException {
    ModelNode schemeNode = AjpListenerResourceDefinition.SCHEME.resolveModelAttribute(context, model);
    String scheme = null;
    if (schemeNode.isDefined()) {
        scheme = schemeNode.asString();
    }
    OptionMap.Builder listenerBuilder = OptionMap.builder().addAll(listenerOptions);
    AjpListenerResourceDefinition.MAX_AJP_PACKET_SIZE.resolveOption(context, model, listenerBuilder);
    return new AjpListenerService(name, scheme, listenerBuilder.getMap(), socketOptions);
}
Also used : OptionMap(org.xnio.OptionMap) ModelNode(org.jboss.dmr.ModelNode)

Example 34 with OptionMap

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

the class UndertowConnectorTestCase method getType.

@Test
public void getType() {
    OptionMap options = OptionMap.builder().getMap();
    assertSame(Connector.Type.AJP, new UndertowConnector(new AjpListenerService("", "", options, OptionMap.EMPTY)).getType());
    assertSame(Connector.Type.HTTP, new UndertowConnector(new HttpListenerService("", "", options, OptionMap.EMPTY, false, false)).getType());
    assertSame(Connector.Type.HTTPS, new UndertowConnector(new HttpsListenerService("", "", options, null, OptionMap.EMPTY)).getType());
}
Also used : OptionMap(org.xnio.OptionMap) AjpListenerService(org.wildfly.extension.undertow.AjpListenerService) HttpListenerService(org.wildfly.extension.undertow.HttpListenerService) HttpsListenerService(org.wildfly.extension.undertow.HttpsListenerService) Test(org.junit.Test)

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