当前位置: 首页>>代码示例>>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;未经允许,请勿转载。