Search in sources :

Example 36 with ConnectException

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

the class DummyConnector method convertToConnectorObject.

private ConnectorObject convertToConnectorObject(DummyAccount account, Collection<String> attributesToGet) throws SchemaViolationException {
    DummyObjectClass objectClass;
    try {
        objectClass = resource.getAccountObjectClass();
    } catch (ConnectException e) {
        log.error(e, e.getMessage());
        throw new ConnectionFailedException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        log.error(e, e.getMessage());
        throw new ConnectorIOException(e.getMessage(), e);
    } catch (ConflictException e) {
        log.error(e, e.getMessage());
        throw new AlreadyExistsException(e);
    }
    ConnectorObjectBuilder builder = createConnectorObjectBuilderCommon(account, objectClass, attributesToGet, true);
    builder.setObjectClass(ObjectClass.ACCOUNT);
    // Password is not returned by default (hardcoded ICF specification)
    if (account.getPassword() != null && attributesToGet != null && attributesToGet.contains(OperationalAttributes.PASSWORD_NAME)) {
        switch(configuration.getPasswordReadabilityMode()) {
            case DummyConfiguration.PASSWORD_READABILITY_MODE_READABLE:
                GuardedString gs = new GuardedString(account.getPassword().toCharArray());
                builder.addAttribute(OperationalAttributes.PASSWORD_NAME, gs);
                break;
            case DummyConfiguration.PASSWORD_READABILITY_MODE_INCOMPLETE:
                AttributeBuilder ab = new AttributeBuilder();
                ab.setName(OperationalAttributes.PASSWORD_NAME);
                ab.setAttributeValueCompleteness(AttributeValueCompleteness.INCOMPLETE);
                builder.addAttribute(ab.build());
                break;
            default:
        }
    }
    if (account.isLockout() != null) {
        builder.addAttribute(OperationalAttributes.LOCK_OUT_NAME, account.isLockout());
    }
    return builder.build();
}
Also used : DummyObjectClass(com.evolveum.icf.dummy.resource.DummyObjectClass) 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) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) ConnectException(java.net.ConnectException)

Example 37 with ConnectException

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

the class DummyConnector method removeAttributeValues.

/**
     * {@inheritDoc}
     */
