Java Code Examples for org.xnio.OptionMap#get()

The following examples show how to use org.xnio.OptionMap#get() . 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 File: UndertowAcceptingSslChannel.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
UndertowAcceptingSslChannel(final UndertowXnioSsl ssl, final AcceptingChannel<? extends StreamConnection> tcpServer, final OptionMap optionMap, final ByteBufferPool applicationBufferPool, final boolean startTls) {
    this.tcpServer = tcpServer;
    this.ssl = ssl;
    this.applicationBufferPool = applicationBufferPool;
    this.startTls = startTls;
    clientAuthMode = optionMap.get(Options.SSL_CLIENT_AUTH_MODE);
    useClientMode = optionMap.get(Options.SSL_USE_CLIENT_MODE, false) ? 1 : 0;
    enableSessionCreation = optionMap.get(Options.SSL_ENABLE_SESSION_CREATION, true) ? 1 : 0;
    final Sequence<String> enabledCipherSuites = optionMap.get(Options.SSL_ENABLED_CIPHER_SUITES);
    cipherSuites = enabledCipherSuites != null ? enabledCipherSuites.toArray(new String[enabledCipherSuites.size()]) : null;
    final Sequence<String> enabledProtocols = optionMap.get(Options.SSL_ENABLED_PROTOCOLS);
    protocols = enabledProtocols != null ? enabledProtocols.toArray(new String[enabledProtocols.size()]) : null;
    //noinspection ThisEscapedInObjectConstruction
    closeSetter = ChannelListeners.<AcceptingChannel<SslConnection>>getDelegatingSetter(tcpServer.getCloseSetter(), this);
    //noinspection ThisEscapedInObjectConstruction
    acceptSetter = ChannelListeners.<AcceptingChannel<SslConnection>>getDelegatingSetter(tcpServer.getAcceptSetter(), this);
    useCipherSuitesOrder = optionMap.get(UndertowOptions.SSL_USER_CIPHER_SUITES_ORDER, false);
}
 
Example 2
Source File: Http2ReceiveListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Http2ReceiveListener(HttpHandler rootHandler, OptionMap undertowOptions, int bufferSize, ConnectorStatisticsImpl connectorStatistics) {
    this.rootHandler = rootHandler;
    this.undertowOptions = undertowOptions;
    this.bufferSize = bufferSize;
    this.connectorStatistics = connectorStatistics;
    this.maxEntitySize = undertowOptions.get(UndertowOptions.MAX_ENTITY_SIZE, UndertowOptions.DEFAULT_MAX_ENTITY_SIZE);
    this.allowEncodingSlash = undertowOptions.get(UndertowOptions.ALLOW_ENCODED_SLASH, false);
    this.decode = undertowOptions.get(UndertowOptions.DECODE_URL, true);
    this.maxParameters = undertowOptions.get(UndertowOptions.MAX_PARAMETERS, UndertowOptions.DEFAULT_MAX_PARAMETERS);
    this.recordRequestStartTime = undertowOptions.get(UndertowOptions.RECORD_REQUEST_START_TIME, false);
    if (undertowOptions.get(UndertowOptions.DECODE_URL, true)) {
        this.encoding = undertowOptions.get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name());
    } else {
        this.encoding = null;
    }
}
 
Example 3
Source File: AjpOpenListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public AjpOpenListener(final ByteBufferPool pool, final OptionMap undertowOptions) {
    this.undertowOptions = undertowOptions;
    this.bufferPool = pool;
    PooledByteBuffer buf = pool.allocate();
    this.bufferSize = buf.getBuffer().remaining();
    buf.close();
    parser = new AjpRequestParser(undertowOptions.get(URL_CHARSET, StandardCharsets.UTF_8.name()), undertowOptions.get(DECODE_URL, true), undertowOptions.get(UndertowOptions.MAX_PARAMETERS, UndertowOptions.DEFAULT_MAX_PARAMETERS), undertowOptions.get(UndertowOptions.MAX_HEADERS, UndertowOptions.DEFAULT_MAX_HEADERS), undertowOptions.get(UndertowOptions.ALLOW_ENCODED_SLASH, false), undertowOptions.get(UndertowOptions.ALLOW_UNESCAPED_CHARACTERS_IN_URL, false));
    connectorStatistics = new ConnectorStatisticsImpl();
    statisticsEnabled = undertowOptions.get(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, false);
}
 
