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


Java MessageBodyReader.readFrom方法代码示例

本文整理汇总了Java中javax.ws.rs.ext.MessageBodyReader.readFrom方法的典型用法代码示例。如果您正苦于以下问题:Java MessageBodyReader.readFrom方法的具体用法?Java MessageBodyReader.readFrom怎么用?Java MessageBodyReader.readFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.ext.MessageBodyReader的用法示例。


在下文中一共展示了MessageBodyReader.readFrom方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getImpl

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private T getImpl(final MinijaxRequestContext context, final InputStream entityStream) throws IOException {
    if (entityClass == String.class) {
        return (T) IOUtils.toString(entityStream, StandardCharsets.UTF_8);
    }

    if (entityClass == MultivaluedMap.class) {
        return (T) context.getForm().asForm().asMap();
    }

    final MediaType mediaType = consumesTypes != null && !consumesTypes.isEmpty() ? consumesTypes.get(0) : null;
    final MessageBodyReader<T> reader = context.getApplication().getProviders().getMessageBodyReader(entityClass, genericType, annotations, mediaType);
    if (reader != null) {
        final MultivaluedMap<String, String> httpHeaders = context.getHeaders();
        return reader.readFrom(entityClass, genericType, annotations, mediaType, httpHeaders, entityStream);
    }

    throw new InjectException("Unknown entity type (" + entityClass + ")");
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:EntityProvider.java

示例2: readFrom

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@Override
public JsonWebKeySet readFrom(final Class<JsonWebKeySet> type,
        final Type genericType,
        final Annotation[] annotations,
        final MediaType mediaType,
        final MultivaluedMap<String, String> httpHeaders,
        final InputStream inputStream) throws IOException,
        WebApplicationException {

    final JsonArray keysArray = Json.createReader(inputStream)
            .readObject()
            .getJsonArray("keys");

    final JsonWebKeySet keySet = new JsonWebKeySet();
    final MessageBodyReader<JsonWebKey> reader = providers.getMessageBodyReader(JsonWebKey.class, JsonWebKey.class, annotations, mediaType);
    for (final JsonValue key : keysArray) {
        final InputStream keyStream = new ByteArrayInputStream(key.toString()
                .getBytes(CharSets.UTF8));
        final JsonWebKey jsonWebKey = reader.readFrom(JsonWebKey.class, null, annotations, mediaType, null, keyStream);
        keySet.add(jsonWebKey);
    }

    return keySet;
}
 
开发者ID:trajano,项目名称:openid-connect,代码行数:25,代码来源:JsonWebKeySetProvider.java

示例3: testReadMap

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testReadMap() throws IOException {
    final String json = "{\"key\":\"value\"}";
    final ByteArrayInputStream inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
    final MessageBodyReader<Map> mapReader = (MessageBodyReader<Map>) reader;
    final Map<String, String> map = mapReader.readFrom(Map.class, null, null, null, null, inputStream);
    assertEquals("value", map.get("key"));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:ReaderTest.java

示例4: testReadWidget

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testReadWidget() throws IOException {
    final String json = "{\"id\":\"123\",\"value\":\"hello\"}";
    final ByteArrayInputStream inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
    final MessageBodyReader<Widget> widgetReader = (MessageBodyReader<Widget>) reader;
    final Widget widget = widgetReader.readFrom(Widget.class, null, null, null, null, inputStream);
    assertEquals("123", widget.id);
    assertEquals("hello", widget.value);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:11,代码来源:ReaderTest.java

示例5: testReaderException

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@Test(expected = BadRequestException.class)
@SuppressWarnings("unchecked")
public void testReaderException() throws IOException {
    final String json = "";
    final ByteArrayInputStream inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
    final MessageBodyReader<Object> objReader = (MessageBodyReader<Object>) reader;
    objReader.readFrom(Object.class, null, null, null, null, inputStream);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:9,代码来源:ReaderTest.java

示例6: unmarshalJsonStringObject

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
protected SelectServer unmarshalJsonStringObject(String jsonStringObject) throws java.io.IOException {
    MessageBodyReader<SelectServer> messageBodyReader = getJsonMessageBodyReader();
    ByteArrayInputStream bais = new ByteArrayInputStream(jsonStringObject.getBytes());
    SelectServer responseObject = messageBodyReader.readFrom(SelectServer.class, SelectServer.class, SelectServer.class.getAnnotations(), null, null, bais);
    bais.close();
    return responseObject;
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:8,代码来源:SelectServerTemplate.java

示例7: readFrom

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    final Type actualTypeArgument = actual(genericType);
    final Class entityType = entityType(actualTypeArgument);
    final MessageBodyReader reader = workers.get().getMessageBodyReader(entityType, actualTypeArgument, annotations, mediaType);

    return reader.readFrom(entityType, actualTypeArgument, annotations, mediaType, httpHeaders, entityStream);
}
 
开发者ID:alex-shpak,项目名称:rx-jersey,代码行数:10,代码来源:RxGenericBodyReader.java

示例8: readFrom

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@Override
public MultipartUploadRepresentation readFrom(Class<MultipartUploadRepresentation> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
	String boundary = mediaType.getParameters().get("boundary");
	if (boundary == null) {
		throw new IOException("Unable to get boundary");
	}
	
	MultipartInputImpl input = new MultipartInputImpl(mediaType, providers);
	input.parse(entityStream);
	Collection<InputPart> parts = input.getParts();
	
	Map<String, BucketObjectUpdateRepresentation> uploads = new HashMap<String, BucketObjectUpdateRepresentation>(parts.size());
	@SuppressWarnings("resource")
	MultipartUploadRepresentation result = new MultipartUploadRepresentation("true".equalsIgnoreCase(httpHeaders.getFirst(BlazeStorageHeaders.QUIET)), uploads, input);
	
	Class<BucketObjectUpdateRepresentation> readerType = BucketObjectUpdateRepresentation.class;
	Type readerGenericType = readerType;
	Annotation[] readerAnnotations = new Annotation[0];
	
	MessageBodyReader<BucketObjectUpdateRepresentation> reader = providers.getMessageBodyReader(readerType, readerGenericType, readerAnnotations, MediaType.WILDCARD_TYPE);
	
	for (InputPart p : parts) {
		MultivaluedMap<String, String> partHttpHeaders = p.getHeaders();
		String partKey = partHttpHeaders.getFirst(BlazeStorageHeaders.MULTIPART_KEY);
		
		if (partKey == null) {
			throw new WebApplicationException(Response.status(Status.BAD_REQUEST).build());
		}
		
		BucketObjectUpdateRepresentation bucketObjectUpdateRepresentation = reader.readFrom(readerType, readerGenericType, readerAnnotations, p.getMediaType(), partHttpHeaders, p.getInputStream());
		uploads.put(partKey, bucketObjectUpdateRepresentation);
	}

	return result;
}
 
开发者ID:Blazebit,项目名称:blaze-storage,代码行数:36,代码来源:MultipartUploadRepresentationMessageBodyReader.java

示例9: getEntity

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
public static <T> T getEntity(ClientMessage msg, Class<T> type, Type genericType, ResteasyProviderFactory factory) {
   int size = msg.getBodySize();
   if (size <= 0)
      return null;

   byte[] body = new byte[size];
   msg.getBodyBuffer().readBytes(body);

   String contentType = msg.getStringProperty(HttpHeaderProperty.CONTENT_TYPE);
   if (contentType == null) {
      throw new UnknownMediaType("Message did not have a Content-Type header cannot extract entity");
   }
   MediaType ct = MediaType.valueOf(contentType);
   MessageBodyReader<T> reader = factory.getMessageBodyReader(type, genericType, null, ct);
   if (reader == null) {
      throw new UnmarshalException("Unable to find a JAX-RS reader for type " + type.getName() + " and media type " + contentType);
   }

   Providers current = ResteasyProviderFactory.getContextData(Providers.class);
   ResteasyProviderFactory.pushContext(Providers.class, factory);
   try {
      return reader.readFrom(type, genericType, null, ct, new Headers<String>(), new ByteArrayInputStream(body));
   } catch (IOException e) {
      throw new RuntimeException(e);
   } finally {
      ResteasyProviderFactory.popContextData(Providers.class);
      if (current != null)
         ResteasyProviderFactory.pushContext(Providers.class, current);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:31,代码来源:ActiveMQ.java

示例10: testGoogleJwks

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@Test
public void testGoogleJwks() throws Exception {

    final MessageBodyReader<JsonWebKeySet> reader = providers.getMessageBodyReader(JsonWebKeySet.class, null, null, MediaType.APPLICATION_JSON_TYPE);
    final JsonWebKeySet jwks = reader.readFrom(JsonWebKeySet.class, JsonWebKeySet.class, null, MediaType.APPLICATION_JSON_TYPE, null, getClass().getResourceAsStream("/googlejwks.json"));

    final JsonWebKey[] keys = jwks.getKeys();
    assertEquals(2, keys.length);
    assertEquals(JsonWebAlgorithm.RS256, keys[0].getAlg());
    assertEquals(JsonWebAlgorithm.RS256, keys[1].getAlg());

    final RSAPublicKey jcaKey = (RSAPublicKey) keys[1].toJcaKey();
    assertNotEquals(jcaKey.getModulus(), BigInteger.ZERO);
    assertNotEquals(jcaKey.getPublicExponent(), BigInteger.ZERO);
}
 
开发者ID:trajano,项目名称:openid-connect,代码行数:16,代码来源:JwksTest.java

示例11: testGoogleJwksRewrite

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
@Test
public void testGoogleJwksRewrite() throws Exception {

    final MessageBodyReader<JsonWebKeySet> reader = providers.getMessageBodyReader(JsonWebKeySet.class, null, null, MediaType.APPLICATION_JSON_TYPE);
    assertNotNull("unable to get reader", reader);

    final JsonWebKeySet jwks = reader.readFrom(JsonWebKeySet.class, JsonWebKeySet.class, null, MediaType.APPLICATION_JSON_TYPE, null, getClass().getResourceAsStream("/googlejwks.json"));

    final JsonWebKey[] keys = jwks.getKeys();
    assertEquals(2, keys.length);
    assertEquals(JsonWebAlgorithm.RS256, keys[0].getAlg());
    assertEquals(JsonWebAlgorithm.RS256, keys[1].getAlg());

    final RSAPublicKey jcaKey = (RSAPublicKey) keys[1].toJcaKey();
    assertNotEquals(jcaKey.getModulus(), BigInteger.ZERO);
    assertNotEquals(jcaKey.getPublicExponent(), BigInteger.ZERO);

    final MessageBodyWriter<JsonWebKeySet> writer = providers.getMessageBodyWriter(JsonWebKeySet.class, null, null, MediaType.APPLICATION_JSON_TYPE);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    writer.writeTo(jwks, JsonWebKeySet.class, null, null, MediaType.APPLICATION_JSON_TYPE, null, baos);
    baos.close();

    final JsonArray googleKeys = Json.createReader(getClass().getResourceAsStream("/googlejwks.json"))
            .readObject()
            .getJsonArray("keys");

    final JsonArray builtKeys = Json.createReader(new ByteArrayInputStream(baos.toByteArray()))
            .readObject()
            .getJsonArray("keys");

    if (googleKeys.getJsonObject(0)
            .getString("kid")
            .equals(builtKeys.getJsonObject(0)
                    .getString("kid"))) {
        assertEquals(googleKeys.getJsonObject(0), builtKeys.getJsonObject(0));
        assertEquals(googleKeys.getJsonObject(1), builtKeys.getJsonObject(1));
    } else {
        assertEquals(googleKeys.getJsonObject(0), builtKeys.getJsonObject(1));
        assertEquals(googleKeys.getJsonObject(1), builtKeys.getJsonObject(0));
    }

}
 
开发者ID:trajano,项目名称:openid-connect,代码行数:43,代码来源:JwksTest.java

示例12: getContent

import javax.ws.rs.ext.MessageBodyReader; //导入方法依赖的package包/类
/**
 * @param inputStream
 * @param providers
 * @param httpHeaders
 * @param type
 * @param genericType
 * @param annotations
 * @return
 */
public static <T> T getContent(InputStream inputStream, Providers providers, HttpHeaders httpHeaders, Class<T> type, Type genericType, Annotation[] annotations) {
	MessageBodyReader<T> reader = providers.getMessageBodyReader(type, genericType, annotations, httpHeaders.getMediaType());
	try {
		return reader.readFrom(type, genericType, annotations, httpHeaders.getMediaType(), httpHeaders.getRequestHeaders(), inputStream);
	} catch (Exception e) {e.printStackTrace();
		throw new MinnalInstrumentationException("Failed while getting the content from the request stream", e);
	}
}
 
开发者ID:minnal,项目名称:minnal,代码行数:18,代码来源:ResourceUtil.java


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