當前位置: 首頁>>代碼示例>>Java>>正文


Java ContextResolver.getContext方法代碼示例

本文整理匯總了Java中javax.ws.rs.ext.ContextResolver.getContext方法的典型用法代碼示例。如果您正苦於以下問題:Java ContextResolver.getContext方法的具體用法?Java ContextResolver.getContext怎麽用?Java ContextResolver.getContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.ext.ContextResolver的用法示例。


在下文中一共展示了ContextResolver.getContext方法的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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: readFrom

import javax.ws.rs.ext.ContextResolver; //導入方法依賴的package包/類
public T readFrom(final Class<T> clazz, final Type type, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> parameters, final InputStream stream) throws IOException, WebApplicationException {
	LogUtils.debugf(this, "readFrom: %s/%s/%s", clazz.getSimpleName(), type, mediaType);

	JAXBContext jaxbContext = null;
	final ContextResolver<JAXBContext> resolver = providers.getContextResolver(JAXBContext.class, mediaType);
	try {

		if (resolver != null) {
			jaxbContext = resolver.getContext(clazz);
		}

		if (jaxbContext == null) {
			jaxbContext = JAXBContext.newInstance(clazz);

		}
		
		return JaxbUtils.unmarshal(clazz, new InputSource(stream), jaxbContext);

	} catch (final JAXBException e) {
		LogUtils.warnf(this, e, "An error occurred while unmarshaling a %s object", clazz.getSimpleName());
		throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
	}
}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:24,代碼來源:ValidatingMessageBodyReader.java

示例12: testSkipUnknownFields

import javax.ws.rs.ext.ContextResolver; //導入方法依賴的package包/類
@Test
public void testSkipUnknownFields() throws IOException {
    final ContextResolver<ObjectMapper> contextResolver = new ObjectMapperProvider();
    final ObjectMapper objectMapper = contextResolver.getContext(ObjectMapper.class);
    final TestEntity testEntity = objectMapper.readValue(JSON, TestEntity.class);
    Assert.assertEquals(TEST_NAME, testEntity.getName());
}
 
開發者ID:mvpotter,項目名稱:kladr-api-client,代碼行數:8,代碼來源:ObjectMapperProviderTest.java

示例13: postConstruct

import javax.ws.rs.ext.ContextResolver; //導入方法依賴的package包/類
@PostConstruct
public void postConstruct() {
    final ContextResolver<GsonBuilder> contextResolver = providers.getContextResolver(GsonBuilder.class, MediaType.APPLICATION_JSON_TYPE);
    if (contextResolver != null) {
        final GsonBuilder builder = contextResolver.getContext(GsonBuilder.class);
        if (builder != null) {
            gson = builder.create();
        }
    }
}
 
開發者ID:martinjmares,項目名稱:javaone2015-cloudone,代碼行數:11,代碼來源:GsonProvider.java

示例14: createResponseForBatch

import javax.ws.rs.ext.ContextResolver; //導入方法依賴的package包/類
/**
 * Creates the response for batch.
 *
 * @param httpHeaders the http headers
 * @param producerResolver the producer resolver
 * @param baseUri the base uri
 * @param requestedEntity the requested entity
 * @return the response
 * @throws Exception the exception
 */
public Response createResponseForBatch(HttpHeaders httpHeaders, ContextResolver<ODataProducer> producerResolver, URI baseUri, String requestedEntity) throws Exception {
  ODataProducer producer = producerResolver.getContext(ODataProducer.class);
  OEntityKey entityKey = null;
  //setting isResponse to true, since the entity we get from the response contain not only name and value pairs, but also metadata, relations,etc
  //so that Json parser will parse it and give you back OEntity.
  Boolean isResponse = true;
  BatchRequestResource batchRequestResource = new BatchRequestResource();
  OEntity entity = batchRequestResource.getRequestEntity(httpHeaders, getResourceHeaders(), getUriInfo(), requestedEntity, producer.getMetadata(), entitySetName, entityKey, isResponse);

  return batchRequestResource.createResponseForBatch(httpHeaders, getUriInfo(), producer, getEnitySetName(), entity, getMediaTypeListForBatch());
}
 
開發者ID:teiid,項目名稱:oreva,代碼行數:22,代碼來源:ODataBatchSingleUnit.java

示例15: functionCallPut

import javax.ws.rs.ext.ContextResolver; //導入方法依賴的package包/類
@PUT
public Response functionCallPut(
    @Context HttpHeaders httpHeaders,
    @Context UriInfo uriInfo,
    @Context ContextResolver<ODataProducer> producerResolver,
    @Context SecurityContext securityContext,
    @QueryParam("$format") String format,
    @QueryParam("$callback") String callback,
    @PathParam("entitySetName") String functionName,
    InputStream payload) throws Exception {

  Response response;
  log("functionCallDelete", "function", functionName);

  ODataProducer producer = producerResolver.getContext(ODataProducer.class);

  // the OData URI scheme makes it impossible to have unique @Paths that refer
  // to functions and entity sets
  if (producer.getMetadata().containsEdmFunctionImport(functionName)) {
    // functions that return collections of entities should support the
    // same set of query options as entity set queries so give them everything.

    QueryInfo query = QueryInfo.newBuilder().setCustomOptions(OptionsQueryParser.parseCustomOptions(uriInfo)).build();
    response = FunctionResource.callFunction(ODataHttpMethod.PUT, httpHeaders, uriInfo, securityContext, producer, functionName, format, callback, query);
  } else {
    throw new NotFoundException(functionName);
  }

  return response;
}
 
開發者ID:teiid,項目名稱:oreva,代碼行數:31,代碼來源:EntitiesRequestResource.java


注:本文中的javax.ws.rs.ext.ContextResolver.getContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。