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


Java ContextResolver类代码示例

本文整理汇总了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;
}
 
开发者ID:holon-platform,项目名称:holon-json,代码行数:21,代码来源:JacksonJsonPropertyBoxProvider.java

示例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;
}
 
开发者ID:holon-platform,项目名称:holon-json,代码行数:20,代码来源:GsonJsonProvider.java

示例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>
	}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:24,代码来源:ExampleAuth.java

示例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;
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:21,代码来源:PropertyBoxFormDataProvider.java

示例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;
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:21,代码来源:PropertyBoxFormDataProvider.java

示例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;
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:21,代码来源:PropertyBoxFormDataProvider.java

示例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);
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:33,代码来源:ResourceUtils.java

示例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;
}
 
开发者ID:geetools,项目名称:geeMVC-Java-MVC-Framework,代码行数:22,代码来源:DefaultProviderFilter.java

示例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();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:20,代码来源:LinksRequestResource.java

示例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();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:20,代码来源:LinksRequestResource.java

示例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();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:18,代码来源:LinksRequestResource.java

示例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();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:22,代码来源:ServiceDocumentResource.java

示例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;
}
 
开发者ID:teiid,项目名称:oreva,代码行数:18,代码来源:ODataBatchPutUnit.java

示例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;
}
 
开发者ID:teiid,项目名称:oreva,代码行数:17,代码来源:ODataBatchMergeUnit.java

示例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);
}
 
开发者ID:teiid,项目名称:oreva,代码行数:17,代码来源:EntityRequestResource.java


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