Search in sources :

Example 51 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project wildfly-core by wildfly.

the class ProtocolConnectionUtils method connectSync.

/**
 * Connect sync.
 *
 * @param configuration the protocol configuration
 * @return the connection
 * @throws IOException
 */
public static Connection connectSync(final ProtocolConnectionConfiguration configuration) throws IOException {
    long timeoutMillis = configuration.getConnectionTimeout();
    CallbackHandler handler = configuration.getCallbackHandler();
    final CallbackHandler actualHandler;
    ProtocolTimeoutHandler timeoutHandler = configuration.getTimeoutHandler();
    // Note: If a client supplies a ProtocolTimeoutHandler it is taking on full responsibility for timeout management.
    if (timeoutHandler == null) {
        GeneralTimeoutHandler defaultTimeoutHandler = new GeneralTimeoutHandler();
        // No point wrapping our AnonymousCallbackHandler.
        actualHandler = handler != null ? new WrapperCallbackHandler(defaultTimeoutHandler, handler) : null;
        timeoutHandler = defaultTimeoutHandler;
    } else {
        actualHandler = handler;
    }
    final IoFuture<Connection> future = connect(actualHandler, configuration);
    IoFuture.Status status = timeoutHandler.await(future, timeoutMillis);
    Connection result = checkFuture(status, future, configuration);
    if (result == null) {
        // Did not complete in time; tell remoting we don't want it
        future.cancel();
        // In case the future completed between when we waited for it and when we cancelled,
        // close any connection that was established. We don't want to risk using a
        // Connection after we told remoting to cancel, and if we don't use it we must close it.
        Connection toClose = checkFuture(future.getStatus(), future, configuration);
        StreamUtils.safeClose(toClose);
        throw ProtocolLogger.ROOT_LOGGER.couldNotConnect(configuration.getUri());
    }
    return result;
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) Connection(org.jboss.remoting3.Connection) IoFuture(org.xnio.IoFuture)

Example 52 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project wildfly-core by wildfly.

the class ConnectSyncUnitTestCase method getConfiguration.

private static ProtocolConnectionConfiguration getConfiguration(IoFuture.Status initialStatus, boolean completeOnRecheck, boolean failOnRecheck) {
    final FutureResult<Connection> futureResult = new FutureResult<>();
    // It seems you need to add a cancel handler if you want a
    // call to futureResult.getIoFuture().cancel() to trigger a change in the future to State.CANCELLED.
    // So add one so we can test whether cancel() has been called.
    futureResult.addCancelHandler(new Cancellable() {

        public Cancellable cancel() {
            futureResult.setCancelled();
            return this;
        }
    });
    final MockConnection connection = initialStatus == IoFuture.Status.DONE || completeOnRecheck ? new MockConnection() : null;
    final TestTimeoutHandler timeoutHandler = new TestTimeoutHandler(futureResult, initialStatus, connection, failOnRecheck);
    final MockEndpoint endpoint = new MockEndpoint(futureResult);
    ProtocolConnectionConfiguration result = ProtocolConnectionConfiguration.create(endpoint, URI.create("http://127.0.0.1"));
    result.setTimeoutHandler(timeoutHandler);
    return result;
}
Also used : FutureResult(org.xnio.FutureResult) Cancellable(org.xnio.Cancellable) ProtocolConnectionConfiguration(org.jboss.as.protocol.ProtocolConnectionConfiguration) Connection(org.jboss.remoting3.Connection)

Example 53 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project wildfly-core by wildfly.

the class ManagementChannelHandler method getRemoteAddress.

/**
 * Get the remote address.
 *
 * @return the remote address, {@code null} if not available
 */
public InetAddress getRemoteAddress() {
    final Channel channel;
    try {
        channel = strategy.getChannel();
    } catch (IOException e) {
        return null;
    }
    final Connection connection = channel.getConnection();
    final InetSocketAddress peerAddress = connection.getPeerAddress(InetSocketAddress.class);
    return peerAddress == null ? null : peerAddress.getAddress();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.remoting3.Channel) Connection(org.jboss.remoting3.Connection) IOException(java.io.IOException)

Example 54 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project hop by apache.

the class SshDialog method test.

private void test() {
    Exception exception = null;
    String errMsg = null;
    Connection connection = null;
    SshMeta meta = new SshMeta();
    getInfo(meta);
    try {
        connection = SshData.openConnection(variables, meta);
    } catch (Exception e) {
        exception = e;
        errMsg = e.getMessage();
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (Exception e) {
            /* Ignore */
            }
        }
    }
    if (exception == null) {
        MessageBox messageBox;
        messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
        messageBox.setMessage(BaseMessages.getString(PKG, "SSHDialog.Connected.OK", meta.getServerName(), meta.getUserName()) + Const.CR);
        messageBox.setText(BaseMessages.getString(PKG, "SSHDialog.Connected.Title.Ok"));
        messageBox.open();
    } else {
        new ErrorDialog(shell, "Error", BaseMessages.getString(PKG, "SSHDialog.Connected.NOK.ConnectionBad", meta.getServerName(), meta.getUserName()) + Const.CR + errMsg + Const.CR, exception);
    }
}
Also used : Connection(com.trilead.ssh2.Connection) HopException(org.apache.hop.core.exception.HopException)

Example 55 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project Sentinel by alibaba.

the class OkHttpResourceExtractorTest method testCustomizeOkHttpUrlCleaner.

@Test
public void testCustomizeOkHttpUrlCleaner() {
    OkHttpResourceExtractor extractor = new OkHttpResourceExtractor() {

        @Override
        public String extract(Request request, Connection connection) {
            String regex = "/okhttp/back/";
            String url = request.url().toString();
            if (url.contains(regex)) {
                url = url.substring(0, url.indexOf(regex) + regex.length()) + "{id}";
            }
            return request.method() + ":" + url;
        }
    };
    String url = "http://localhost:8083/okhttp/back/abc";
    Request request = new Request.Builder().url(url).build();
    assertEquals("GET:http://localhost:8083/okhttp/back/{id}", extractor.extract(request, null));
}
Also used : Request(okhttp3.Request) Connection(okhttp3.Connection) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)68 Connection (org.ovirt.engine.sdk4.Connection)64 Connection (com.trilead.ssh2.Connection)61 Connection (org.osate.aadl2.Connection)57 Session (com.trilead.ssh2.Session)33 Connection (org.jboss.remoting3.Connection)33 Connection (com.google.cloud.bigquery.connection.v1.Connection)31 Test (org.junit.Test)30 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 InputStream (java.io.InputStream)29 Connection (okhttp3.Connection)28 Connection (ch.ethz.ssh2.Connection)24 Request (okhttp3.Request)20 Subcomponent (org.osate.aadl2.Subcomponent)19 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)18 PortConnection (org.osate.aadl2.PortConnection)18 VmService (org.ovirt.engine.sdk4.services.VmService)18 ArrayList (java.util.ArrayList)17 Response (okhttp3.Response)17