/** {@inheritDoc} */ public ConnectionProvider createInstance(final ConnectionProviderContext context, final OptionMap optionMap, final String protocolName) throws IOException { return new HttpUpgradeConnectionProvider(optionMap, context, protocolName); } }
@Override public void checkHandshake(final Map<String, String> headers) throws IOException { if(!headers.containsKey(SEC_JBOSS_REMOTING_ACCEPT)) { throw new IOException("No " + SEC_JBOSS_REMOTING_ACCEPT + " header in response"); } final String expectedResponse = createExpectedResponse(key); final String response = headers.get(SEC_JBOSS_REMOTING_ACCEPT); if(!response.equals(expectedResponse)) { throw new IOException(SEC_JBOSS_REMOTING_ACCEPT + " value of " + response + " did not match expected " + expectedResponse); } } }
@Override public void handleEvent(StreamConnection channel) { final Map<String, String> headers = new HashMap<String, String>(); headers.put(UPGRADE, "jboss-remoting"); final String secKey = createSecKey(); headers.put(SEC_JBOSS_REMOTING_KEY, secKey); IoFuture<T> upgradeFuture = HttpUpgrade.performUpgrade(type.cast(channel), uri, headers, upgradeChannel -> { ChannelListeners.invokeChannelListener(upgradeChannel, openListener); }, new RemotingHandshakeChecker(secKey)); upgradeFuture.addNotifier( new IoFuture.HandlingNotifier<T, FutureResult<T>>() { @Override public void handleCancelled(FutureResult<T> attachment) { attachment.setCancelled(); } @Override public void handleFailed(IOException exception, FutureResult<T> attachment) { attachment.setException(exception); } @Override public void handleDone(T data, FutureResult<T> attachment) { attachment.setResult(data); } }, futureResult); }
public void accept(final StreamConnection channel) { if (channel.getWorker() != getXnioWorker()) { throw conn.invalidWorker(); } try { channel.setOption(Options.TCP_NODELAY, Boolean.TRUE); } catch (IOException e) { // ignore } final SslChannel sslChannel = channel instanceof SslConnection ? (SslConnection) channel : null; final RemoteConnection connection = new RemoteConnection(channel, sslChannel, optionMap, HttpUpgradeConnectionProvider.this); final ServerConnectionOpenListener openListener = new ServerConnectionOpenListener(connection, getConnectionProviderContext(), saslAuthenticationFactory, optionMap); channel.getSinkChannel().setWriteListener(connection.getWriteListener()); conn.tracef("Accepted connection from %s to %s", channel.getPeerAddress(), channel.getLocalAddress()); openListener.handleEvent(channel.getSourceChannel()); } }
protected IoFuture<StreamConnection> createConnection(final URI uri, final InetSocketAddress bindAddress, final InetSocketAddress destination, final OptionMap connectOptions, final ChannelListener<StreamConnection> openListener) { final URI newUri; try { newUri = new URI("http", "", uri.getHost(), uri.getPort(), "/", "", ""); } catch (URISyntaxException e) { return new FailedIoFuture<>(new IOException(e)); } final FutureResult<StreamConnection> returnedFuture = new FutureResult<>(getExecutor()); ChannelListener<StreamConnection> upgradeListener = new UpgradeListener<StreamConnection>(StreamConnection.class, newUri, openListener, returnedFuture); IoFuture<StreamConnection> rawFuture = super.createConnection(uri, bindAddress, destination, connectOptions, upgradeListener); rawFuture.addNotifier( new IoFuture.HandlingNotifier<StreamConnection, FutureResult<StreamConnection>>() { @Override public void handleCancelled(FutureResult<StreamConnection> attachment) { attachment.setCancelled(); } @Override public void handleFailed(IOException exception, FutureResult<StreamConnection> attachment) { attachment.setException(exception); } } , returnedFuture); return returnedFuture.getIoFuture(); }
public void accept(final StreamConnection channel) { if (channel.getWorker() != getXnioWorker()) { throw conn.invalidWorker(); } try { channel.setOption(Options.TCP_NODELAY, Boolean.TRUE); } catch (IOException e) { // ignore } final SslChannel sslChannel = channel instanceof SslConnection ? (SslConnection) channel : null; final RemoteConnection connection = new RemoteConnection(channel, sslChannel, optionMap, HttpUpgradeConnectionProvider.this); final ServerConnectionOpenListener openListener = new ServerConnectionOpenListener(connection, getConnectionProviderContext(), saslAuthenticationFactory, optionMap); channel.getSinkChannel().setWriteListener(connection.getWriteListener()); conn.tracef("Accepted connection from %s to %s", channel.getPeerAddress(), channel.getLocalAddress()); openListener.handleEvent(channel.getSourceChannel()); } }
protected IoFuture<SslConnection> createSslConnection(final URI uri, final InetSocketAddress bindAddress, final InetSocketAddress destination, final OptionMap options, final AuthenticationConfiguration configuration, final SSLContext sslContext, final ChannelListener<StreamConnection> openListener) { final URI newUri; try { newUri = new URI("https", "", uri.getHost(), uri.getPort(), "/", "", ""); } catch (URISyntaxException e) { return new FailedIoFuture<>(new IOException(e)); } final FutureResult<SslConnection> returnedFuture = new FutureResult<>(getExecutor()); final OptionMap modifiedOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, false).getMap(); ChannelListener<StreamConnection> upgradeListener = new UpgradeListener<SslConnection>(SslConnection.class, newUri, openListener, returnedFuture); IoFuture<SslConnection> rawFuture = super.createSslConnection(uri, bindAddress, destination, modifiedOptions, configuration, sslContext, upgradeListener); rawFuture.addNotifier( new IoFuture.HandlingNotifier<StreamConnection, FutureResult<SslConnection>>() { @Override public void handleCancelled(FutureResult<SslConnection> attachment) { attachment.setCancelled(); } @Override public void handleFailed(IOException exception, FutureResult<SslConnection> attachment) { attachment.setException(exception); } } , returnedFuture); return returnedFuture.getIoFuture(); }
protected IoFuture<StreamConnection> createConnection(final URI uri, final InetSocketAddress bindAddress, final InetSocketAddress destination, final OptionMap connectOptions, final ChannelListener<StreamConnection> openListener) { final URI newUri; try { newUri = new URI("http", "", uri.getHost(), uri.getPort(), "/", "", ""); } catch (URISyntaxException e) { return new FailedIoFuture<>(new IOException(e)); } final FutureResult<StreamConnection> returnedFuture = new FutureResult<>(getExecutor()); ChannelListener<StreamConnection> upgradeListener = new UpgradeListener<StreamConnection>(StreamConnection.class, newUri, openListener, returnedFuture); IoFuture<StreamConnection> rawFuture = super.createConnection(uri, bindAddress, destination, connectOptions, upgradeListener); rawFuture.addNotifier( new IoFuture.HandlingNotifier<StreamConnection, FutureResult<StreamConnection>>() { @Override public void handleCancelled(FutureResult<StreamConnection> attachment) { attachment.setCancelled(); } @Override public void handleFailed(IOException exception, FutureResult<StreamConnection> attachment) { attachment.setException(exception); } } , returnedFuture); return returnedFuture.getIoFuture(); }
/** {@inheritDoc} */ public ConnectionProvider createInstance(final ConnectionProviderContext context, final OptionMap optionMap, final String protocolName) throws IOException { return new HttpUpgradeConnectionProvider(optionMap, context, protocolName); } }
@Override public void checkHandshake(final Map<String, String> headers) throws IOException { if(!headers.containsKey(SEC_JBOSS_REMOTING_ACCEPT)) { throw new IOException("No " + SEC_JBOSS_REMOTING_ACCEPT + " header in response"); } final String expectedResponse = createExpectedResponse(key); final String response = headers.get(SEC_JBOSS_REMOTING_ACCEPT); if(!response.equals(expectedResponse)) { throw new IOException(SEC_JBOSS_REMOTING_ACCEPT + " value of " + response + " did not match expected " + expectedResponse); } } }
@Override public void handleEvent(StreamConnection channel) { final Map<String, String> headers = new HashMap<String, String>(); headers.put(UPGRADE, "jboss-remoting"); final String secKey = createSecKey(); headers.put(SEC_JBOSS_REMOTING_KEY, secKey); IoFuture<T> upgradeFuture = HttpUpgrade.performUpgrade(type.cast(channel), uri, headers, upgradeChannel -> { ChannelListeners.invokeChannelListener(upgradeChannel, openListener); }, new RemotingHandshakeChecker(secKey)); upgradeFuture.addNotifier( new IoFuture.HandlingNotifier<T, FutureResult<T>>() { @Override public void handleCancelled(FutureResult<T> attachment) { attachment.setCancelled(); } @Override public void handleFailed(IOException exception, FutureResult<T> attachment) { attachment.setException(exception); } @Override public void handleDone(T data, FutureResult<T> attachment) { attachment.setResult(data); } }, futureResult); }
protected IoFuture<SslConnection> createSslConnection(final URI uri, final InetSocketAddress bindAddress, final InetSocketAddress destination, final OptionMap options, final AuthenticationConfiguration configuration, final SSLContext sslContext, final ChannelListener<StreamConnection> openListener) { final URI newUri; try { newUri = new URI("https", "", uri.getHost(), uri.getPort(), "/", "", ""); } catch (URISyntaxException e) { return new FailedIoFuture<>(new IOException(e)); } final FutureResult<SslConnection> returnedFuture = new FutureResult<>(getExecutor()); final OptionMap modifiedOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, false).getMap(); ChannelListener<StreamConnection> upgradeListener = new UpgradeListener<SslConnection>(SslConnection.class, newUri, openListener, returnedFuture); IoFuture<SslConnection> rawFuture = super.createSslConnection(uri, bindAddress, destination, modifiedOptions, configuration, sslContext, upgradeListener); rawFuture.addNotifier( new IoFuture.HandlingNotifier<StreamConnection, FutureResult<SslConnection>>() { @Override public void handleCancelled(FutureResult<SslConnection> attachment) { attachment.setCancelled(); } @Override public void handleFailed(IOException exception, FutureResult<SslConnection> attachment) { attachment.setException(exception); } } , returnedFuture); return returnedFuture.getIoFuture(); }