Search in sources :

Example 36 with ServerScopedRuntimeException

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

the class BDBHARemoteReplicationNodeImpl method onDelete.

@Override
protected ListenableFuture<Void> onDelete() {
    if (!_nodeLeft) {
        SettableFuture<Void> future = SettableFuture.create();
        String nodeName = getName();
        boolean deletionAllowed;
        try {
            getEventLogger().message(_virtualHostNodeLogSubject, HighAvailabilityMessages.DELETED());
            deletionAllowed = _replicatedEnvironmentFacade.removeNodeFromGroup(nodeName);
            if (deletionAllowed) {
                future.set(null);
            } else {
                future.setException(new IllegalStateTransitionException(String.format("Node '%s' cannot be deleted when role is a master", nodeName)));
            }
        } catch (ServerScopedRuntimeException e) {
            future.setException(e);
            throw e;
        } catch (RuntimeException e) {
            future.setException(new IllegalStateTransitionException(String.format("Unexpected exception on node '%s' deletion", nodeName), e));
        }
        return future;
    } else {
        return super.onDelete();
    }
}
Also used : ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 37 with ServerScopedRuntimeException

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

the class ConfiguredDerivedInjectedAttribute 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)

Example 38 with ServerScopedRuntimeException

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

the class ConfiguredObjectInjectedOperation method perform.

@Override
public Object perform(C subject, Map<String, Object> parameters) {
    if (!_validator.appliesToType((Class<? extends ConfiguredObject<?>>) subject.getClass())) {
        throw new IllegalArgumentException("Operation " + _operation.getName() + " cannot be used on an object of type " + subject.getClass().getSimpleName());
    } else {
        Set<String> providedNames = new HashSet<>(parameters.keySet());
        providedNames.removeAll(_validNames);
        if (!providedNames.isEmpty()) {
            throw new IllegalArgumentException("Parameters " + providedNames + " are not accepted by " + getName());
        }
        Object[] paramValues = new Object[1 + _staticParams.length + _params.size()];
        paramValues[0] = subject;
        for (int i = 0; i < _staticParams.length; i++) {
            paramValues[i + 1] = _staticParams[i];
        }
        for (int i = 0; i < _params.size(); i++) {
            paramValues[i + 1 + _staticParams.length] = getParameterValue(subject, parameters, _params.get(i));
        }
        try {
            return _operation.invoke(null, paramValues);
        } catch (IllegalAccessException e) {
            throw new ServerScopedRuntimeException(e);
        } catch (InvocationTargetException e) {
            if (e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
            } else if (e.getCause() instanceof Error) {
                throw (Error) e.getCause();
            } else {
                throw new ServerScopedRuntimeException(e);
            }
        }
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 39 with ServerScopedRuntimeException

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

the class ConfiguredObjectTypeRegistry method addStateTransitions.

private void addStateTransitions(final Class<? extends ConfiguredObject> clazz, final Map<State, Map<State, Method>> map) {
    for (Method m : clazz.getDeclaredMethods()) {
        if (m.isAnnotationPresent(StateTransition.class)) {
            if (ListenableFuture.class.isAssignableFrom(m.getReturnType())) {
                if (m.getParameterTypes().length == 0) {
                    m.setAccessible(true);
                    StateTransition annotation = m.getAnnotation(StateTransition.class);
                    for (State state : annotation.currentState()) {
                        addStateTransition(state, annotation.desiredState(), m, map);
                    }
                } else {
                    throw new ServerScopedRuntimeException("A state transition method must have no arguments. Method " + m.getName() + " on " + clazz.getName() + " does not meet this criteria.");
                }
            } else {
                throw new ServerScopedRuntimeException("A state transition method must return a ListenableFuture. Method " + m.getName() + " on " + clazz.getName() + " does not meet this criteria.");
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 40 with ServerScopedRuntimeException

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

the class ConfiguredObjectTypeRegistry method findField.

private AutomatedField findField(final ConfiguredObjectAttribute<?, ?> attr, Class<?> objClass) {
    Class<?> clazz = objClass;
    while (clazz != null) {
        for (Field field : clazz.getDeclaredFields()) {
            if (field.isAnnotationPresent(ManagedAttributeField.class) && field.getName().equals("_" + attr.getName().replace('.', '_'))) {
                try {
                    ManagedAttributeField annotation = field.getAnnotation(ManagedAttributeField.class);
                    field.setAccessible(true);
                    Method beforeSet;
                    if (!"".equals(annotation.beforeSet())) {
                        beforeSet = clazz.getDeclaredMethod(annotation.beforeSet());
                        beforeSet.setAccessible(true);
                    } else {
                        beforeSet = null;
                    }
                    Method afterSet;
                    if (!"".equals(annotation.afterSet())) {
                        afterSet = clazz.getDeclaredMethod(annotation.afterSet());
                        afterSet.setAccessible(true);
                    } else {
                        afterSet = null;
                    }
                    return new AutomatedField(field, beforeSet, afterSet);
                } catch (NoSuchMethodException e) {
                    throw new ServerScopedRuntimeException("Cannot find method referenced by annotation for pre/post setting action", e);
                }
            }
        }
        clazz = clazz.getSuperclass();
    }
    if (objClass.isInterface() || Modifier.isAbstract(objClass.getModifiers())) {
        return null;
    }
    throw new ServerScopedRuntimeException("Unable to find field definition for automated field " + attr.getName() + " in class " + objClass.getName());
}
Also used : Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) 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