Search in sources :

Example 31 with ConnectException

use of java.net.ConnectException in project CloudStack-archive by CloudStack-extras.

the class NioConnection method run.

@Override
public void run() {
    synchronized (_thread) {
        try {
            init();
        } catch (ConnectException e) {
            s_logger.error("Unable to connect to remote");
            return;
        } catch (IOException e) {
            s_logger.error("Unable to initialize the threads.", e);
            return;
        } catch (Exception e) {
            s_logger.error("Unable to initialize the threads due to unknown exception.", e);
            return;
        }
        _isStartup = true;
        _thread.notifyAll();
    }
    while (_isRunning) {
        try {
            _selector.select();
            // Someone is ready for I/O, get the ready keys
            Set<SelectionKey> readyKeys = _selector.selectedKeys();
            Iterator<SelectionKey> i = readyKeys.iterator();
            if (s_logger.isTraceEnabled()) {
                s_logger.trace("Keys Processing: " + readyKeys.size());
            }
            // Walk through the ready keys collection.
            while (i.hasNext()) {
                SelectionKey sk = i.next();
                i.remove();
                if (!sk.isValid()) {
                    if (s_logger.isTraceEnabled()) {
                        s_logger.trace("Selection Key is invalid: " + sk.toString());
                    }
                    Link link = (Link) sk.attachment();
                    if (link != null) {
                        link.terminated();
                    } else {
                        closeConnection(sk);
                    }
                } else if (sk.isReadable()) {
                    read(sk);
                } else if (sk.isWritable()) {
                    write(sk);
                } else if (sk.isAcceptable()) {
                    accept(sk);
                } else if (sk.isConnectable()) {
                    connect(sk);
                }
            }
            s_logger.trace("Keys Done Processing.");
            processTodos();
        } catch (Throwable e) {
            s_logger.warn("Caught an exception but continuing on.", e);
        }
    }
    synchronized (_thread) {
        _isStartup = false;
    }
}
Also used : SelectionKey(java.nio.channels.SelectionKey) IOException(java.io.IOException) CancelledKeyException(java.nio.channels.CancelledKeyException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Example 32 with ConnectException

use of java.net.ConnectException in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method connectFailureNotifiesHandlerWithConnectException.

@Test
public void connectFailureNotifiesHandlerWithConnectException() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            final CountDownLatch l = new CountDownLatch(1);
            int port = findFreePort();
            client.prepareGet(String.format("http://localhost:%d/", port)).execute(new AsyncCompletionHandlerAdapter() {

                @Override
                public void onThrowable(Throwable t) {
                    try {
                        assertTrue(t instanceof ConnectException);
                    } finally {
                        l.countDown();
                    }
                }
            });
            if (!l.await(TIMEOUT, SECONDS)) {
                fail("Timed out");
            }
        });
    });
}
Also used : AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectException(java.net.ConnectException) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Example 33 with ConnectException

use of java.net.ConnectException in project timber by JakeWharton.

the class TimberTest method exceptionOnly.

