本文整理汇总了Java中org.springframework.http.converter.HttpMessageNotReadableException类的典型用法代码示例。如果您正苦于以下问题:Java HttpMessageNotReadableException类的具体用法?Java HttpMessageNotReadableException怎么用?Java HttpMessageNotReadableException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpMessageNotReadableException类属于org.springframework.http.converter包,在下文中一共展示了HttpMessageNotReadableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readInternal
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的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: readJavaType
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
try {
if (inputMessage instanceof MappingJacksonInputMessage) {
Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
if (deserializationView != null) {
return this.objectMapper.readerWithView(deserializationView).withType(javaType).
readValue(inputMessage.getBody());
}
}
return this.objectMapper.readValue(inputMessage.getBody(), javaType);
}
catch (IOException ex) {
throw new HttpMessageNotReadableException("Could not read document: " + ex.getMessage(), ex);
}
}
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:17,代码来源:AbstractJackson2HttpMessageConverter.java
示例3: readInternal
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的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: readFromSource
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的package包/类
@Override
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException {
Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required");
try {
Object result = this.unmarshaller.unmarshal(source);
if (!clazz.isInstance(result)) {
throw new TypeMismatchException(result, clazz);
}
return result;
}
catch (UnmarshallingFailureException ex) {
throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex);
}
}
示例5: readInternal
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的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.");
}
}
示例6: readStAXSource
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的package包/类
private Source readStAXSource(InputStream body) {
try {
XMLInputFactory inputFactory = XMLInputFactory.newFactory();
inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities());
if (!isProcessExternalEntities()) {
inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
}
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body);
return new StAXSource(streamReader);
}
catch (XMLStreamException ex) {
throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex);
}
}
示例7: handleHttpMessageNotReadableException
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的package包/类
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public XAPIErrorInfo handleHttpMessageNotReadableException(final HttpServletRequest request, HttpMessageNotReadableException e) {
if (e.getCause() instanceof UnrecognizedPropertyException) {
return this.handleUnrecognizedPropertyException(request, (UnrecognizedPropertyException)e.getCause());
} else {
XAPIErrorInfo result;
if (e.getCause() instanceof JsonProcessingException) {
final JsonProcessingException jpe = (JsonProcessingException)e.getCause();
result = new XAPIErrorInfo(HttpStatus.BAD_REQUEST, request, jpe.getOriginalMessage());
} else {
result = new XAPIErrorInfo(HttpStatus.BAD_REQUEST, request, e);
}
this.logException(e);
this.logError(result);
return result;
}
}
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:20,代码来源:XAPIExceptionHandlerAdvice.java
示例8: readInternal
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的package包/类
@Override
protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
WxMediaResource wxMediaResource = new WxMediaResource(inputMessage);
if (wxMediaResource.isUrlMedia() && !clazz.isAssignableFrom(WxMediaResource.class)) {
throw new WxApiException("不支持的返回类型,接口返回了url");
}
if (InputStreamResource.class == clazz) {
return new InputStreamResource(wxMediaResource.getInputStream());
} else if (clazz.isAssignableFrom(WxMediaResource.class)) {
return wxMediaResource;
} else if (clazz.isAssignableFrom(ByteArrayResource.class)) {
return new ByteArrayResource(wxMediaResource.getBody());
} else if (clazz.isAssignableFrom(FileSystemResource.class)) {
return new FileSystemResource(wxMediaResource.getFile());
}
// else if (clazz.isAssignableFrom(File.class)) {
// return wxMediaResource.getFile();
// }
throw new WxApiException("不支持的返回类型");
}
示例9: readInternal
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的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() + ".");
}
示例10: read
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的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);
}
示例11: readInternal
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的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);
}
示例12: readWithMessageConverters
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的package包/类
@Override
protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter methodParam,
Type paramType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException {
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(servletRequest);
Object arg = readWithMessageConverters(inputMessage, methodParam, paramType);
if (arg == null) {
if (methodParam.getParameterAnnotation(RequestBody.class).required()) {
throw new HttpMessageNotReadableException("Required request body is missing: " +
methodParam.getMethod().toGenericString());
}
}
return arg;
}
示例13: readInternal
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的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);
}
}
示例14: readInternal
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的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.");
}
}
示例15: testXmlBomb
import org.springframework.http.converter.HttpMessageNotReadableException; //导入依赖的package包/类
@Test
public void testXmlBomb() throws Exception {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String content = "<?xml version=\"1.0\"?>\n" +
"<!DOCTYPE lolz [\n" +
" <!ENTITY lol \"lol\">\n" +
" <!ELEMENT lolz (#PCDATA)>\n" +
" <!ENTITY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" +
" <!ENTITY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" +
" <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" +
" <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" +
" <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" +
" <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" +
" <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" +
" <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" +
" <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" +
"]>\n" +
"<rootElement><external>&lol9;</external></rootElement>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
this.thrown.expect(HttpMessageNotReadableException.class);
this.thrown.expectMessage("DOCTYPE");
this.converter.read(RootElement.class, inputMessage);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:Jaxb2RootElementHttpMessageConverterTests.java