public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> valuesToRemove, OperationOptions options) {
    validate(objectClass);
    validate(uid);
    try {
        if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
            DummyAccount account;
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                account = resource.getAccountByUsername(uid.getUidValue());
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                account = resource.getAccountById(uid.getUidValue());
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
            if (account == null) {
                throw new UnknownUidException("Account with UID " + uid + " does not exist on resource");
            }
            for (Attribute attr : valuesToRemove) {
                if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
                    throw new UnsupportedOperationException("Removing password value is not supported");
                } else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
                    throw new IllegalArgumentException("Attempt to remove value from enable attribute");
                } else if (PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME.equalsIgnoreCase(attr.getName())) {
                    account.deleteAuxiliaryObjectClassNames(attr.getValue());
                } else {
                    String name = attr.getName();
                    try {
                        account.removeAttributeValues(name, attr.getValue());
                        log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), account, account.getAttributeValues(name, Object.class));
                    } catch (SchemaViolationException e) {
                        // The framework should deal with it ... somehow
                        throw new IllegalArgumentException(e.getMessage(), e);
                    }
                }
            }
        } else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
            DummyGroup group;
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                group = resource.getGroupByName(uid.getUidValue());
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                group = resource.getGroupById(uid.getUidValue());
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
            if (group == null) {
                throw new UnknownUidException("Group with UID " + uid + " does not exist on resource");
            }
            for (Attribute attr : valuesToRemove) {
                if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
                    throw new IllegalArgumentException("Attempt to change password on group");
                } else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
                    throw new IllegalArgumentException("Attempt to remove value from enable attribute");
                } else {
                    String name = attr.getName();
                    List<Object> values = attr.getValue();
                    if (attr.is(DummyGroup.ATTR_MEMBERS_NAME) && values != null && configuration.getUpCaseName()) {
                        List<Object> newValues = new ArrayList<Object>(values.size());
                        for (Object val : values) {
                            newValues.add(StringUtils.upperCase((String) val));
                        }
                        values = newValues;
                    }
                    try {
                        group.removeAttributeValues(name, values);
                        log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), group, group.getAttributeValues(name, Object.class));
                    } catch (SchemaViolationException e) {
                        // The framework should deal with it ... somehow
                        throw new IllegalArgumentException(e.getMessage(), e);
                    }
                }
            }
        } else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
            DummyPrivilege priv;
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                priv = resource.getPrivilegeByName(uid.getUidValue());
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                priv = resource.getPrivilegeById(uid.getUidValue());
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
            if (priv == null) {
                throw new UnknownUidException("Privilege with UID " + uid + " does not exist on resource");
            }
            for (Attribute attr : valuesToRemove) {
                if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
                    throw new IllegalArgumentException("Attempt to change password on privilege");
                } else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
                    throw new IllegalArgumentException("Attempt to remove value from enable attribute");
                } else {
                    String name = attr.getName();
                    try {
                        priv.removeAttributeValues(name, attr.getValue());
                        log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), priv, priv.getAttributeValues(name, Object.class));
                    } catch (SchemaViolationException e) {
                        // The framework should deal with it ... somehow
                        throw new IllegalArgumentException(e.getMessage(), e);
                    }
                }
            }
        } else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
            DummyOrg org;
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                org = resource.getOrgByName(uid.getUidValue());
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                org = resource.getOrgById(uid.getUidValue());
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
            if (org == null) {
                throw new UnknownUidException("Org with UID " + uid + " does not exist on resource");
            }
            for (Attribute attr : valuesToRemove) {
                if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
                    throw new IllegalArgumentException("Attempt to change password on org");
                } else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
                    throw new IllegalArgumentException("Attempt to remove value from enable org");
                } else {
                    String name = attr.getName();
                    try {
                        org.removeAttributeValues(name, attr.getValue());
                        log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), org, org.getAttributeValues(name, Object.class));
                    } catch (SchemaViolationException e) {
                        // The framework should deal with it ... somehow
                        throw new IllegalArgumentException(e.getMessage(), e);
                    }
                }
            }
        } else {
            throw new ConnectorException("Unknown object class " + objectClass);
        }
    } catch (ConnectException e) {
        log.info("removeAttributeValues::exception " + e);
        throw new ConnectionFailedException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        log.info("removeAttributeValues::exception " + e);
        throw new ConnectorIOException(e.getMessage(), e);
    } catch (SchemaViolationException e) {
        log.info("removeAttributeValues::exception " + e);
        throw new InvalidAttributeValueException(e.getMessage(), e);
    } catch (ConflictException e) {
        log.info("removeAttributeValues::exception " + e);
        throw new AlreadyExistsException(e);
    }
    return uid;
}
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) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) DummyObject(com.evolveum.icf.dummy.resource.DummyObject) UnknownUidException(org.identityconnectors.framework.common.exceptions.UnknownUidException) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) DummyPrivilege(com.evolveum.icf.dummy.resource.DummyPrivilege) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ConnectException(java.net.ConnectException)

Example 38 with ConnectException

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

the class DummyConnector method sync.

/**
     * {@inheritDoc}
     */
