Announcement Announcement Module
Collapse
No announcement yet.
Intermittent HttpMessageNotReadableException when calling postForObject Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Intermittent HttpMessageNotReadableException when calling postForObject

    I am seeing an intermittent error. I am using the a org.springframework.web.client.RestTemplate, calling postForObject. The parameters are the path, a custom class, and the response is a list.

    Here is a stack trace:

    Code:
    org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out 
    
    org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readJavaType (MappingJacksonHttpMessageConverter.java:170)
    org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.read(MappingJacksonHttpMessageConverter.java:162)
    org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:138)
    org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:180)
    org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:95)
    org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
    For reference, here's the method where it's breaking, line 170 is the "throw new" line:

    Code:
    	private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
    		try {
    			return this.objectMapper.readValue(inputMessage.getBody(), javaType);
    		}
    		catch (IOException ex) {
    			throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex);
    		}
    	}
    Does anyone know why this would happen? It seems like the request is finished, but it's failing trying to serialize the JSON returned into the object return type.

  • #2
    Update w/ more info

    More info:

    Since this is a POST, and the web service criteria had a List<Integer>, I figured maybe the primitive type was at fault. Tried wrapping the Integer in a class to see if that would help, so created a IntCriteria class that contained an integer, and used it instead.


    Here's my criteria object:

    Code:
    package com.example;
    
    import java.io.Serializable;
    import java.util.List;
    
    public class CriteriaReference implements Serializable {
    
    	private static final long serialVersionUID = 1L;
    
    	private List<IntCriteria> criteriaIds;
    	private List<IntCriteria> referenceIds;
    	private Integer criteriaContentId;
    	
    	public List<IntCriteria> getCriteriaIds() {
    		return tagIds;
    	}
    	public void setCriteriaIds(List<IntCriteria> criteriaIds) {
    		this.criteriaIds = criteriaIds;
    	}
    	public List<IntCriteria> getReferenceIds() {
    		return referenceIds;
    	}
    	public void setReferenceIds(List<IntCriteria> referenceIds) {
    		this.referenceIds = referenceIds;
    	}
    	public int getCriteriaContentId() {
    		return criteriaContentId;
    	}
    	public void setCriteriaContentId(int criteriaContentId) {
    		this.criteriaContentId = criteriaContentId;
    	}
    }
    The problem is still mainfesting itself. Will next try to enable logging on the server to get a sample request/response that contained the issue.

    Comment


    • #3
      The exception is coming from the Rest Template. We believe it's related to a network issue, but exactly how is uncertain.

      We were using the Java implementation. We've since changed the Rest Template connector to an Apache implementation. Since then, we have seen the problem go away.

      Just to re-iterate, we started seeing this problem only with a POST that contain an object with a List (in the body). It was not reliably reproducible. Just from pure speculation, this may be a network issue that is handled more gracefully by the Apache interface, or maybe a race/load condition that is handled in a thread-safe manner in Apache but not in the Java implementation.

      Hope this helps somebody in the future!

      Comment

      Working...
      X