Example 4
Source File: AjpOpenListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setUndertowOptions(final OptionMap undertowOptions) {
    if (undertowOptions == null) {
        throw UndertowMessages.MESSAGES.argumentCannotBeNull("undertowOptions");
    }
    this.undertowOptions = undertowOptions;
    statisticsEnabled = undertowOptions.get(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, false);
    parser = new AjpRequestParser(undertowOptions.get(URL_CHARSET, StandardCharsets.UTF_8.name()), undertowOptions.get(DECODE_URL, true), undertowOptions.get(UndertowOptions.MAX_PARAMETERS, UndertowOptions.DEFAULT_MAX_PARAMETERS), undertowOptions.get(UndertowOptions.MAX_HEADERS, UndertowOptions.DEFAULT_MAX_HEADERS), undertowOptions.get(UndertowOptions.ALLOW_ENCODED_SLASH, false), undertowOptions.get(UndertowOptions.ALLOW_UNESCAPED_CHARACTERS_IN_URL, false));
}
 
Example 5
Source File: Http2OpenListener.java    From lams with 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 6
Source File: Http2OpenListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setUndertowOptions(final OptionMap undertowOptions) {
    if (undertowOptions == null) {
        throw UndertowMessages.MESSAGES.argumentCannotBeNull("undertowOptions");
    }
    this.undertowOptions = undertowOptions;
    statisticsEnabled = undertowOptions.get(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, false);
}
 
Example 7
Source File: HttpOpenListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public HttpOpenListener(final ByteBufferPool pool, final OptionMap undertowOptions) {
    this.undertowOptions = undertowOptions;
    this.bufferPool = pool;
    PooledByteBuffer buf = pool.allocate();
    this.bufferSize = buf.getBuffer().remaining();
    buf.close();
    parser = HttpRequestParser.instance(undertowOptions);
    connectorStatistics = new ConnectorStatisticsImpl();
    statisticsEnabled = undertowOptions.get(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, false);
}
 
Example 8
Source File: HttpOpenListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setUndertowOptions(final OptionMap undertowOptions) {
    if (undertowOptions == null) {
        throw UndertowMessages.MESSAGES.argumentCannotBeNull("undertowOptions");
    }
    this.undertowOptions = undertowOptions;
    this.parser = HttpRequestParser.instance(undertowOptions);
    statisticsEnabled = undertowOptions.get(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, false);
}
 
Example 9
Source File: HttpRequestParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public HttpRequestParser(OptionMap options) {
    maxParameters = options.get(UndertowOptions.MAX_PARAMETERS, UndertowOptions.DEFAULT_MAX_PARAMETERS);
    maxHeaders = options.get(UndertowOptions.MAX_HEADERS, UndertowOptions.DEFAULT_MAX_HEADERS);
    allowEncodedSlash = options.get(UndertowOptions.ALLOW_ENCODED_SLASH, false);
    decode = options.get(UndertowOptions.DECODE_URL, true);
    charset = options.get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name());
    maxCachedHeaderSize = options.get(UndertowOptions.MAX_CACHED_HEADER_SIZE, UndertowOptions.DEFAULT_MAX_CACHED_HEADER_SIZE);
    this.allowUnescapedCharactersInUrl = options.get(UndertowOptions.ALLOW_UNESCAPED_CHARACTERS_IN_URL, false);
}
 