@Test
public void exceptionOnly() {
    Timber.plant(new Timber.DebugTree());
    Timber.v(new IllegalArgumentException());
    assertExceptionLogged(Log.VERBOSE, null, "java.lang.IllegalArgumentException", "TimberTest", 0);
    Timber.i(new NullPointerException());
    assertExceptionLogged(Log.INFO, null, "java.lang.NullPointerException", "TimberTest", 1);
    Timber.d(new UnsupportedOperationException());
    assertExceptionLogged(Log.DEBUG, null, "java.lang.UnsupportedOperationException", "TimberTest", 2);
    Timber.w(new UnknownHostException());
    assertExceptionLogged(Log.WARN, null, "java.net.UnknownHostException", "TimberTest", 3);
    Timber.e(new ConnectException());
    assertExceptionLogged(Log.ERROR, null, "java.net.ConnectException", "TimberTest", 4);
    Timber.wtf(new AssertionError());
    assertExceptionLogged(Log.ASSERT, null, "java.lang.AssertionError", "TimberTest", 5);
}
Also used : UnknownHostException(java.net.UnknownHostException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 34 with ConnectException

use of java.net.ConnectException in project midpoint by Evolveum.

the class DummyConnector method delete.

/**
     * {@inheritDoc}
     */
public void delete(final ObjectClass objectClass, final Uid uid, final OperationOptions options) {
    log.info("delete::begin");
    validate(objectClass);
    validate(uid);
    String id = uid.getUidValue();
    try {
        if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                resource.deleteAccountByName(id);
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                resource.deleteAccountById(id);
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
        } else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                resource.deleteGroupByName(id);
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                resource.deleteGroupById(id);
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
        } else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                resource.deletePrivilegeByName(id);
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                resource.deletePrivilegeById(id);
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
        } else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                resource.deleteOrgByName(id);
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                resource.deleteOrgById(id);
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
        } else {
            throw new ConnectorException("Unknown object class " + objectClass);
        }
    } catch (ObjectDoesNotExistException e) {
        // The framework should deal with it ... somehow
        throw new UnknownUidException(e.getMessage(), e);
    } catch (ConnectException e) {
        log.info("delete::exception " + e);
        throw new ConnectionFailedException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        log.info("delete::exception " + e);
        throw new ConnectorIOException(e.getMessage(), e);
    } catch (SchemaViolationException e) {
        log.info("delete::exception " + e);
        throw new InvalidAttributeValueException(e.getMessage(), e);
    } catch (ConflictException e) {
        log.info("delete::exception " + e);
        throw new AlreadyExistsException(e);
    }
    log.info("delete::end");
}
Also used : ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) ConflictException(com.evolveum.icf.dummy.resource.ConflictException) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) ObjectDoesNotExistException(com.evolveum.icf.dummy.resource.ObjectDoesNotExistException) UnknownUidException(org.identityconnectors.framework.common.exceptions.UnknownUidException) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) ConnectException(java.net.ConnectException)

Example 35 with ConnectException

use of java.net.ConnectException in project midpoint by Evolveum.

the class DummyConnector method createAccountObjectClass.

private ObjectClassInfo createAccountObjectClass(boolean supportsActivation) throws SchemaViolationException, ConflictException {
    // __ACCOUNT__ objectclass
    DummyObjectClass dummyAccountObjectClass;
    try {
        dummyAccountObjectClass = resource.getAccountObjectClass();
    } catch (ConnectException e) {
        throw new ConnectionFailedException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new ConnectorIOException(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        throw new ConnectorException(e.getMessage(), e);
    }
    // DO NOT catch IllegalStateException, let it pass
    ObjectClassInfoBuilder objClassBuilder = createCommonObjectClassBuilder(getAccountObjectClassName(), dummyAccountObjectClass, supportsActivation);
    // __PASSWORD__ attribute
    AttributeInfo passwordAttrInfo;
    switch(configuration.getPasswordReadabilityMode()) {
        case DummyConfiguration.PASSWORD_READABILITY_MODE_READABLE:
        case DummyConfiguration.PASSWORD_READABILITY_MODE_INCOMPLETE:
            AttributeInfoBuilder aib = new AttributeInfoBuilder();
            aib.setName(OperationalAttributes.PASSWORD_NAME);
            aib.setType(GuardedString.class);
            aib.setMultiValued(false);
            aib.setReadable(true);
            aib.setReturnedByDefault(false);
            passwordAttrInfo = aib.build();
            break;
        default:
            passwordAttrInfo = OperationalAttributeInfos.PASSWORD;
            break;
    }
    objClassBuilder.addAttributeInfo(passwordAttrInfo);
    return objClassBuilder.build();
}
Also used : DummyObjectClass(com.evolveum.icf.dummy.resource.DummyObjectClass) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) FileNotFoundException(java.io.FileNotFoundException) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)521 IOException (java.io.IOException)211 Socket (java.net.Socket)84 SocketTimeoutException (java.net.SocketTimeoutException)69 Test (org.junit.Test)69 UnknownHostException (java.net.UnknownHostException)57 InetSocketAddress (java.net.InetSocketAddress)56 WebServiceException (javax.xml.ws.WebServiceException)48 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)48 ErrorCode (org.olat.modules.vitero.model.ErrorCode)48 FileNotFoundException (java.io.FileNotFoundException)39 URL (java.net.URL)36 InputStream (java.io.InputStream)33 NoRouteToHostException (java.net.NoRouteToHostException)33 SocketException (java.net.SocketException)33 ArrayList (java.util.ArrayList)31 InetAddress (java.net.InetAddress)29 InputStreamReader (java.io.InputStreamReader)28 OutputStream (java.io.OutputStream)28 HttpURLConnection (java.net.HttpURLConnection)28