本文整理汇总了Java中javax.ws.rs.ext.ContextResolver类的典型用法代码示例。如果您正苦于以下问题:Java ContextResolver类的具体用法?Java ContextResolver怎么用?Java ContextResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextResolver类属于javax.ws.rs.ext包,在下文中一共展示了ContextResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPropertySetRefIntrospector
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
/**
* Get the {@link PropertySetRefIntrospector} instance to use.
* @return The {@link PropertySetRefIntrospector} instance to use, from {@link ContextResolver} if available or the
* default one
*/
private PropertySetRefIntrospector getPropertySetRefIntrospector() {
if (propertySetRefIntrospector == null) {
// init using a contextresolver, if available
ContextResolver<PropertySetRefIntrospector> contextResolver = providers
.getContextResolver(PropertySetRefIntrospector.class, MediaType.APPLICATION_JSON_TYPE);
if (contextResolver != null) {
propertySetRefIntrospector = contextResolver.getContext(PropertySetRefIntrospector.class);
}
if (propertySetRefIntrospector == null) {
// use default
propertySetRefIntrospector = PropertySetRefIntrospector.getDefault();
}
}
return propertySetRefIntrospector;
}
示例2: getGson
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
/**
* Get the {@link Gson} instance to use.
* @return The {@link Gson} instance to use, from {@link ContextResolver} if available or the default one
*/
private Gson getGson() {
if (gson == null) {
// init using a contextresolver, if available
ContextResolver<Gson> contextResolver = providers.getContextResolver(Gson.class,
MediaType.APPLICATION_JSON_TYPE);
if (contextResolver != null) {
gson = contextResolver.getContext(Gson.class);
}
if (gson == null) {
// use default
gson = GsonConfiguration.builder().create();
}
}
return gson;
}
示例3: configureJaxrsApplication
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
public void configureJaxrsApplication() {
AccountProvider provider = id -> { // <5>
// a test provider wich always returns an Account with given id and s3cr3t as password
return Optional.ofNullable(Account.builder(id).credentials(Credentials.builder().secret("s3cr3t").build())
.enabled(true).build());
};
Realm realm = Realm.builder() // <6>
.resolver(AuthenticationToken.httpBasicResolver()) // <7>
.authenticator(Account.authenticator(provider)) // <8>
.withDefaultAuthorizer().build();
ContextResolver<Realm> realmContextResolver = new ContextResolver<Realm>() { // <9>
@Override
public Realm getContext(Class<?> type) {
return realm;
}
};
register(realmContextResolver); // <10>
}
示例4: getPropertySetRefIntrospector
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
/**
* Get the {@link PropertySetRefIntrospector} instance to use.
* @return The {@link PropertySetRefIntrospector} instance to use, from {@link ContextResolver} if available or the
* default one
*/
private PropertySetRefIntrospector getPropertySetRefIntrospector() {
if (_propertySetRefIntrospector == null) {
// init using a contextresolver, if available
ContextResolver<PropertySetRefIntrospector> contextResolver = providers
.getContextResolver(PropertySetRefIntrospector.class, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
if (contextResolver != null) {
_propertySetRefIntrospector = contextResolver.getContext(PropertySetRefIntrospector.class);
}
if (_propertySetRefIntrospector == null) {
// use default
_propertySetRefIntrospector = PropertySetRefIntrospector.getDefault();
}
}
return _propertySetRefIntrospector;
}
示例5: getSerializer
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
/**
* Get the {@link FormDataPropertyValueSerializer} instance to use.
* @return The {@link FormDataPropertyValueSerializer} instance to use, from {@link ContextResolver} if available or
* the default one
*/
private FormDataPropertyValueSerializer getSerializer() {
if (_serializer == null) {
// init using a contextresolver, if available
ContextResolver<FormDataPropertyValueSerializer> contextResolver = providers.getContextResolver(
FormDataPropertyValueSerializer.class, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
if (contextResolver != null) {
_serializer = contextResolver.getContext(FormDataPropertyValueSerializer.class);
}
if (_serializer == null) {
// use default
_serializer = FormDataPropertyValueSerializer.getDefault();
}
}
return _serializer;
}
示例6: getDeserializer
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
/**
* Get the {@link FormDataPropertyValueDeserializer} instance to use.
* @return The {@link FormDataPropertyValueDeserializer} instance to use, from {@link ContextResolver} if available
* or the default one
*/
private FormDataPropertyValueDeserializer getDeserializer() {
if (_deserializer == null) {
// init using a contextresolver, if available
ContextResolver<FormDataPropertyValueDeserializer> contextResolver = providers.getContextResolver(
FormDataPropertyValueDeserializer.class, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
if (contextResolver != null) {
_deserializer = contextResolver.getContext(FormDataPropertyValueDeserializer.class);
}
if (_deserializer == null) {
// use default
_deserializer = FormDataPropertyValueDeserializer.getDefault();
}
}
return _deserializer;
}
示例7: lookupResource
import javax.ws.rs.ext.ContextResolver; //导入依赖的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);
}
示例8: sortedList
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
protected List<ContextResolver<?>> sortedList(Map<ProviderKey, ContextResolver<?>> providerMap, MediaType targetMediaType) {
List<ContextResolver<?>> contextResolvers = new ArrayList<>(providerMap.values());
Collections.sort(contextResolvers, new Comparator<ContextResolver<?>>() {
public int compare(ContextResolver<?> cr1, ContextResolver<?> cr2) {
Set<String> providerMediaTypes1 = mediaTypes(cr1.getClass().getAnnotationsByType(Produces.class));
Set<String> providerMediaTypes2 = mediaTypes(cr2.getClass().getAnnotationsByType(Produces.class));
int score1 = relevanceScore(providerMediaTypes1, targetMediaType);
int score2 = relevanceScore(providerMediaTypes2, targetMediaType);
if (score1 == score2)
return 0;
return (score2 - score1) < 0 ? -1 : 1;
}
});
return contextResolvers;
}
示例9: createLink
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
@POST
public Response createLink(@Context HttpHeaders httpHeaders,
@Context UriInfo uriInfo,
@Context ContextResolver<ODataProducer> producerResolver,
@Context SecurityContext securityContext,
String payload) {
log.info(String.format(
"createLink(%s,%s,%s,%s)",
sourceEntity.getEntitySetName(),
sourceEntity.getEntityKey(),
targetNavProp,
targetEntityKey));
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
OEntityId newTargetEntity = parseRequestUri(httpHeaders, uriInfo, payload);
producer.createLink(ODataContextImpl.builder().aspect(httpHeaders).aspect(securityContext).build(), sourceEntity, targetNavProp, newTargetEntity);
return noContent();
}
示例10: updateLink
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
@PUT
public Response updateLink(@Context HttpHeaders httpHeaders,
@Context UriInfo uriInfo,
@Context ContextResolver<ODataProducer> producerResolver,
@Context SecurityContext securityContext,
String payload) {
log.info(String.format(
"updateLink(%s,%s,%s,%s)",
sourceEntity.getEntitySetName(),
sourceEntity.getEntityKey(),
targetNavProp,
targetEntityKey));
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
OEntityId newTargetEntity = parseRequestUri(httpHeaders, uriInfo, payload);
producer.updateLink(ODataContextImpl.builder().aspect(httpHeaders).aspect(securityContext).build(), sourceEntity, targetNavProp, targetEntityKey, newTargetEntity);
return noContent();
}
示例11: deleteLink
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
@DELETE
public Response deleteLink(@Context HttpHeaders httpHeaders,
@Context UriInfo uriInfo,
@Context ContextResolver<ODataProducer> producerResolver,
@Context SecurityContext securityContext) {
log.info(String.format(
"deleteLink(%s,%s,%s,%s)",
sourceEntity.getEntitySetName(),
sourceEntity.getEntityKey(),
targetNavProp,
targetEntityKey));
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
producer.deleteLink(ODataContextImpl.builder().aspect(httpHeaders).aspect(securityContext).build(), sourceEntity, targetNavProp, targetEntityKey);
return noContent();
}
示例12: getServiceDocument
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
@GET
@Produces({ ODataConstants.APPLICATION_XML_CHARSET_UTF8, ODataConstants.TEXT_JAVASCRIPT_CHARSET_UTF8, ODataConstants.APPLICATION_JAVASCRIPT_CHARSET_UTF8 })
public Response getServiceDocument(
@Context HttpHeaders httpHeaders,
@Context UriInfo uriInfo,
@Context ContextResolver<ODataProducer> producerResolver,
@QueryParam("$format") String format,
@QueryParam("$callback") String callback) {
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
EdmDataServices metadata = producer.getMetadata();
StringWriter w = new StringWriter();
FormatWriter<EdmDataServices> fw = FormatWriterFactory.getFormatWriter(EdmDataServices.class, httpHeaders.getAcceptableMediaTypes(), format, callback);
fw.write(uriInfo, w, metadata);
return Response.ok(w.toString(), fw.getContentType())
.header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
.build();
}
示例13: delegate
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
@Override
protected Response delegate(HttpHeaders httpHeaders, URI baseUri, ContextResolver<ODataProducer> producerResolver) throws Exception {
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
OEntity entity = new BatchRequestResource().getRequestEntity(httpHeaders, getResourceHeaders(),
getUriInfo(),
getResourceContent(),
producer.getMetadata(),
getEnitySetName(),
OEntityKey.parse(getEntityKey()), false);
producer.updateEntity(null, getEnitySetName(), entity);
Response response = Response.ok().header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
.header(ODataConstants.Headers.CONTENT_TYPE, getResourceHeaders().getFirst(ODataConstants.Headers.CONTENT_TYPE))
.header(ODataConstants.Headers.CONTENT_LENGTH, 0).build();
return response;
}
示例14: delegate
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
@Override
protected Response delegate(HttpHeaders httpHeaders, URI baseUri, ContextResolver<ODataProducer> producerResolver) throws Exception {
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
OEntity entity = new BatchRequestResource().getRequestEntity(httpHeaders, getResourceHeaders(),
getUriInfo(),
getResourceContent(),
producer.getMetadata(),
getEnitySetName(),
OEntityKey.parse(getEntityKey()), false);
producer.mergeEntity(null, getEnitySetName(), entity);
Response response = Response.ok().header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
.header(ODataConstants.Headers.CONTENT_TYPE, getResourceHeaders().getFirst(ODataConstants.Headers.CONTENT_TYPE))
.header(ODataConstants.Headers.CONTENT_LENGTH, 0).build();
return response;
}
示例15: getEntity
import javax.ws.rs.ext.ContextResolver; //导入依赖的package包/类
@GET
@Produces({ ODataConstants.APPLICATION_ATOM_XML_CHARSET_UTF8, ODataConstants.TEXT_JAVASCRIPT_CHARSET_UTF8, ODataConstants.APPLICATION_JAVASCRIPT_CHARSET_UTF8 })
public Response getEntity(@Context HttpHeaders httpHeaders,
@Context UriInfo uriInfo,
@Context ContextResolver<ODataProducer> producerResolver,
@Context SecurityContext securityContext,
@PathParam("entitySetName") String entitySetName,
@PathParam("id") String id,
@QueryParam("$format") String format,
@QueryParam("$callback") String callback,
@QueryParam("$expand") String expand,
@QueryParam("$select") String select) {
ODataProducer producer = producerResolver.getContext(ODataProducer.class);
return getEntityImpl(httpHeaders, uriInfo, securityContext, producer, entitySetName, id, format, callback, expand, select);
}