简体   繁体   English

SpringBoot - HttpMessageNotReadableException:JSON 解析错误:java.net.SocketTimeoutException

[英]SpringBoot - HttpMessageNotReadableException: JSON parse error: java.net.SocketTimeoutException

My code is throwing an exception as follows我的代码抛出异常如下

JSON parse error: java.net.SocketTimeoutException; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.net.SocketTimeoutException (through reference chain: java.util.ArrayList[9])
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: java.net.SocketTimeoutException; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.net.SocketTimeoutException (through reference chain: java.util.ArrayList[9])
        at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:245) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:227) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:204) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:127) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) ~[spring-web-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) [spring-webmvc-5.1.9.RELEASE.jar!/:5.1.9.RELEASE]

My spring-boot version is 2.1.7.RELEASE and the embedded tomcat is used to run the application.我的 spring-boot 版本是 2.1.7.RELEASE,嵌入式 tomcat 用于运行应用程序。 I also set the property server.connection-timeout=30s我还设置了属性server.connection-timeout=30s

I almost search everywhere and couldn't identify the root cause of this problem.我几乎到处搜索,无法确定这个问题的根本原因。 I am also catching this exception and printing it in the log and return the response as BAD_REQUEST.我也捕捉到了这个异常并将其打印在日志中并将响应返回为 BAD_REQUEST。

This exception is throwing intermittently and my production server consumes above 80% of CPU and memory at this time.这个异常间歇性地抛出,我的生产服务器此时消耗了 80% 以上的 CPU 和 memory。

This is actually a POST request and the request body is validated as follows这实际上是一个 POST 请求,请求正文验证如下

    @RequestMapping( value = "/save", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
    public SaveDto create( @RequestBody @Valid SaveDto saveDto,
        HttpServletResponse response, HttpServletRequest request )
    {
      //my logic
    }

and my SaveDto is as follows我的 SaveDto 如下

@JsonInclude( JsonInclude.Include.NON_NULL )
public class SaveDto
{
    private String id;
    @Size( min = 1 )
    @Valid
    private List< SaveEntryDto > saveLogEntries;
}

My saveEntryDto is as follows我的 saveEntryDto 如下

public class SaveEntryDto implements Comparable<SaveEntryDto> {
    private String id;
    private String idRef;
    private WER wer;
    @Min(0)
    @Max(1440)
    private Integer kjh;
    @Min(0)
    @Max(1440)
    private Integer gfd;
    private String abc;
    private Double def;
    private String ghi;
    private Boolean klm = Boolean.FALSE;
    private Boolean hug;
    private Boolean qwe;
    private Double azx;
    private Double xds;
    private Boolean cvf = Boolean.FALSE;
    private Boolean bgh = Boolean.FALSE;
    private String nmj;
    private Boolean rgh;
    private Boolean jkh;
    private Boolean mkl = Boolean.FALSE;
    private Boolean wed = Boolean.FALSE;
    private Long ftu;
    private XYZ xyzxd;
    private String klp;
    private ABC xxz;
    private Boolean llo;
    private Long iop;
    private Double poi;
    private Boolean uyt = Boolean.FALSE;
    private Boolean rew = Boolean.FALSE;
    private String qsd;
}

Try server.tomcat.connection-timeout instead of server.connection-timeout .尝试server.tomcat.connection-timeout而不是server.connection-timeout For some reason there are many mentions of server.connection-timeout , but I don't think it does anything (according to https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html ).出于某种原因,有很多提到server.connection-timeout ,但我认为它没有任何作用(根据https://docs.spring.io/spring-boot/docs/current/reference/html/application-属性.html )。

server.tomcat.connection-timeout=30000 - this sets the timeout to 30s server.tomcat.connection-timeout=30000 - 这会将超时设置为 30 秒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM