Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-2837

EOFException by using HTTP outbound gateway

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 2.1.4
    • Fix Version/s: 2.2. GA
    • Component/s: HTTP Support
    • Labels:
    • Environment:
      Windows Vista 64, JDK 1.6.0_34

      Description

      We faced some issues using http outbound gateway via service method that has a POJO as parameter and another POJO as result.

      public interface RequestGateway {
      	ResponseObject execute(RequestObject request);
      }
      

      The client configuration:

      <int:gateway id="requestGateway" 
       service-interface="org.springframework.integration.samples.http.RequestGateway"
             default-request-channel="requestChannel">
      	</int:gateway>             
      	
      	<int:channel id="requestChannel"/>
      
      	<int-http:outbound-gateway request-channel="requestChannel" 
            url="http://localhost:8181/http/receiveGateway"
      		http-method="POST" 
      		expected-response-type="org.springframework.integration.samples.http.ResponseObject" />
      

      The server configuration:

         <bean class="org.springframework.integration.http.inbound.UriPathHandlerMapping"/>
      
         <bean id="testServiceImpl" class="org.springframework.integration.samples.http.RequestGatewayImpl">
         </bean>   
         
         <!-- Inbound HTTP Gateway -->
         <int-http:inbound-gateway id="httpTestGateway" path="/http/receiveGateway"
            request-channel="requests" reply-channel="executions" 
            />
      
         <int:channel id="requests" />
         <int:channel id="executions" />
         
         <int:service-activator input-channel="requests" output-channel="executions" 
            ref="testServiceImpl"/>
      

      And test case:

      @Autowired
      	RequestGateway requestGateway;
      
      	@Test
      	public void testHttpGateway() throws Exception {
      		RequestObject request = new RequestObject();
      		ResponseObject execute = requestGateway.execute(request);
      	}
      

      If we run the test we'll get:

      Caused by: org.springframework.web.client.HttpServerErrorException: 500 Could not convert reply: no suitable HttpMessageConverter found for type [org.springframework.integration.samples.http.ResponseObject] and accept types [[text/html, image/gif, image/jpeg, */*;q=.2, */*;q=.2]]

      Strange accept types, I'd say. OK, I found a solution (right one?). We set Accept header explicit.

      	<int:gateway id="requestGateway" 
      	             service-interface="org.springframework.integration.samples.http.RequestGateway"
      	             default-request-channel="requestChannel">
           <int:method name="execute" request-channel="requestChannel">
             <int:header name="Accept" value="application/x-java-serialized-object"/>
           </int:method>   
      	</int:gateway>             
      

      not nice but works. After the conversion on the server works, the next problem the conversion on client.

      Caused by: org.springframework.web.client.ResourceAccessException: I/O error: null; nested exception is java.io.EOFException
      	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:453)
      	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
      	at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:384)
      	at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:258)
      	... 50 more
      Caused by: java.io.EOFException
      	at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
      	at java.io.ObjectInputStream$BlockDataInputStream.readUTFBody(ObjectInputStream.java:3018)
      	at java.io.ObjectInputStream$BlockDataInputStream.readUTF(ObjectInputStream.java:2819)
      	at java.io.ObjectInputStream.readString(ObjectInputStream.java:1598)
      	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1319)
      	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
      	at java.util.HashMap.readObject(HashMap.java:1030)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:969)
      	at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
      	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
      	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
      	at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
      	at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
      	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
      	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
      	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
      	at org.springframework.integration.http.converter.SerializingHttpMessageConverter.readInternal(SerializingHttpMessageConverter.java:68)
      	at org.springframework.integration.http.converter.SerializingHttpMessageConverter.readInternal(SerializingHttpMessageConverter.java:38)
      	at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:154)
      	at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:74)
      	at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:619)
      	at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:1)
      	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:446)
      	... 53 more
      

      The reason: SerializingHttpMessageConvert does not implement getContentLength() from parent. The integration framework gets somehow as fall-back the content length of the request. If actual content length of response is greater than request one then EOFException is thrown.

      The solution is quite trivial but analysis made me crazy.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              grussell Gary Russell
              Reporter:
              valery Valery Gavrilovets
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: