Search in sources :

Example 1 with ProtocolConnectionConfiguration

use of org.jboss.as.protocol.ProtocolConnectionConfiguration in project wildfly-core by wildfly.

the class RemoteDomainConnection method openConnection.

/**
 * Connect and register at the remote domain controller.
 *
 * @return connection the established connection
 * @throws IOException
 */
protected Connection openConnection() throws IOException {
    // Perhaps this can just be done once?
    CallbackHandler callbackHandler = null;
    SSLContext sslContext = null;
    final ProtocolConnectionConfiguration config = ProtocolConnectionConfiguration.copy(configuration);
    // TODO this needs cleaning up.
    config.setCallbackHandler(callbackHandler);
    config.setSslContext(sslContext);
    config.setUri(uri);
    AuthenticationContext authenticationContext = this.authenticationContext != null ? this.authenticationContext : AuthenticationContext.captureCurrent();
    // Connect
    try {
        return authenticationContext.run((PrivilegedExceptionAction<Connection>) () -> ProtocolConnectionUtils.connectSync(config));
    } catch (PrivilegedActionException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
        throw new IOException(e);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) PrivilegedActionException(java.security.PrivilegedActionException) ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration) Connection(org.jboss.remoting3.Connection) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException)

Example 2 with ProtocolConnectionConfiguration

use of org.jboss.as.protocol.ProtocolConnectionConfiguration in project wildfly-core by wildfly.

the class HostControllerConnection method asyncReconnect.

/**
 * This continuously tries to reconnect in a separate thread and will only stop if the connection was established
 * successfully or the server gets shutdown. If there is currently a reconnect task active the connection paramaters
 * and callback will get updated.
 *
 * @param reconnectUri    the updated connection uri
 * @param authKey         the updated authentication key
 * @param callback        the current callback
 */
synchronized void asyncReconnect(final URI reconnectUri, String authKey, final ReconnectCallback callback) {
    if (getState() != State.OPEN) {
        return;
    }
    // Update the configuration with the new credentials
    final ProtocolConnectionConfiguration config = ProtocolConnectionConfiguration.copy(configuration);
    config.setCallbackHandler(createClientCallbackHandler(userName, authKey));
    config.setUri(reconnectUri);
    this.configuration = config;
    final ReconnectRunner reconnectTask = this.reconnectRunner;
    if (reconnectTask == null) {
        final ReconnectRunner task = new ReconnectRunner();
        task.callback = callback;
        task.future = executorService.submit(task);
    } else {
        reconnectTask.callback = callback;
    }
}
Also used : ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration)

Example 3 with ProtocolConnectionConfiguration

use of org.jboss.as.protocol.ProtocolConnectionConfiguration in project wildfly-core by wildfly.

the class TestControllerUtils method create.

static TestControllerUtils create(URI uri, CallbackHandler callbackHandler) throws IOException {
    final Endpoint endpoint = Endpoint.getCurrent();
    final ProtocolConnectionConfiguration configuration = ProtocolConnectionConfiguration.create(endpoint, uri);
    configuration.setCallbackHandler(callbackHandler);
    return new TestControllerUtils(endpoint, configuration, createDefaultExecutor());
}
Also used : Endpoint(org.jboss.remoting3.Endpoint) ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration)

Example 4 with ProtocolConnectionConfiguration

use of org.jboss.as.protocol.ProtocolConnectionConfiguration in project wildfly-core by wildfly.

the class RemotingModelControllerClient method getOrCreateChannel.

protected Channel getOrCreateChannel() throws IOException {
    synchronized (closeable) {
        if (closeable.closed) {
            throw ControllerClientLogger.ROOT_LOGGER.objectIsClosed(ModelControllerClient.class.getSimpleName());
        }
        if (closeable.strategy == null) {
            try {
                closeable.endpoint = Endpoint.builder().setEndpointName("management-client").build();
                final ProtocolConnectionConfiguration configuration = ProtocolConfigurationFactory.create(closeable.clientConfiguration, closeable.endpoint);
                closeable.strategy = ManagementClientChannelStrategy.create(configuration, closeable.channelAssociation, closeable.clientConfiguration.getCallbackHandler(), closeable.clientConfiguration.getSaslOptions(), closeable.clientConfiguration.getSSLContext(), new CloseHandler<Channel>() {

                    @Override
                    public void handleClose(final Channel closed, final IOException exception) {
                        closeable.channelAssociation.handleChannelClosed(closed, exception);
                    }
                });
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return closeable.strategy.getChannel();
    }
}
Also used : ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration) Channel(org.jboss.remoting3.Channel) CloseHandler(org.jboss.remoting3.CloseHandler) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 5 with ProtocolConnectionConfiguration

use of org.jboss.as.protocol.ProtocolConnectionConfiguration in project wildfly-core by wildfly.

the class ConnectSyncUnitTestCase method testTimeoutFailure.

@Test
public void testTimeoutFailure() throws IOException {
    ProtocolConnectionConfiguration configuration = getConfiguration(IoFuture.Status.WAITING, false, true);
    try {
        ProtocolConnectionUtils.connectSync(configuration);
        fail();
    } catch (ConnectException expected) {
        TestTimeoutHandler handler = (TestTimeoutHandler) configuration.getTimeoutHandler();
        assertEquals(handler.getFailure(), expected.getCause());
        assertTrue(expected.getMessage().contains("WFLYPRT0053"));
    }
}
Also used : ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Aggregations

ProtocolConnectionConfiguration (org.jboss.as.protocol.ProtocolConnectionConfiguration)17 ConnectException (java.net.ConnectException)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 URI (java.net.URI)4 ResponseAttachmentInputStreamSupport (org.jboss.as.controller.remote.ResponseAttachmentInputStreamSupport)3 Connection (org.jboss.remoting3.Connection)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ManagementChannelHandler (org.jboss.as.protocol.mgmt.ManagementChannelHandler)2 StartException (org.jboss.msc.service.StartException)2 Channel (org.jboss.remoting3.Channel)2 Endpoint (org.jboss.remoting3.Endpoint)2 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 InterruptedIOException (java.io.InterruptedIOException)1 InetSocketAddress (java.net.InetSocketAddress)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1