public EmptyBodyCheckingHttpInputMessage(HttpInputMessage inputMessage) throws IOException { this.headers = inputMessage.getHeaders(); InputStream inputStream = inputMessage.getBody(); if (inputStream.markSupported()) { inputStream.mark(1); this.body = (inputStream.read() != -1 ? inputStream : null); inputStream.reset(); } else { PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream); int b = pushbackInputStream.read(); if (b == -1) { this.body = null; } else { this.body = pushbackInputStream; pushbackInputStream.unread(b); } } }
@Override @Nullable public String getFilename() { return inputMessage.getHeaders().getContentDisposition().getFilename(); } };
private static Reader getReader(HttpInputMessage inputMessage) throws IOException { return new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders())); }
@Override public String getFilename() { return inputMessage.getHeaders().getContentDisposition().getFilename(); } };
@Override public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException { long contentLength = inputMessage.getHeaders().getContentLength(); ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE); StreamUtils.copy(inputMessage.getBody(), bos); return bos.toByteArray(); }
@Override public final T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { try { return readFromSource(clazz, inputMessage.getHeaders(), new StreamSource(inputMessage.getBody())); } catch (IOException | HttpMessageConversionException ex) { throw ex; } catch (Exception ex) { throw new HttpMessageNotReadableException("Could not unmarshal to [" + clazz + "]: " + ex.getMessage(), ex, inputMessage); } }
@Override public MultiValueMap<String, String> read(@Nullable Class<? extends MultiValueMap<String, ?>> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { MediaType contentType = inputMessage.getHeaders().getContentType(); Charset charset = (contentType != null && contentType.getCharset() != null ? contentType.getCharset() : this.charset); String body = StreamUtils.copyToString(inputMessage.getBody(), charset); String[] pairs = StringUtils.tokenizeToStringArray(body, "&"); MultiValueMap<String, String> result = new LinkedMultiValueMap<>(pairs.length); for (String pair : pairs) { int idx = pair.indexOf('='); if (idx == -1) { result.add(URLDecoder.decode(pair, charset.name()), null); } else { String name = URLDecoder.decode(pair.substring(0, idx), charset.name()); String value = URLDecoder.decode(pair.substring(idx + 1), charset.name()); result.add(name, value); } } return result; }
@Override public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws IOException { JsonView ann = methodParameter.getParameterAnnotation(JsonView.class); Assert.state(ann != null, "No JsonView annotation"); Class<?>[] classes = ann.value(); if (classes.length != 1) { throw new IllegalArgumentException( "@JsonView only supported for request body advice with exactly 1 class argument: " + methodParameter); } return new MappingJacksonInputMessage(inputMessage.getBody(), inputMessage.getHeaders(), classes[0]); }
@Override @Nullable public String getFilename() { return inputMessage.getHeaders().getContentDisposition().getFilename(); } };
private static Reader getReader(HttpInputMessage inputMessage) throws IOException { return new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders())); }
@Override public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException { long contentLength = inputMessage.getHeaders().getContentLength(); ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE); StreamUtils.copy(inputMessage.getBody(), bos); return bos.toByteArray(); }
@Override public String getFilename() { return inputMessage.getHeaders().getContentDisposition().getFilename(); } };
@Override public final T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { try { return readFromSource(clazz, inputMessage.getHeaders(), new StreamSource(inputMessage.getBody())); } catch (IOException | HttpMessageConversionException ex) { throw ex; } catch (Exception ex) { throw new HttpMessageNotReadableException("Could not unmarshal to [" + clazz + "]: " + ex.getMessage(), ex, inputMessage); } }
@Override protected String readInternal(Class<? extends String> clazz, HttpInputMessage inputMessage) throws IOException { Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); return StreamUtils.copyToString(inputMessage.getBody(), charset); }
@Override public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws IOException { JsonView ann = methodParameter.getParameterAnnotation(JsonView.class); Assert.state(ann != null, "No JsonView annotation"); Class<?>[] classes = ann.value(); if (classes.length != 1) { throw new IllegalArgumentException( "@JsonView only supported for request body advice with exactly 1 class argument: " + methodParameter); } return new MappingJacksonInputMessage(inputMessage.getBody(), inputMessage.getHeaders(), classes[0]); }
@Override @SuppressWarnings("unchecked") protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { WireFeedInput feedInput = new WireFeedInput(); MediaType contentType = inputMessage.getHeaders().getContentType(); Charset charset = (contentType != null && contentType.getCharset() != null ? contentType.getCharset() : DEFAULT_CHARSET); try { Reader reader = new InputStreamReader(inputMessage.getBody(), charset); return (T) feedInput.build(reader); } catch (FeedException ex) { throw new HttpMessageNotReadableException("Could not read WireFeed: " + ex.getMessage(), ex, inputMessage); } }
@Override protected String readInternal(Class<? extends String> clazz, HttpInputMessage inputMessage) throws IOException { Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); return StreamUtils.copyToString(inputMessage.getBody(), charset); }
try { imageInputStream = createImageInputStream(inputMessage.getBody()); MediaType contentType = inputMessage.getHeaders().getContentType(); if (contentType == null) { throw new HttpMessageNotReadableException("No Content-Type header", inputMessage);
@Override @SuppressWarnings("unchecked") protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { WireFeedInput feedInput = new WireFeedInput(); MediaType contentType = inputMessage.getHeaders().getContentType(); Charset charset = (contentType != null && contentType.getCharset() != null ? contentType.getCharset() : DEFAULT_CHARSET); try { Reader reader = new InputStreamReader(inputMessage.getBody(), charset); return (T) feedInput.build(reader); } catch (FeedException ex) { throw new HttpMessageNotReadableException("Could not read WireFeed: " + ex.getMessage(), ex, inputMessage); } }
@Override protected Message readInternal(Class<? extends Message> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { MediaType contentType = inputMessage.getHeaders().getContentType(); if (contentType == null) { contentType = PROTOBUF; } Charset charset = contentType.getCharset(); if (charset == null) { charset = DEFAULT_CHARSET; } Message.Builder builder = getMessageBuilder(clazz); if (PROTOBUF.isCompatibleWith(contentType)) { builder.mergeFrom(inputMessage.getBody(), this.extensionRegistry); } else if (TEXT_PLAIN.isCompatibleWith(contentType)) { InputStreamReader reader = new InputStreamReader(inputMessage.getBody(), charset); TextFormat.merge(reader, this.extensionRegistry, builder); } else if (this.protobufFormatSupport != null) { this.protobufFormatSupport.merge( inputMessage.getBody(), charset, contentType, this.extensionRegistry, builder); } return builder.build(); }