Example 10
Source File: AlpnOpenListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public AlpnOpenListener(ByteBufferPool bufferPool, OptionMap undertowOptions, String fallbackProtocol, DelegateOpenListener fallbackListener) {
    this.bufferPool = bufferPool;
    this.undertowOptions = undertowOptions;
    this.fallbackProtocol = fallbackProtocol;
    statisticsEnabled = undertowOptions.get(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, false);
    if (fallbackProtocol != null && fallbackListener != null) {
        addProtocol(fallbackProtocol, fallbackListener, 0);
    }
}
 
Example 11
Source File: AlpnOpenListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setUndertowOptions(OptionMap undertowOptions) {
    if (undertowOptions == null) {
        throw UndertowMessages.MESSAGES.argumentCannotBeNull("undertowOptions");
    }
    this.undertowOptions = undertowOptions;
    for (Map.Entry<String, ListenerEntry> delegate : listeners.entrySet()) {
        delegate.getValue().listener.setRootHandler(rootHandler);
    }
    statisticsEnabled = undertowOptions.get(UndertowOptions.ENABLE_CONNECTOR_STATISTICS, false);
}
 
Example 12
Source File: AbstractFramedChannel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@link io.undertow.server.protocol.framed.AbstractFramedChannel}
 * 8
 *  @param connectedStreamChannel The {@link org.xnio.channels.ConnectedStreamChannel} over which the Frames should get send and received.
 *                               Be aware that it already must be "upgraded".
 * @param bufferPool             The {@link ByteBufferPool} which will be used to acquire {@link ByteBuffer}'s from.
 * @param framePriority
 * @param settings               The settings
 */
protected AbstractFramedChannel(final StreamConnection connectedStreamChannel, ByteBufferPool bufferPool, FramePriority<C, R, S> framePriority, final PooledByteBuffer readData, OptionMap settings) {
    this.framePriority = framePriority;
    this.maxQueuedBuffers = settings.get(UndertowOptions.MAX_QUEUED_READ_BUFFERS, 10);
    this.settings = settings;
    if (readData != null) {
        if(readData.getBuffer().hasRemaining()) {
            this.readData = new ReferenceCountedPooled(readData, 1);
        } else {
            readData.close();
        }
    }
    if(bufferPool == null) {
        throw UndertowMessages.MESSAGES.argumentCannotBeNull("bufferPool");
    }
    if(connectedStreamChannel == null) {
        throw UndertowMessages.MESSAGES.argumentCannotBeNull("connectedStreamChannel");
    }
    IdleTimeoutConduit idle = createIdleTimeoutChannel(connectedStreamChannel);
    connectedStreamChannel.getSourceChannel().setConduit(idle);
    connectedStreamChannel.getSinkChannel().setConduit(idle);
    this.idleTimeoutConduit = idle;
    this.channel = connectedStreamChannel;
    this.bufferPool = bufferPool;

    closeSetter = new ChannelListener.SimpleSetter<>();
    receiveSetter = new ChannelListener.SimpleSetter<>();
    channel.getSourceChannel().getReadSetter().set(null);
    channel.getSourceChannel().suspendReads();

    channel.getSourceChannel().getReadSetter().set(new FrameReadListener());
    connectedStreamChannel.getSinkChannel().getWriteSetter().set(new FrameWriteListener());
    FrameCloseListener closeListener = new FrameCloseListener();
    connectedStreamChannel.getSinkChannel().getCloseSetter().set(closeListener);
    connectedStreamChannel.getSourceChannel().getCloseSetter().set(closeListener);
}
 
Example 13
Source File: QueryParameterUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static String getQueryParamEncoding(HttpServerExchange exchange) {
    String encoding = null;
    OptionMap undertowOptions = exchange.getConnection().getUndertowOptions();
    if(undertowOptions.get(UndertowOptions.DECODE_URL, true)) {
        encoding = undertowOptions.get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name());
    }
    return encoding;
}
 
