mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 22:27:55 +01:00
Add debug information on broken input streams.
This commit is contained in:
parent
337a67a8f6
commit
4cce432bb8
@ -0,0 +1,54 @@
|
|||||||
|
package com.wisemapping.rest;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpInputMessage;
|
||||||
|
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
|
public class DebugMappingJacksonHttpMessageConverter extends MappingJacksonHttpMessageConverter {
|
||||||
|
@Override
|
||||||
|
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
|
||||||
|
final byte[] bytes = IOUtils.toByteArray(inputMessage.getBody());
|
||||||
|
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
||||||
|
final WrapHttpInputMessage wrap = new WrapHttpInputMessage(bais, inputMessage.getHeaders());
|
||||||
|
|
||||||
|
try {
|
||||||
|
return super.readInternal(clazz, wrap);
|
||||||
|
|
||||||
|
} catch (org.springframework.http.converter.HttpMessageNotReadableException e) {
|
||||||
|
throw new HttpMessageNotReadableException("Request Body:\n" + new String(bytes, "UTF-8"), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class HttpMessageNotReadableException extends org.springframework.http.converter.HttpMessageNotReadableException {
|
||||||
|
|
||||||
|
public HttpMessageNotReadableException(String msg, org.springframework.http.converter.HttpMessageNotReadableException cause) {
|
||||||
|
super(msg, cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WrapHttpInputMessage implements HttpInputMessage {
|
||||||
|
private InputStream body;
|
||||||
|
private HttpHeaders headers;
|
||||||
|
|
||||||
|
WrapHttpInputMessage(InputStream is, HttpHeaders headers) {
|
||||||
|
this.body = is;
|
||||||
|
this.headers = headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getBody() throws IOException {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpHeaders getHeaders() {
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.wisemapping.rest;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RestMvcConfiguration extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureMessageConverters(@NotNull final List<HttpMessageConverter<?>> converters) {
|
||||||
|
converters.add(converter());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
MappingJacksonHttpMessageConverter converter() {
|
||||||
|
return new DebugMappingJacksonHttpMessageConverter();
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
<context:component-scan base-package="com.wisemapping.rest"/>
|
<context:component-scan base-package="com.wisemapping.rest"/>
|
||||||
<context:annotation-config/>
|
<context:annotation-config/>
|
||||||
<mvc:annotation-driven/>
|
|
||||||
|
|
||||||
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
|
||||||
<property name="classesToBeBound">
|
<property name="classesToBeBound">
|
||||||
|
Loading…
Reference in New Issue
Block a user