public void sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler, final OperationOptions options) {
    log.info("sync::begin");
    validate(objectClass);
    Collection<String> attributesToGet = getAttrsToGet(options);
    try {
        int syncToken = (Integer) token.getValue();
        List<DummyDelta> deltas = resource.getDeltasSince(syncToken);
        for (DummyDelta delta : deltas) {
            Class<? extends DummyObject> deltaObjectClass = delta.getObjectClass();
            if (objectClass.is(ObjectClass.ALL_NAME)) {
            // take all changes
            } else if (objectClass.is(ObjectClass.ACCOUNT_NAME)) {
                if (deltaObjectClass != DummyAccount.class) {
                    log.ok("Skipping delta {0} because of objectclass mismatch", delta);
                    continue;
                }
            } else if (objectClass.is(ObjectClass.GROUP_NAME)) {
                if (deltaObjectClass != DummyGroup.class) {
                    log.ok("Skipping delta {0} because of objectclass mismatch", delta);
                    continue;
                }
            }
            SyncDeltaBuilder deltaBuilder = new SyncDeltaBuilder();
            if (deltaObjectClass == DummyAccount.class) {
                deltaBuilder.setObjectClass(ObjectClass.ACCOUNT);
            } else if (deltaObjectClass == DummyGroup.class) {
                deltaBuilder.setObjectClass(ObjectClass.GROUP);
            } else if (deltaObjectClass == DummyPrivilege.class) {
                deltaBuilder.setObjectClass(new ObjectClass(OBJECTCLASS_PRIVILEGE_NAME));
            } else if (deltaObjectClass == DummyOrg.class) {
                deltaBuilder.setObjectClass(new ObjectClass(OBJECTCLASS_ORG_NAME));
            } else {
                throw new IllegalArgumentException("Unknown delta objectClass " + deltaObjectClass);
            }
            SyncDeltaType deltaType;
            if (delta.getType() == DummyDeltaType.ADD || delta.getType() == DummyDeltaType.MODIFY) {
                if (resource.getSyncStyle() == DummySyncStyle.DUMB) {
                    deltaType = SyncDeltaType.CREATE_OR_UPDATE;
                } else {
                    if (delta.getType() == DummyDeltaType.ADD) {
                        deltaType = SyncDeltaType.CREATE;
                    } else {
                        deltaType = SyncDeltaType.UPDATE;
                    }
                }
                if (deltaObjectClass == DummyAccount.class) {
                    DummyAccount account = resource.getAccountById(delta.getObjectId());
                    if (account == null) {
                        throw new IllegalStateException("We have delta for account '" + delta.getObjectId() + "' but such account does not exist");
                    }
                    ConnectorObject cobject = convertToConnectorObject(account, attributesToGet);
                    deltaBuilder.setObject(cobject);
                } else if (deltaObjectClass == DummyGroup.class) {
                    DummyGroup group = resource.getGroupById(delta.getObjectId());
                    if (group == null) {
                        throw new IllegalStateException("We have delta for group '" + delta.getObjectId() + "' but such group does not exist");
                    }
                    ConnectorObject cobject = convertToConnectorObject(group, attributesToGet);
                    deltaBuilder.setObject(cobject);
                } else if (deltaObjectClass == DummyPrivilege.class) {
                    DummyPrivilege privilege = resource.getPrivilegeById(delta.getObjectId());
                    if (privilege == null) {
                        throw new IllegalStateException("We have privilege for group '" + delta.getObjectId() + "' but such privilege does not exist");
                    }
                    ConnectorObject cobject = convertToConnectorObject(privilege, attributesToGet);
                    deltaBuilder.setObject(cobject);
                } else {
                    throw new IllegalArgumentException("Unknown delta objectClass " + deltaObjectClass);
                }
            } else if (delta.getType() == DummyDeltaType.DELETE) {
                deltaType = SyncDeltaType.DELETE;
            } else {
                throw new IllegalStateException("Unknown delta type " + delta.getType());
            }
            deltaBuilder.setDeltaType(deltaType);
            deltaBuilder.setToken(new SyncToken(delta.getSyncToken()));
            Uid uid;
            if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
                uid = new Uid(delta.getObjectName());
            } else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
                if (nameHintChecksEnabled()) {
                    uid = new Uid(delta.getObjectId(), new Name(delta.getObjectName()));
                } else {
                    uid = new Uid(delta.getObjectId());
                }
            } else {
                throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
            }
            deltaBuilder.setUid(uid);
            SyncDelta syncDelta = deltaBuilder.build();
            log.info("sync::handle {0}", syncDelta);
            handler.handle(syncDelta);
        }
    } catch (ConnectException e) {
        log.info("sync::exception " + e);
        throw new ConnectionFailedException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        log.info("sync::exception " + e);
        throw new ConnectorIOException(e.getMessage(), e);
    } catch (SchemaViolationException e) {
        log.info("sync::exception " + e);
        throw new InvalidAttributeValueException(e.getMessage(), e);
    } catch (ConflictException e) {
        log.info("sync::exception " + e);
        throw new AlreadyExistsException(e);
    }
    log.info("sync::end");
}
Also used : ConflictException(com.evolveum.icf.dummy.resource.ConflictException) DummyDelta(com.evolveum.icf.dummy.resource.DummyDelta) FileNotFoundException(java.io.FileNotFoundException) GuardedString(org.identityconnectors.common.security.GuardedString) SchemaViolationException(com.evolveum.icf.dummy.resource.SchemaViolationException) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) ConnectException(java.net.ConnectException) ConnectorIOException(org.identityconnectors.framework.common.exceptions.ConnectorIOException) DummyObjectClass(com.evolveum.icf.dummy.resource.DummyObjectClass) AlreadyExistsException(org.identityconnectors.framework.common.exceptions.AlreadyExistsException) ObjectAlreadyExistsException(com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException) InvalidAttributeValueException(org.identityconnectors.framework.common.exceptions.InvalidAttributeValueException) DummyPrivilege(com.evolveum.icf.dummy.resource.DummyPrivilege) DummyOrg(com.evolveum.icf.dummy.resource.DummyOrg) ConnectionFailedException(org.identityconnectors.framework.common.exceptions.ConnectionFailedException)

Example 39 with ConnectException

use of java.net.ConnectException in project opennms by OpenNMS.