Example 14
Source File: Http2Channel.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Http2Channel(StreamConnection connectedStreamChannel, String protocol, ByteBufferPool bufferPool, PooledByteBuffer data, boolean clientSide, boolean fromUpgrade, boolean prefaceRequired, ByteBuffer initialOtherSideSettings, OptionMap settings) {
    super(connectedStreamChannel, bufferPool, new Http2FramePriority(clientSide ? (fromUpgrade ? 3 : 1) : 2), data, settings);
    streamIdCounter = clientSide ? (fromUpgrade ? 3 : 1) : 2;

    pushEnabled = settings.get(UndertowOptions.HTTP2_SETTINGS_ENABLE_PUSH, true);
    this.initialReceiveWindowSize = settings.get(UndertowOptions.HTTP2_SETTINGS_INITIAL_WINDOW_SIZE, DEFAULT_INITIAL_WINDOW_SIZE);
    this.receiveMaxConcurrentStreams = settings.get(UndertowOptions.HTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, -1);

    this.protocol = protocol == null ? Http2OpenListener.HTTP2 : protocol;
    this.maxHeaders = settings.get(UndertowOptions.MAX_HEADERS, clientSide ? -1 : UndertowOptions.DEFAULT_MAX_HEADERS);

    encoderHeaderTableSize = settings.get(UndertowOptions.HTTP2_SETTINGS_HEADER_TABLE_SIZE, Hpack.DEFAULT_TABLE_SIZE);
    receiveMaxFrameSize = settings.get(UndertowOptions.HTTP2_SETTINGS_MAX_FRAME_SIZE, DEFAULT_MAX_FRAME_SIZE);
    maxPadding = settings.get(UndertowOptions.HTTP2_PADDING_SIZE, 0);
    maxHeaderListSize = settings.get(UndertowOptions.HTTP2_SETTINGS_MAX_HEADER_LIST_SIZE, settings.get(UndertowOptions.MAX_HEADER_SIZE, -1));
    if(maxPadding > 0) {
        paddingRandom = new SecureRandom();
    } else {
        paddingRandom = null;
    }

    this.decoder = new HpackDecoder(encoderHeaderTableSize);
    this.encoder = new HpackEncoder(encoderHeaderTableSize);
    if(!prefaceRequired) {
        prefaceCount = PREFACE_BYTES.length;
    }

    if (clientSide) {
        sendPreface();
        prefaceCount = PREFACE_BYTES.length;
        sendSettings();
        initialSettingsSent = true;
        if(fromUpgrade) {
            StreamHolder streamHolder = new StreamHolder((Http2StreamSinkChannel) null);
            streamHolder.sinkClosed = true;
            sendConcurrentStreamsAtomicUpdater.getAndIncrement(this);
            currentStreams.put(1, streamHolder);
        }
    } else if(fromUpgrade) {
        sendSettings();
        initialSettingsSent = true;
    }
    if (initialOtherSideSettings != null) {
        Http2SettingsParser parser = new Http2SettingsParser(initialOtherSideSettings.remaining());
        try {
            final Http2FrameHeaderParser headerParser = new Http2FrameHeaderParser(this, null);
            headerParser.length = initialOtherSideSettings.remaining();
            parser.parse(initialOtherSideSettings, headerParser);
            updateSettings(parser.getSettings());
        } catch (Throwable e) {
            IoUtils.safeClose(connectedStreamChannel);
            //should never happen
            throw new RuntimeException(e);
        }
    }
    int requestParseTimeout = settings.get(UndertowOptions.REQUEST_PARSE_TIMEOUT, -1);
    int requestIdleTimeout = settings.get(UndertowOptions.NO_REQUEST_TIMEOUT, -1);
    if(requestIdleTimeout < 0 && requestParseTimeout < 0) {
        this.parseTimeoutUpdater = null;
    } else {
        this.parseTimeoutUpdater = new ParseTimeoutUpdater(this, requestParseTimeout, requestIdleTimeout, new Runnable() {
            @Override
            public void run() {
                sendGoAway(ERROR_NO_ERROR);
                //just to make sure the connection is actually closed we give it 2 seconds
                //then we forcibly kill the connection
                getIoThread().executeAfter(new Runnable() {
                    @Override
                    public void run() {
                        IoUtils.safeClose(Http2Channel.this);
                    }
                }, 2, TimeUnit.SECONDS);
            }
        });
        this.addCloseTask(new ChannelListener<Http2Channel>() {
            @Override
            public void handleEvent(Http2Channel channel) {
                parseTimeoutUpdater.close();
            }
        });
    }
}
 
