当前位置: 首页>>代码示例>>Java>>正文


Java Configuration类代码示例

本文整理汇总了Java中javax.ws.rs.core.Configuration的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Configuration类属于javax.ws.rs.core包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldRegisterAMultiTypedProviderInstanceWithPriorities

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Test
public void shouldRegisterAMultiTypedProviderInstanceWithPriorities() {
    MultiTypedProvider provider = new MultiTypedProvider();
    Map<Class<?>, Integer> priorities = new HashMap<>();
    priorities.put(ClientRequestFilter.class, 500);
    priorities.put(ClientResponseFilter.class, 501);
    priorities.put(MessageBodyReader.class, 502);
    priorities.put(MessageBodyWriter.class, 503);
    priorities.put(ReaderInterceptor.class, 504);
    priorities.put(WriterInterceptor.class, 505);
    priorities.put(ResponseExceptionMapper.class, 506);
    priorities.put(ParamConverterProvider.class, 507);
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, priorities);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered");
    Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
    assertEquals(contracts.size(), priorities.size(),
        "There should be "+priorities.size()+" provider types registered");
    for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
        Integer contractPriority = contracts.get(priority.getKey());
        assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
    }
}
 
开发者ID:eclipse,项目名称:microprofile-rest-client,代码行数:25,代码来源:AdditionalRegistrationTest.java

示例2: configure

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE,
            String.class);
    // Other JSON providers registered.
    if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
        return false;
    }
    // Disable other JSON providers.
    context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
    // Register FastJson.
    if (!config.isRegistered(FastJsonProvider.class)) {
        //DisableCircularReferenceDetect
        FastJsonProvider fastJsonProvider = new FastJsonProvider();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        //fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.BrowserSecure);

        fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);

        fastJsonProvider.setFastJsonConfig(fastJsonConfig);

        context.register(fastJsonProvider, MessageBodyReader.class, MessageBodyWriter.class);
    }
    return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:Issue1341.java

示例3: testRegister

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Test
public void testRegister() throws Exception {
	logger.info("start Register test");
	Client client = newClient();
	Map<Class<?>, Integer> myContracts = new HashMap<Class<?>, Integer>();
	myContracts.put(Feature.class, 1200);
	client.register(MyComponent.class, myContracts);
	Configuration configuration = client.getConfiguration();
	Set<Class<?>> classes = configuration.getClasses();
	for (Class<?> clazz : classes) {
		if (MyComponent.class.isAssignableFrom(clazz)) {
			Map<Class<?>, Integer> contracts = configuration.getContracts(clazz);
			int priority = contracts.get(Feature.class);
			assertTrue("Only standard: Feature, DynamicFeature, WriterInterceptor, "
					+ "ReaderInterceptor, ContainerResponseFilter, " + "ContainerRequestFilter, "
					+ "ClientResponseFilter, ClientRequestFilter, " + "ExceptionMapper, MessageBodyWriter, "
					+ "MessageBodyReader,ParamConverterProvider or implemented: InjectorFactory, "
					+ "StringParameterUnmarshaller, StringConverter, " + "ContextResolver, PostProcessInterceptor, "
					+ "PreProcessInterceptor, ClientExecutionInterceptor, ClientExceptionMapper"
					+ "can be registered as contracts. Registered priority", priority == 1200);
		}
	}
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:24,代码来源:ComponentTestCase.java

示例4: registerJerseyJsonFeature

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
/**
 * Register a Jersey JSON provider feature only if another JSON provider is not already registered, checking
 * {@link #JERSEY_JSON_PROVIDER_PROPERTY} property value.
 * @param context Feature context
 * @param feature Feature to register
 * @param featureName Feature name to register
 * @return <code>true</code> if feature was registered, <code>false</code> otherwise
 */
private static boolean registerJerseyJsonFeature(FeatureContext context, Class<? extends Feature> feature,
		String featureName) {
	final Configuration config = context.getConfiguration();

	final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
			JERSEY_JSON_PROVIDER_PROPERTY, featureName, String.class);
	if (!featureName.equalsIgnoreCase(jsonFeature)) {
		// Other JSON providers registered
		return false;
	}
	// Disable other JSON providers
	context.property(
			PropertiesHelper.getPropertyNameForRuntime(JERSEY_JSON_PROVIDER_PROPERTY, config.getRuntimeType()),
			featureName);
	// Register
	if (!config.isRegistered(feature)) {
		context.register(feature);
	}
	return true;
}
 
