Java Code Examples for javax.ws.rs.RuntimeType#SERVER

The following examples show how to use javax.ws.rs.RuntimeType#SERVER . 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: CoreFeature.java    From krazo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {

    // RESTEasy seems to ignore @ConstrainedTo in some cases
    if (context.getConfiguration().getRuntimeType() == RuntimeType.SERVER) {

        // https://issues.apache.org/jira/browse/CXF-7501
        // https://issues.apache.org/jira/browse/TOMEE-2122
        if (servletContext == null) {
            log.warning("The ServletContext wasn't injected into the JAX-RS Feature class");
        }

        Initializer.initialize(context, servletContext);
        return true;

    }
    return false;

}
 
Example 2
Source File: OzarkCoreFeature.java    From ozark with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {

    // RESTEasy seems to ignore @ConstrainedTo in some cases
    if (context.getConfiguration().getRuntimeType() == RuntimeType.SERVER) {

        // https://issues.apache.org/jira/browse/CXF-7501
        // https://issues.apache.org/jira/browse/TOMEE-2122
        if (servletContext == null) {
            log.warning("The ServletContext wasn't injected into the JAX-RS Feature class");
        }

        OzarkInitializer.initialize(context, servletContext);
        return true;

    }
    return false;

}
 
Example 3
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidContract() {
    TestHandler handler = new TestHandler();
    LogUtils.getL7dLogger(ConfigurationImpl.class).addHandler(handler);

    ConfigurationImpl c = new ConfigurationImpl(RuntimeType.SERVER);
    ContainerResponseFilter filter = new ContainerResponseFilterImpl();
    assertFalse(c.register(filter,
                           Collections.<Class<?>, Integer>singletonMap(MessageBodyReader.class, 1000)));

    for (String message : handler.messages) {
        if (message.startsWith("WARN") && message.contains("does not implement specified contract")) {
            return; // success
        }
    }
    fail("did not log expected message");
}
 
Example 4
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test 
public void testIsEnabledWithMultipleFeaturesOfSameType() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);

    featureContext.register(new DisablableFeature());
    featureContext.register(new DisablableFeature());
    featureContext.register(new DisablableFeature());

    Configuration config = configurable.getConfiguration();
    assertEquals(3, config.getInstances().size());
    assertFalse(config.isEnabled(DisablableFeature.class));

    DisablableFeature enabledFeature = new DisablableFeature();
    enabledFeature.enabled = true;

    featureContext.register(enabledFeature);
    assertEquals(4, config.getInstances().size());
    assertTrue(config.isEnabled(DisablableFeature.class));

    featureContext.register(new DisablableFeature());
    assertEquals(5, config.getInstances().size());
    assertTrue(config.isEnabled(DisablableFeature.class));
}
 
Example 5
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 6
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 7
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void doTestIsFilterRegistered(Object provider, Class<?> providerClass) throws Exception {
    ConfigurationImpl c = new ConfigurationImpl(RuntimeType.SERVER);
    assertTrue(c.register(provider,
                          Collections.<Class<?>, Integer>singletonMap(ContainerResponseFilter.class, 1000)));
    assertTrue(c.isRegistered(provider));
    assertFalse(c.isRegistered(providerClass.newInstance()));
    assertTrue(c.isRegistered(providerClass));
    assertFalse(c.isRegistered(ContainerResponseFilter.class));
    assertFalse(c.register(provider,
                           Collections.<Class<?>, Integer>singletonMap(ContainerResponseFilter.class, 1000)));
    assertFalse(c.register(providerClass,
                           Collections.<Class<?>, Integer>singletonMap(ContainerResponseFilter.class, 1000)));
}
 
Example 8
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubClassIsRegisteredOnConfigurable() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(ContainerResponseFilterSubClassImpl.class);
    Configuration config = configurable.getConfiguration();
    Map<Class<?>, Integer> contracts = config.getContracts(ContainerResponseFilter.class);
    assertEquals(1, contracts.size());
    assertTrue(contracts.containsKey(ContainerResponseFilter.class));
}
 
Example 9
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testClientFilterContractsOnServerFeatureIsRejected() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(TestFilter.class);
    Configuration config = configurable.getConfiguration();
    Map<Class<?>, Integer> contracts = config.getContracts(TestFilter.class);
    assertFalse(contracts.containsKey(ClientRequestFilter.class));
    assertFalse(contracts.containsKey(ClientResponseFilter.class));
    assertTrue(contracts.containsKey(ContainerRequestFilter.class));
    assertTrue(contracts.containsKey(ContainerResponseFilter.class));
}
 
Example 10
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeatureDisabledClass() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(DisablableFeature.class);

    Configuration config = configurable.getConfiguration();
    assertFalse(config.isEnabled(DisablableFeature.class));
}
 
Example 11
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeatureDisabledInstance() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    Feature feature = new DisablableFeature();
    featureContext.register(feature);

    Configuration config = configurable.getConfiguration();
    assertFalse(config.isEnabled(feature));
}
 
Example 12
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;
}
 
Example 13
Source File: ConfigurationImpl.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public RuntimeType getRuntimeType() {
	return RuntimeType.SERVER;
}
 
Example 14
Source File: CdiServerConfigurableFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
CdiServerFeatureContextConfigurable(FeatureContext mc, BeanManager beanManager) {
    super(mc, RuntimeType.SERVER);
    this.instantiator = new CdiInstantiator(beanManager);
}
 
Example 15
Source File: ServerProviderFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected ServerFeatureContextConfigurable(FeatureContext mc) {
    super(mc, RuntimeType.SERVER);
}
 
Example 16
Source File: ServerProviderFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public RuntimeType getRuntimeType() {
    return RuntimeType.SERVER;
}