Search in sources :

Example 11 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class AbstractQueue method addConsumer.

// ------ Manage Consumers
@Override
public <T extends ConsumerTarget<T>> QueueConsumerImpl<T> addConsumer(final T target, final FilterManager filters, final Class<? extends ServerMessage> messageClass, final String consumerName, final EnumSet<ConsumerOption> optionSet, final Integer priority) throws ExistingExclusiveConsumer, ExistingConsumerPreventsExclusive, ConsumerAccessRefused, QueueDeleted {
    try {
        final QueueConsumerImpl<T> queueConsumer = getTaskExecutor().run(new Task<QueueConsumerImpl<T>, Exception>() {

            @Override
            public QueueConsumerImpl<T> execute() throws Exception {
                return addConsumerInternal(target, filters, messageClass, consumerName, optionSet, priority);
            }

            @Override
            public String getObject() {
                return AbstractQueue.this.toString();
            }

            @Override
            public String getAction() {
                return "add consumer";
            }

            @Override
            public String getArguments() {
                return "target=" + target + ", consumerName=" + consumerName + ", optionSet=" + optionSet;
            }
        });
        target.consumerAdded(queueConsumer);
        if (isEmpty()) {
            target.noMessagesAvailable();
        }
        target.updateNotifyWorkDesired();
        target.notifyWork();
        return queueConsumer;
    } catch (ExistingExclusiveConsumer | ConsumerAccessRefused | ExistingConsumerPreventsExclusive | QueueDeleted | RuntimeException e) {
        throw e;
    } catch (Exception e) {
        // Should never happen
        throw new ServerScopedRuntimeException(e);
    }
}
Also used : SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) MessageDestinationIsAlternateException(org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException) ParseException(org.apache.qpid.server.filter.selector.ParseException) VirtualHostUnavailableException(org.apache.qpid.server.virtualhost.VirtualHostUnavailableException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException) MessageDeletedException(org.apache.qpid.server.message.MessageDeletedException) IOException(java.io.IOException) AccessControlException(java.security.AccessControlException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 12 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class FileTrustStoreImpl method validateTrustStore.

private static void validateTrustStore(FileTrustStore trustStore) {
    KeyStore keyStore;
    try {
        keyStore = initializeKeyStore(trustStore);
    } catch (Exception e) {
        final String message;
        if (e instanceof IOException && e.getCause() != null && e.getCause() instanceof UnrecoverableKeyException) {
            message = "Check trust store password. Cannot instantiate trust store from '" + trustStore.getStoreUrl() + "'.";
        } else {
            message = "Cannot instantiate trust store from '" + trustStore.getStoreUrl() + "'.";
        }
        throw new IllegalConfigurationException(message, e);
    }
    try {
        final Enumeration<String> aliasesEnum = keyStore.aliases();
        boolean certificateFound = false;
        while (aliasesEnum.hasMoreElements()) {
            String alias = aliasesEnum.nextElement();
            if (keyStore.isCertificateEntry(alias)) {
                certificateFound = true;
                break;
            }
        }
        if (!certificateFound) {
            throw new IllegalConfigurationException("Trust store must contain at least one certificate.");
        }
    } catch (KeyStoreException e) {
        throw new ServerScopedRuntimeException("Trust store has not been initialized", e);
    }
    try {
        TrustManagerFactory.getInstance(trustStore.getTrustManagerFactoryAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalConfigurationException("Unknown trustManagerFactoryAlgorithm: " + trustStore.getTrustManagerFactoryAlgorithm());
    }
}
Also used : UnrecoverableKeyException(java.security.UnrecoverableKeyException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 13 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class AbstractConfiguredObject method automatedSetValue.

private void automatedSetValue(final String name, Object value) {
    try {
        final ConfiguredAutomatedAttribute attribute = (ConfiguredAutomatedAttribute) _attributeTypes.get(name);
        if (value == null && !"".equals(attribute.defaultValue())) {
            value = attribute.defaultValue();
        }
        ConfiguredObjectTypeRegistry.AutomatedField field = _automatedFields.get(name);
        if (field.getPreSettingAction() != null) {
            field.getPreSettingAction().invoke(this);
        }
        Object desiredValue = attribute.convert(value, this);
        field.getField().set(this, desiredValue);
        if (field.getPostSettingAction() != null) {
            field.getPostSettingAction().invoke(this);
        }
    } catch (IllegalAccessException e) {
        throw new ServerScopedRuntimeException("Unable to set the automated attribute " + name + " on the configure object type " + getClass().getName(), e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw new ServerScopedRuntimeException("Unable to set the automated attribute " + name + " on the configure object type " + getClass().getName(), e);
    }
}
Also used : ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 14 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class AbstractSystemConfig method makeActive.

protected ListenableFuture<Void> makeActive() {
    final EventLogger eventLogger = _eventLogger;
    final EventLogger startupLogger = initiateStartupLogging();
    try {
        final Container<?> container = initiateStoreAndRecovery();
        container.setEventLogger(startupLogger);
        final SettableFuture<Void> returnVal = SettableFuture.create();
        addFutureCallback(container.openAsync(), new FutureCallback() {

            @Override
            public void onSuccess(final Object result) {
                State state = container.getState();
                if (state == State.ACTIVE) {
                    startupLogger.message(BrokerMessages.READY());
                    container.setEventLogger(eventLogger);
                    returnVal.set(null);
                } else {
                    returnVal.setException(new ServerScopedRuntimeException("Broker failed reach ACTIVE state (state is " + state + ")"));
                }
            }

            @Override
            public void onFailure(final Throwable t) {
                returnVal.setException(t);
            }
        }, getTaskExecutor());
        return returnVal;
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : EventLogger(org.apache.qpid.server.logging.EventLogger) IOException(java.io.IOException) FutureCallback(com.google.common.util.concurrent.FutureCallback) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 15 with ServerScopedRuntimeException

use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.

the class ConfiguredObjectInjectedStatistic method getValue.

@Override
public T getValue(final C configuredObject) {
    try {
        Object[] params = new Object[1 + _staticParams.length];
        params[0] = configuredObject;
        for (int i = 0; i < _staticParams.length; i++) {
            params[i + 1] = _staticParams[i];
        }
        return (T) _method.invoke(null, params);
    } catch (IllegalAccessException e) {
        throw new ServerScopedRuntimeException("Unable to get value for '" + getName() + "' from configured object of category " + configuredObject.getCategoryClass().getSimpleName(), e);
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        if (targetException instanceof RuntimeException) {
            throw (RuntimeException) targetException;
        } else if (targetException instanceof Error) {
            throw (Error) targetException;
        } else {
            // This should never happen as it would imply a getter which is declaring a checked exception
            throw new ServerScopedRuntimeException("Unable to get value for '" + getName() + "' from configured object of category " + configuredObject.getCategoryClass().getSimpleName(), e);
        }
    }
}
Also used : ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Aggregations

ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)45 IOException (java.io.IOException)17 GeneralSecurityException (java.security.GeneralSecurityException)10 Map (java.util.Map)10 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 URL (java.net.URL)9 InputStream (java.io.InputStream)8 HttpURLConnection (java.net.HttpURLConnection)8 ConnectionBuilder (org.apache.qpid.server.util.ConnectionBuilder)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)6 TrustStore (org.apache.qpid.server.model.TrustStore)6 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)6 IdentityResolverException (org.apache.qpid.server.security.auth.manager.oauth2.IdentityResolverException)6 Field (java.lang.reflect.Field)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3