當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。