Example 15
Source File: ProtocolConnectionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static IoFuture<Connection> connect(final CallbackHandler handler, final ProtocolConnectionConfiguration configuration) throws IOException {
    configuration.validate();
    final Endpoint endpoint = configuration.getEndpoint();
    final URI uri = configuration.getUri();
    String clientBindAddress = configuration.getClientBindAddress();

    AuthenticationContext captured = AuthenticationContext.captureCurrent();
    AuthenticationConfiguration mergedConfiguration = AUTH_CONFIGURATION_CLIENT.getAuthenticationConfiguration(uri, captured);
    if (handler != null) {
        // Clear the three values as the CallbackHandler will be used for these.
        mergedConfiguration = mergedConfiguration.useAnonymous();
        mergedConfiguration = mergedConfiguration.useCredentials(IdentityCredentials.NONE);
        mergedConfiguration = mergedConfiguration.useRealm(null);
        mergedConfiguration = mergedConfiguration.useCallbackHandler(handler, DEFAULT_CALLBACK_KINDS);
    }

    Map<String, String> saslOptions = configuration.getSaslOptions();
    mergedConfiguration = configureSaslMechanisms(saslOptions, isLocal(uri), mergedConfiguration);

    // Pass through any other SASL options from the ProtocolConnectionConfiguration
    // When we merge these, any pre-existing options already associated with the
    // AuthenticationConfiguration will take precedence.
    if (saslOptions != null) {
        saslOptions = new HashMap<>(saslOptions);
        // Drop SASL_DISALLOWED_MECHANISMS which we already handled
        saslOptions.remove(Options.SASL_DISALLOWED_MECHANISMS.getName());
        mergedConfiguration = mergedConfiguration.useMechanismProperties(saslOptions);
    }

    SSLContext sslContext = configuration.getSslContext();
    if (sslContext == null) {
        try {
            sslContext = AUTH_CONFIGURATION_CLIENT.getSSLContext(uri, captured);
        } catch (GeneralSecurityException e) {
            throw ProtocolLogger.ROOT_LOGGER.failedToConnect(uri, e);
        }
    }

    // WFCORE-2342 check for default SSL / TLS options
    final OptionMap.Builder builder = OptionMap.builder();
    OptionMap optionMap = configuration.getOptionMap();
    for (Option option : optionMap) {
        builder.set(option, optionMap.get(option));
    }
    if (optionMap.get(Options.SSL_ENABLED) == null)
        builder.set(Options.SSL_ENABLED, configuration.isSslEnabled());
    if (optionMap.get(Options.SSL_STARTTLS) == null)
        builder.set(Options.SSL_STARTTLS, configuration.isUseStartTLS());

    AuthenticationContext authenticationContext = AuthenticationContext.empty();
    authenticationContext = authenticationContext.with(MatchRule.ALL, mergedConfiguration);
    final SSLContext finalSslContext = sslContext;
    authenticationContext = authenticationContext.withSsl(MatchRule.ALL, () -> finalSslContext);

    if (clientBindAddress == null) {
        return endpoint.connect(uri, builder.getMap(), authenticationContext);
    } else {
        InetSocketAddress bindAddr = new InetSocketAddress(clientBindAddress, 0);
        return endpoint.connect(uri, bindAddr, builder.getMap(), authenticationContext);
    }
}