當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpMessageNotReadableException類代碼示例

本文整理匯總了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;
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:18,代碼來源:LoggregatorHttpMessageConverter.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:AbstractWireFeedHttpMessageConverter.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:MarshallingHttpMessageConverter.java

示例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.");
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:SourceHttpMessageConverter.java

示例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);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:SourceHttpMessageConverter.java

示例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("不支持的返回類型");
    }
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:23,代碼來源:WxMediaResourceMessageConverter.java

示例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() + ".");
}
 
開發者ID:bobxwang,項目名稱:springboot-scala-withswagger,代碼行數:18,代碼來源:ProtostuffHttpMessageConverter.java

示例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);
}
 
開發者ID:hs-web,項目名稱:hsweb-framework,代碼行數:18,代碼來源:FastJsonGenericHttpMessageConverter.java

示例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);
}
 
開發者ID:hs-web,項目名稱:hsweb-framework,代碼行數:19,代碼來源:FastJsonHttpMessageConverter.java

示例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;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:RequestResponseBodyMethodProcessor.java

示例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);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:AbstractWireFeedHttpMessageConverter.java

示例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.");
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:SourceHttpMessageConverter.java

示例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


注:本文中的org.springframework.http.converter.HttpMessageNotReadableException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。