本文整理汇总了Java中org.springframework.http.HttpInputMessage.getBody方法的典型用法代码示例。如果您正苦于以下问题:Java HttpInputMessage.getBody方法的具体用法?Java HttpInputMessage.getBody怎么用?Java HttpInputMessage.getBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.HttpInputMessage
的用法示例。
在下文中一共展示了HttpInputMessage.getBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@Override
protected ApplicationLogs readInternal(Class<? extends ApplicationLogs> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
String boundary = getMessageBoundary(inputMessage);
Multipart multipart = new Multipart(inputMessage.getBody(), boundary);
ApplicationLogs logs = new ApplicationLogs();
Multipart.Part part;
while ((part = multipart.nextPart()) != null) {
ApplicationLog log = messageParser.parseMessage(part.getContent());
logs.add(log);
}
return logs;
}
示例2: EmptyBodyCheckingHttpInputMessage
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
public EmptyBodyCheckingHttpInputMessage(HttpInputMessage inputMessage) throws IOException {
this.headers = inputMessage.getHeaders();
InputStream inputStream = inputMessage.getBody();
if (inputStream == null) {
this.body = null;
}
else 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);
}
}
this.method = ((HttpRequest) inputMessage).getMethod();
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AbstractMessageConverterMethodArgumentResolver.java
示例3: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@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;
if (contentType != null && contentType.getCharSet() != null) {
charset = contentType.getCharSet();
} else {
charset = 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);
}
}
示例4: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
InputStream body = inputMessage.getBody();
if (DOMSource.class.equals(clazz)) {
return (T) readDOMSource(body);
}
else if (SAXSource.class.equals(clazz)) {
return (T) readSAXSource(body);
}
else if (StAXSource.class.equals(clazz)) {
return (T) readStAXSource(body);
}
else if (StreamSource.class.equals(clazz) || Source.class.equals(clazz)) {
return (T) readStreamSource(body);
}
else {
throw new HttpMessageConversionException("Could not read class [" + clazz +
"]. Only DOMSource, SAXSource, StAXSource, and StreamSource are supported.");
}
}
示例5: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();
if (MEDIA_TYPE.isCompatibleWith(contentType)) {
final Schema<?> schema = getSchema(clazz);
final Object value = schema.newMessage();
try (final InputStream stream = inputMessage.getBody()) {
ProtobufIOUtil.mergeFrom(stream, value, (Schema<Object>) schema);
return value;
}
}
throw new HttpMessageNotReadableException(
"Unrecognized HTTP media type " + inputMessage.getHeaders().getContentType().getType() + ".");
}
示例6: read
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@Override
public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream in = inputMessage.getBody();
byte[] buf = new byte[1024];
for (; ; ) {
int len = in.read(buf);
if (len == -1) {
break;
}
if (len > 0) {
baos.write(buf, 0, len);
}
}
byte[] bytes = baos.toByteArray();
return readByBytes(type, bytes);
}
示例7: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException,
HttpMessageNotReadableException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream in = inputMessage.getBody();
byte[] buf = new byte[1024];
for (; ; ) {
int len = in.read(buf);
if (len == -1) {
break;
}
if (len > 0) {
baos.write(buf, 0, len);
}
}
byte[] bytes = baos.toByteArray();
return readByBytes(clazz, bytes);
}
示例8: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@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);
}
}
示例9: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
InputStream body = inputMessage.getBody();
if (DOMSource.class == clazz) {
return (T) readDOMSource(body);
}
else if (SAXSource.class == clazz) {
return (T) readSAXSource(body);
}
else if (StAXSource.class == clazz) {
return (T) readStAXSource(body);
}
else if (StreamSource.class == clazz || Source.class == clazz) {
return (T) readStreamSource(body);
}
else {
throw new HttpMessageConversionException("Could not read class [" + clazz +
"]. Only DOMSource, SAXSource, StAXSource, and StreamSource are supported.");
}
}
示例10: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@Override
protected MultipartFile[] readInternal (Class<? extends MultipartFile[]> clazz, HttpInputMessage inputMessage
) throws IOException {
val boundaryBytes = getMultiPartBoundary(inputMessage.getHeaders().getContentType());
MultipartStream multipartStream = new MultipartStream(inputMessage.getBody(), boundaryBytes, bufSize, null);
val multiparts = new LinkedList<ByteArrayMultipartFile>();
for (boolean nextPart = multipartStream.skipPreamble(); nextPart; nextPart = multipartStream.readBoundary()) {
ByteArrayMultipartFile multiPart;
try {
multiPart = readMultiPart(multipartStream);
} catch (Exception e) {
throw new HttpMessageNotReadableException("Multipart body could not be read.", e);
}
multiparts.add(multiPart);
}
return multiparts.toArray(new ByteArrayMultipartFile[multiparts.size()]);
}
示例11: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
@Override
protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream in = inputMessage.getBody();
byte[] buf = new byte[1024];
for (;;) {
int len = in.read(buf);
if (len == -1) {
break;
}
if (len > 0) {
baos.write(buf, 0, len);
}
}
byte[] bytes = baos.toByteArray();
return JSON.parseObject(bytes, 0, bytes.length, charset.newDecoder(), clazz);
}
示例12: readTypeToken
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
private Object readTypeToken(final TypeToken<?> token, final HttpInputMessage inputMessage) throws IOException {
final Reader reader = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders()));
try {
final String json = IOUtils.toString(reader);
reader.close();
// do the actual validation
final ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY);
mapper.readTree(json);
return this.gson.fromJson(json, token.getType());
} catch (JsonParseException ex) {
throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex);
}
}
示例13: readTypeToken
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
private Object readTypeToken(TypeToken<?> token, HttpInputMessage inputMessage) throws IOException {
InputStreamReader json = new InputStreamReader(inputMessage.getBody(), this.getCharset(inputMessage.getHeaders()));
try {
return this.gson.fromJson(json, token.getType());
} catch (JsonParseException var5) {
throw new HttpMessageNotReadableException("JSON parse error: " + var5.getMessage(), var5);
}
}
示例14: readObject
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
private Object readObject(HttpInputMessage inputMessage, TypeToken<?> token) throws IOException {
try (Reader json = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders()))) {
return this.gsonForReader.fromJson(json, token.getType());
} catch (JsonParseException ex) {
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex);
}
}
示例15: readInternal
import org.springframework.http.HttpInputMessage; //导入方法依赖的package包/类
protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream in = inputMessage.getBody();
byte[] buf = new byte[1024];
while (true) {
int len = in.read(buf);
if (len == -1) {
byte[] bytes = baos.toByteArray();
return JSON.parseObject(bytes, 0, bytes.length, this.charset.newDecoder(), (Type) clazz, new Feature[0]);
} else if (len > 0) {
baos.write(buf, 0, len);
}
}
}