开发者ID:holon-platform,项目名称:holon-json,代码行数:29,代码来源:GsonAutoDiscoverable.java

示例5: testApiKey

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Test
public void testApiKey() {
    final User user = new User();

    final ApiKey apiKey = new ApiKey();
    apiKey.setValue("xyz");
    apiKey.setUser(user);

    final String authorization = AuthUtils.create(apiKey.getValue(), "");

    final SecurityDao dao = mock(SecurityDao.class);
    when(dao.findApiKeyByValue(eq("xyz"))).thenReturn(apiKey);
    when(dao.read(eq(User.class), eq(user.getId()))).thenReturn(user);

    final Configuration config = mock(Configuration.class);
    when(config.getProperty(eq(MinijaxProperties.SECURITY_USER_CLASS))).thenReturn(User.class);

    final Security<User> security = new Security<>(dao, config, authorization, null);
    security.requireLogin();
    assertTrue(security.isLoggedIn());
    assertNotNull(security.getUserPrincipal());
    assertEquals(user, security.getUserPrincipal());
    assertEquals(user, security.getUserPrincipal());
    assertEquals(SecurityContext.BASIC_AUTH, security.getAuthenticationScheme());
}
 
开发者ID:minijax,项目名称:minijax,代码行数:26,代码来源:SecurityTest.java

示例6: testApiKeyDeleted

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Test
public void testApiKeyDeleted() {
    final User user = new User();

    final ApiKey apiKey = new ApiKey();
    apiKey.setValue("xyz");
    apiKey.setUser(user);
    apiKey.setDeleted(true);

    final String authorization = AuthUtils.create(apiKey.getValue(), "");

    final SecurityDao dao = mock(SecurityDao.class);
    when(dao.findApiKeyByValue(eq("xyz"))).thenReturn(apiKey);

    final Configuration config = mock(Configuration.class);
    final Security<User> security = new Security<>(dao, config, authorization, null);
    assertFalse(security.isLoggedIn());
    assertNull(security.getUserPrincipal());
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:SecurityTest.java

示例7: testInvalidSessionToken

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Test(expected = BadRequestException.class)
public void testInvalidSessionToken() {
    final User user = new User();

    final UserSession session = new UserSession();
    session.setUser(user);

    final String cookie = session.getId().toString();

    final SecurityDao dao = mock(SecurityDao.class);
    when(dao.read(eq(UserSession.class), eq(session.getId()))).thenReturn(session);
    when(dao.read(eq(User.class), eq(user.getId()))).thenReturn(user);

    final Configuration config = mock(Configuration.class);
    when(config.getProperty(eq(MinijaxProperties.SECURITY_USER_CLASS))).thenReturn(User.class);

    final Security<User> security = new Security<>(dao, config, null, cookie);
    security.validateSession("not-the-right-token");
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:SecurityTest.java

示例8: testLogout

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Test
public void testLogout() {
    final User user = new User();

    final UserSession session = new UserSession();
    session.setUser(user);

    final String cookie = session.getId().toString();

    final SecurityDao dao = mock(SecurityDao.class);
    when(dao.read(eq(UserSession.class), eq(session.getId()))).thenReturn(session);
    when(dao.read(eq(User.class), eq(user.getId()))).thenReturn(user);

    final Configuration config = mock(Configuration.class);
    when(config.getProperty(eq(MinijaxProperties.SECURITY_USER_CLASS))).thenReturn(User.class);

    final Security<User> security = new Security<>(dao, config, null, cookie);
    final NewCookie newCookie = security.logout();
    assertNotNull(newCookie);
    assertEquals("", newCookie.getValue());

    verify(dao).purge(eq(session));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:24,代码来源:SecurityTest.java

示例9: shouldRegisterAMultiTypedProviderClassWithPriorities

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Test
public void shouldRegisterAMultiTypedProviderClassWithPriorities() {
    Map<Class<?>, Integer> priorities = new HashMap<>();
    priorities.put(ClientRequestFilter.class, 500);
    priorities.put(ClientResponseFilter.class, 501);
    priorities.put(MessageBodyReader.class, 502);
    priorities.put(MessageBodyWriter.class, 503);
    priorities.put(ReaderInterceptor.class, 504);
    priorities.put(WriterInterceptor.class, 505);
    priorities.put(ResponseExceptionMapper.class, 506);
    priorities.put(ParamConverterProvider.class, 507);
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, priorities);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
    assertEquals(contracts.size(), priorities.size(),
        "There should be "+priorities.size()+" provider types registered");
    for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
        Integer contractPriority = contracts.get(priority.getKey());
        assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
    }
}
 
开发者ID:eclipse,项目名称:microprofile-rest-client,代码行数:23,代码来源:AdditionalRegistrationTest.java

示例10: configure

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
  Configuration configuration = context.getConfiguration();
  Boolean enabled = PropertyHelper.getProperty(configuration, RestServerV2.FIRST_TIME_API_ENABLE);
  Boolean testApiEnabled = PropertyHelper.getProperty(configuration, RestServerV2.TEST_API_ENABLE);

  // Default is not enabled
  if (enabled == null || !enabled) {
    return false;
  }

  boolean allowTestApis = testApiEnabled != null && testApiEnabled;

  // this is handled separately from firstTimeApi because we may enable the api only on master
  // but still register the filer on all nodes
  context.register(BootstrapResource.class);
  if (allowTestApis) {
    context.register(NoUserTestFilter.class);
  } else {
    context.register(NoUserFilter.class);
  }

  return true;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:25,代码来源:FirstTimeFeature.java

示例11: configure

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
  Configuration configuration = context.getConfiguration();
  Boolean enabled = PropertyHelper.getProperty(configuration, RestServerV2.TEST_API_ENABLE);

  // Default is not enabled
  if (enabled == null || !enabled) {
    return false;
  }

  for (Class<?> resource : scanResult.getAnnotatedClasses(RestResourceUsedForTesting.class)) {
    context.register(resource);
  }

  return true;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:TestResourcesFeature.java

示例12: configure

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
  final Configuration configuration = context.getConfiguration();

  Boolean disabled = PropertyHelper.getProperty(configuration, RestServerV2.DAC_AUTH_FILTER_DISABLE);
  // Default is not disabled
  if (disabled != null && disabled) {
    return false;
  }

  context.register(DACAuthFilter.class);
  if (!configuration.isRegistered(RolesAllowedDynamicFeature.class)) {
    context.register(RolesAllowedDynamicFeature.class);
  }
  return true;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:DACAuthFilterFeature.java

示例13: configure

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
public boolean configure(final FeatureContext context) {
	final Configuration config = context.getConfiguration();
	final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(), InternalProperties.JSON_FEATURE, JSON_FEATURE,
			String.class);
	// Other JSON providers registered.
	if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
		return false;
	}
	// Disable other JSON providers.
	context.property(PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()), JSON_FEATURE);
	// Register FastJson.
	if (!config.isRegistered(FastJsonProvider.class)) {
		context.register(FastJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
	}
	return true;
}
 
