本文整理汇总了Java中javax.ws.rs.ext.Providers.getContextResolver方法的典型用法代码示例。如果您正苦于以下问题:Java Providers.getContextResolver方法的具体用法?Java Providers.getContextResolver怎么用?Java Providers.getContextResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.ext.Providers
的用法示例。
在下文中一共展示了Providers.getContextResolver方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupResource
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
/**
* Lookup a resource of given <code>resourceType</code> type, either using a suitable {@link ContextResolver} if
* <code>providers</code> is not <code>null</code> and a {@link ContextResolver} for given <code>resourceType</code>
* is available, or trying to obtain the resource from {@link Context} using given <code>resourceType</code> as
* context resource key.
* @param <R> Resource type
* @param caller Caller class
* @param resourceType Resource type to lookup (not null)
* @param providers JAX-RS {@link Providers}, if available
* @return Resource instance, or an empty optional if not available
*/
public static <R> Optional<R> lookupResource(Class<?> caller, Class<R> resourceType, Providers providers) {
ObjectUtils.argumentNotNull(resourceType, "Resource type must be not null");
R resource = null;
// try to use a ContextResolver, if available
ContextResolver<R> resolver = providers.getContextResolver(resourceType, null);
if (resolver != null) {
resource = resolver.getContext(caller);
}
if (resource == null) {
// lookup in context
resource = Context.get()
.resource(resourceType,
(caller != null) ? caller.getClassLoader() : ClassUtils.getDefaultClassLoader())
.orElse(null);
}
return Optional.ofNullable(resource);
}
示例2: testLocateGensonContextResolver
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
@Test
public void testLocateGensonContextResolver() {
Providers providers = instance(Providers.class);
RuntimeDelegate.setInstance(new DefaultRuntimeDelegate());
ContextResolver contextResolver = providers.getContextResolver(Genson.class, MediaType.APPLICATION_JSON_TYPE);
assertNotNull(contextResolver);
assertEquals(TestGensonContextResolver3.class, contextResolver.getClass());
}
示例3: testLocateObjectContextResolver
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
@Test
public void testLocateObjectContextResolver() {
Providers providers = instance(Providers.class);
RuntimeDelegate.setInstance(new DefaultRuntimeDelegate());
ContextResolver contextResolver = providers.getContextResolver(Person.class, MediaType.APPLICATION_JSON_TYPE);
assertNotNull(contextResolver);
assertEquals(TestGensonContextResolver6.class, contextResolver.getClass());
}
示例4: testLocateApplicationContextResolver
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
@Test
public void testLocateApplicationContextResolver() {
Providers providers = instance(Providers.class);
RuntimeDelegate.setInstance(new DefaultRuntimeDelegate());
ContextResolver contextResolver = providers.getContextResolver(Application.class, MediaType.APPLICATION_JSON_TYPE);
assertNotNull(contextResolver);
assertEquals(TestApplicationContextResolver.class, contextResolver.getClass());
}
示例5: locateFactory
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
public static SpearalFactory locateFactory(Configuration configuration, Providers providers) {
ContextResolver<SpearalFactory> resolver = providers.getContextResolver(SpearalFactory.class, APPLICATION_SPEARAL_TYPE);
if (resolver != null)
return resolver.getContext(SpearalFactory.class);
for (Object instance : configuration.getInstances()) {
if (instance instanceof SpearalFactory)
return (SpearalFactory)instance;
}
throw new RuntimeException("Could not locate SpearalFactory in JAX-RS context");
}
示例6: resolveFromContext
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
public static <T> T resolveFromContext(Providers providers, Class<T> clazz, MediaType mediaType, Class<?> type) {
ContextResolver<T> contextResolver = providers.getContextResolver(clazz, mediaType);
if (contextResolver == null) {
throw new RestException("No context resolver found for class " + clazz.getName());
}
return contextResolver.getContext(type);
}
示例7: PersonMessageBodyReader
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
public PersonMessageBodyReader(@Context Application application, @Context UriInfo uriInfo, @Context HttpHeaders httpHeaders, @Context Providers providers) {
ContextResolver<Genson> gensonResolver = providers.getContextResolver(Genson.class, MediaType.APPLICATION_JSON_TYPE);
gensonResolver.getContext(Genson.class);
}
示例8: locate
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
public static ServiceRepository locate(Providers providers) {
ContextResolver<ServiceRepository> resolver = providers.getContextResolver(ServiceRepository.class, MediaType.WILDCARD_TYPE);
return resolver.getContext(null);
}
示例9: getContextFromProvider
import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
private static DiscoveryContext<String> getContextFromProvider(Providers providers)
{
ContextResolver<DiscoveryContext> contextResolver = providers.getContextResolver(DiscoveryContext.class, MediaType.WILDCARD_TYPE);
//noinspection unchecked
return contextResolver.getContext(DiscoveryContext.class);
}