javax.ws.rs.ConstrainedTo Java Examples

The following examples show how to use javax.ws.rs.ConstrainedTo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Jersey2Plugin.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
private Set<Class<?>> filterClasses(Collection<Class<?>> classes) {
    Set<Class<?>> result = new HashSet<>();

    if (classes != null) {
        for (Class<?> aClass : classes) {
            ConstrainedTo annotation = aClass.getAnnotation(ConstrainedTo.class);
            if (annotation == null || annotation.value() == RuntimeType.SERVER) {
                result.add(aClass);
            }
        }
    }

    return result;
}
 
Example #2
Source File: ConfigurableImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean checkConstraints(Object provider) {
    Class<?> providerClass = provider.getClass();
    ConstrainedTo providerConstraint = providerClass.getAnnotation(ConstrainedTo.class);
    if (providerConstraint != null) {
        RuntimeType currentRuntime = config.getRuntimeType();
        RuntimeType providerRuntime = providerConstraint.value();
        // need to check (1) whether the registration is occurring in the specified runtime type
        // and (2) does the provider implement an invalid interface based on the constrained runtime type
        if (!providerRuntime.equals(currentRuntime)) {
            LOG.warning("Provider " + provider + " cannot be registered in this " + currentRuntime
                        + " runtime because it is constrained to " + providerRuntime + " runtimes.");
            return false;
        }
        
        Class<?>[] restrictedInterfaces = RuntimeType.CLIENT.equals(providerRuntime) ? RESTRICTED_CLASSES_IN_CLIENT
                                                                                     : RESTRICTED_CLASSES_IN_SERVER;
        for (Class<?> restrictedContract : restrictedInterfaces) {
            if (restrictedContract.isAssignableFrom(providerClass)) {
                RuntimeType opposite = RuntimeType.CLIENT.equals(providerRuntime) ? RuntimeType.SERVER
                                                                                  : RuntimeType.CLIENT;
                LOG.warning("Provider " + providerClass.getName() + " is invalid - it is constrained to "
                    + providerRuntime + " runtimes but implements a " + opposite + " interface ");
                return false;
            }
        }
    }
    return true;
}
 
Example #3
Source File: CxfRsHttpListener.java    From tomee with Apache License 2.0 5 votes vote down vote up
private boolean isNotServerProvider(Class<?> clazz) {
    final ConstrainedTo ct = clazz.getAnnotation(ConstrainedTo.class);
    if (ct != null && ct.value() != RuntimeType.SERVER) {
        if (!FAIL_ON_CONSTRAINED_TO) {
            LOGGER.warning(clazz + " is not a SERVER provider, ignoring");
            return true;
        }
        throw new IllegalArgumentException(clazz + " is not a SERVER provider");
    }
    return false;
}