开发者ID:ChineseLincoln,项目名称:JerseyRestful,代码行数:17,代码来源:FastJsonFeature.java

示例14: configure

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Override
public void configure(FeatureContext context) {
    final int priorityInc = 3000;

    // Jersey MOXY provider have higher priority(7000), so we need set higher than it
    int priority = Priorities.USER + priorityInc;
    Configuration config = context.getConfiguration();

    if (!config.isRegistered(ParsecValidationExceptionMapper.class)) {
        context.register(ParsecValidationExceptionMapper.class, priority);
    }
    if (!config.isRegistered(ValidationConfigurationContextResolver.class)) {
        context.register(ValidationConfigurationContextResolver.class, priority);
    }
    if (!config.isRegistered(ParsecMoxyProvider.class)) {
        context.register(ParsecMoxyProvider.class, priority);
    }
    if (!config.isRegistered(JaxbExceptionMapper.class)) {
        context.register(JaxbExceptionMapper.class, priority);
    }
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:22,代码来源:ParsecValidationAutoDiscoverable.java

示例15: configure

import javax.ws.rs.core.Configuration; //导入依赖的package包/类
@Override
public boolean configure(FeatureContext context) {
    Configuration configuration = context.getConfiguration();
    if (!configuration.isRegistered(ConfigPropertyResolver.class)) {
        LOGGER.debug("Register ConfigPropertyFeature");
        context.register(ConfigPropertyResolver.class);
        context.register(new AbstractBinder() {
            @Override
            protected void configure() {
                bind(ConfigPropertyResolver.class)
                        .to(new TypeLiteral<InjectionResolver<ConfigProperty>>() {})
                        .in(Singleton.class);
            }
        });
    }
    return true;
}
 
开发者ID:protoxme,项目名称:protox-webapp-archetype,代码行数:18,代码来源:ConfigPropertyFeature.java


注:本文中的javax.ws.rs.core.Configuration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。