Refine search
@SuppressWarnings("unchecked") private <T> T readAndCast(GenericType<T> type, MediaType effectiveMediaType, MessageBodyReader reader) { try { return (T) reader.readFrom( type.getRawType(), type.getType(), annotations, effectiveMediaType, headers, new ByteArrayInputStream(data)); } catch (IOException ex) { throw new ProcessingException(ex); } }
final MediaType mediaType) { try { return provider.isReadable(type, genericType, annotations, mediaType); } catch (final Exception ex) { if (LOGGER.isLoggable(Level.FINE)) {
@SuppressWarnings("unchecked") public Object readContent(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { @SuppressWarnings("rawtypes") MessageBodyReader reader = providers.getMessageBodyReader(type, genericType, annotations, mediaType); if (reader == null) throw new RuntimeException(Messages.MESSAGES.unableToFindReaderForContentType()); try { ByteArrayInputStream bais = new ByteArrayInputStream(content); return reader.readFrom(type, genericType, annotations, mediaType, new MultivaluedHashMap<String, String>(), bais); } catch (Exception e) { throw new RuntimeException(e); } }
MessageBodyReader<T> reader = workers.getMessageBodyReader(type, genericType, empty, contentType); if (reader == null) return reader.readFrom(type, genericType, empty, contentType, headers, getBody());
/** * Returns the entity after appropriate conversion to the requested type. This is useful only when the containing * {@link MultiPart} instance has been received, which causes the {@code providers} property to have been set. * * @param clazz desired class into which the entity should be converted. * @return entity after appropriate conversion to the requested type. * * @throws ProcessingException if an IO error arises during reading an entity. * @throws IllegalArgumentException if no {@link MessageBodyReader} can be found to perform the requested conversion. * @throws IllegalStateException if this method is called when the {@code providers} property has not been set or when the * entity instance is not the unconverted content of the body part entity. */ public <T> T getEntityAs(final Class<T> clazz) { if (entity == null || !(entity instanceof BodyPartEntity)) { throw new IllegalStateException(LocalizationMessages.ENTITY_HAS_WRONG_TYPE()); } if (clazz == BodyPartEntity.class) { return clazz.cast(entity); } final Annotation[] annotations = new Annotation[0]; final MessageBodyReader<T> reader = messageBodyWorkers.getMessageBodyReader(clazz, clazz, annotations, mediaType); if (reader == null) { throw new IllegalArgumentException(LocalizationMessages.NO_AVAILABLE_MBR(clazz, mediaType)); } try { return reader.readFrom(clazz, clazz, annotations, mediaType, headers, ((BodyPartEntity) entity).getInputStream()); } catch (final IOException ioe) { throw new ProcessingException(LocalizationMessages.ERROR_READING_ENTITY(String.class), ioe); } }
@SuppressWarnings("unchecked") protected <T> T deserialize(HttpRequest request, Class<T> type, Type genericType, MediaType mediaType) throws IOException { try { MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>(); return bodyReaders.stream() .filter(reader -> reader.isReadable(type, genericType, null, mediaType)) .map(reader -> { try { return (T) MessageBodyReader.class.cast(reader) .readFrom(type, genericType, null, mediaType, headers, request.getBody()); } catch (IOException e) { throw new UncheckedIOException(e); } }) .filter(Objects::nonNull) .findAny() .orElse(null); } catch (UncheckedIOException e) { throw e.getCause(); } }
public <T> T readContent(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) { Providers tmp = providers; if (tmp == null) tmp = ResteasyProviderFactory.getInstance(); MessageBodyReader<T> reader = tmp.getMessageBodyReader(type, genericType, annotations, mediaType); if (reader == null) throw new RuntimeException(Messages.MESSAGES.unableToFindReaderForContentType()); try { ByteArrayInputStream bais = new ByteArrayInputStream(rawContent); return reader.readFrom(type, genericType, annotations, mediaType, new MultivaluedHashMap<String, String>(), bais); } catch (Exception e) { throw new RuntimeException(e); } } }
if (mimeHeaders.containsKey("Content-Type")) contentType = mimeHeaders.getFirst("Content-Type"); MediaType mediaType = MediaType.valueOf(contentType); MessageBodyReader reader = providers.getMessageBodyReader(t, gt, ann, mediaType); if (reader == null) return reader.readFrom(t, gt, ann, mediaType, mimeHeaders, inputStream);
return bw.readFrom(type, genericType, as, mediaType, headers, entity); } catch (WebApplicationException ex) { throw ex;
@SuppressWarnings("unchecked") protected <T> T deserialize(HttpRequest request, Class<T> type, Type genericType, MediaType mediaType) throws IOException { try { MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>(); return bodyReaders.stream() .filter(reader -> reader.isReadable(type, genericType, null, mediaType)) .map(reader -> { try { return (T) MessageBodyReader.class.cast(reader) .readFrom(type, genericType, null, mediaType, headers, request.getBody()); } catch (IOException e) { throw new UncheckedIOException(e); } }) .filter(Objects::nonNull) .findAny() .orElse(null); } catch (UncheckedIOException e) { throw e.getCause(); } }
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); return (MultivaluedMap<String, String>) reader.readFrom(MultivaluedMap.class, MultivaluedMap.class, EMPTY_ANNOTATIONS, MediaType.APPLICATION_FORM_URLENCODED_TYPE, null, in); } catch (IOException ioe) {
@SuppressWarnings({"rawtypes", "unchecked"}) public <T2> T2 getEntity(Class<T2> t, Type gt, Annotation[] ann, MediaType mediaType) { if (entity != null) return (T2)entity; byte[] bytes = (byte[])data.getSignedContent().getContent(); MessageBodyReader reader = providers.getMessageBodyReader(t, gt, ann, mediaType); ByteArrayInputStream is = new ByteArrayInputStream(bytes); try { entity = reader.readFrom(t, gt, ann, mediaType, new MultivaluedMapImpl<String, String>(), is); } catch (Exception e) { throw new RuntimeException(e); } return (T2)entity; }
@Override @SuppressWarnings("unchecked") public Stream<T> readFrom(Class<Stream<T>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { // If we don't use an intermediate list, the underlying stream gets closed before we // get the chance to read the stream. Maybe this can be fixed/improved. return providers.getMessageBodyReader(List.class, GENERIC_TYPE, annotations, mediaType) .readFrom(List.class, GENERIC_TYPE, annotations, mediaType, httpHeaders, entityStream).stream(); } }
@SuppressWarnings(value = "unchecked") protected Object readFrom(MessageBodyReader reader) throws IOException { return reader.readFrom(type, genericType, annotations, mediaType, headers, inputStream); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Object aroundReadFrom(ReaderInterceptorContext c) throws IOException, WebApplicationException { Class entityCls = (Class)c.getType(); Type entityType = c.getGenericType(); MediaType entityMt = c.getMediaType(); Annotation[] entityAnns = c.getAnnotations(); if (m.get(ProviderFactory.PROVIDER_SELECTION_PROPERTY_CHANGED) == Boolean.TRUE && !reader.isReadable(entityCls, entityType, entityAnns, entityMt)) { reader = ProviderFactory.getInstance(m) .createMessageBodyReader(entityCls, entityType, entityAnns, entityMt, m); if (reader == null) { throw new RuntimeException("No reader available"); } } return reader.readFrom(entityCls, entityType, entityAnns, entityMt, new HttpHeadersImpl(m).getRequestHeaders(), c.getInputStream()); }
final MediaType mediaType) { try { return provider.isReadable(type, genericType, annotations, mediaType); } catch (final Exception ex) { if (LOGGER.isLoggable(Level.FINE)) {
if (parameter.getDefaultValue() != null) { stream = new ByteArrayInputStream(parameter.getDefaultValue() .getBytes(MessageUtils.getCharset(mediaType))); } else { return reader.readFrom( parameter.getRawType(), parameter.getType(), p.getMediaType()); @SuppressWarnings("unchecked") final String value = (String) reader.readFrom( String.class, String.class,
public static <T> T readFromString(Providers providers, String input, Class<T> type, Type genericType, MultivaluedMap<String, String> httpHeaders, MediaType mediaType) throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(input.getBytes(getCharset(mediaType))); MessageBodyReader<T> reader = providers.getMessageBodyReader(type, genericType, null, mediaType); if (reader == null) { return null; } return reader.readFrom(type, genericType, new Annotation[0], mediaType, httpHeaders, is); }
@Override public <T> T getBody(Class<T> type, Type genericType) throws IOException { final MediaType mediaType = getMediaType(); final MessageBodyReader<T> reader = providers.getMessageBodyReader(type, genericType, EMPTY, mediaType); if (reader == null) { throw new RuntimeException( String.format("Unable to find a MessageBodyReader for media type '%s' and class '%s'", mediaType, type.getName())); } return reader.readFrom(type, genericType, EMPTY, mediaType, headers, getBody()); }
@SuppressWarnings("unchecked") private Object invokeReadFrom(final ReaderInterceptorContext context, final MessageBodyReader reader, final EntityInputStream input) throws WebApplicationException, IOException { final TracingLogger tracingLogger = getTracingLogger(); final long timestamp = tracingLogger.timestamp(MsgTraceEvent.MBR_READ_FROM); final InputStream stream = new UnCloseableInputStream(input, reader); try { return reader.readFrom(context.getType(), context.getGenericType(), context.getAnnotations(), context.getMediaType(), context.getHeaders(), stream); } catch (final NoContentException ex) { if (translateNce) { throw new BadRequestException(ex); } else { throw ex; } } finally { tracingLogger.logDuration(MsgTraceEvent.MBR_READ_FROM, timestamp, reader); } } }