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