the class Jsr160ConnectionFactory method getMBeanServerConnection.

public static JmxServerConnectionWrapper getMBeanServerConnection(Map<String, String> propertiesMap, InetAddress address) throws IOException {
    final long timeout = DEFAULT_TIMEOUT;
    propertiesMap.putIfAbsent("factory", "STANDARD");
    propertiesMap.putIfAbsent("port", "1099");
    propertiesMap.putIfAbsent("protocol", "rmi");
    propertiesMap.putIfAbsent("urlPath", "/jmxrmi");
    propertiesMap.putIfAbsent("timeout", Long.toString(timeout));
    final Callable<JmxServerConnectionWrapper> task = new Callable<JmxServerConnectionWrapper>() {

        @Override
        public JmxServerConnectionWrapper call() throws Exception {
            return new DefaultJmxConnector().createConnection(address, propertiesMap);
        }
    };
    final Future<JmxServerConnectionWrapper> future = executor.submit(task);
    try {
        final JmxServerConnectionWrapper connectionWrapper = future.get(timeout, TimeUnit.MILLISECONDS);
        return connectionWrapper;
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        final String url = JmxConnectionConfigBuilder.buildFrom(address, propertiesMap).build().getUrl();
        LOG.info("Exception connecting JMXConnectorFactory url {} , Error: {}", url, e.getMessage());
        if (!future.isDone()) {
            future.cancel(true);
            LOG.info(" the task {}", future.isCancelled() ? "was cancelled" : "could not be cancelled");
        }
        throw new ConnectException("Error connecting JMXConnectionFactory  " + url);
    }
}
Also used : JmxServerConnectionWrapper(org.opennms.netmgt.jmx.connection.JmxServerConnectionWrapper) ExecutionException(java.util.concurrent.ExecutionException) Callable(java.util.concurrent.Callable) TimeoutException(java.util.concurrent.TimeoutException) ConnectException(java.net.ConnectException)

Example 40 with ConnectException

use of java.net.ConnectException in project heron by twitter.

the class KafkaUtils method fetchMessages.

/***
   * Fetch messages from kafka
   * @param config
   * @param consumer
   * @param partition
   * @param offset
   * @return
   * @throws TopicOffsetOutOfRangeException
   * @throws FailedFetchException
   * @throws RuntimeException
   */
public static ByteBufferMessageSet fetchMessages(KafkaConfig config, SimpleConsumer consumer, Partition partition, long offset) throws TopicOffsetOutOfRangeException, FailedFetchException, RuntimeException {
    ByteBufferMessageSet msgs = null;
    String topic = partition.topic;
    int partitionId = partition.partition;
    FetchRequestBuilder builder = new FetchRequestBuilder();
    FetchRequest fetchRequest = builder.addFetch(topic, partitionId, offset, config.fetchSizeBytes).clientId(config.clientId).maxWait(config.fetchMaxWait).minBytes(config.minFetchByte).build();
    FetchResponse fetchResponse;
    try {
        fetchResponse = consumer.fetch(fetchRequest);
    // SUPPRESS CHECKSTYLE IllegalCatch
    } catch (Exception e) {
        if (e instanceof ConnectException || e instanceof SocketTimeoutException || e instanceof IOException || e instanceof UnresolvedAddressException) {
            LOG.warn("Network error when fetching messages:", e);
            throw new FailedFetchException(e);
        } else {
            throw new RuntimeException(e);
        }
    }
    if (fetchResponse.hasError()) {
        KafkaError error = KafkaError.getError(fetchResponse.errorCode(topic, partitionId));
        if (error.equals(KafkaError.OFFSET_OUT_OF_RANGE) && config.useStartOffsetTimeIfOffsetOutOfRange) {
            String msg = partition + " Got fetch request with offset out of range: [" + offset + "]";
            LOG.warn(msg);
            throw new TopicOffsetOutOfRangeException(msg);
        } else {
            String message = "Error fetching data from [" + partition + "] for topic [" + topic + "]: [" + error + "]";
            LOG.error(message);
            throw new FailedFetchException(message);
        }
    } else {
        msgs = fetchResponse.messageSet(topic, partitionId);
    }
    return msgs;
}
Also used : FetchResponse(kafka.javaapi.FetchResponse) IOException(java.io.IOException) ByteBufferMessageSet(kafka.javaapi.message.ByteBufferMessageSet) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) SocketTimeoutException(java.net.SocketTimeoutException) FetchRequestBuilder(kafka.api.FetchRequestBuilder) FetchRequest(kafka.api.FetchRequest) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) 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