Announcement Announcement Module
Collapse
No announcement yet.
Bugfix HttpInboundGateway 1.0.4 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bugfix HttpInboundGateway 1.0.4

    Problem:

    I extract data from a DB and create a spring-integration message wich is passed over http to another machine.

    For 10 or 100 records everything works fine. But I use a bigger number of records the message is truncated.

    The debugger shows, that the full size (43298 bytes) of the message is allocated for a byte array, but after the offset 1EF4 all bytes are filled with 00 which leads to a java.io.StreamCorruptedException: invalid type code: 00


    1ED0 30 3A 30 31 3A 32 38 2E 30 0D 0A 32 36 34 36 7C 0:01:28.0..2646|
    1EE0 31 32 7C 31 30 30 30 30 30 30 30 31 37 37 7C 32 12|10000000177|2
    1EF0 30 30 35 2D 30 00 00 00 00 00 00 00 00 00 00 00 005-0...........
    1F00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    1F10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    ...
    A910 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    A920 00 00


    Solution:

    org.springframework.integration.http.DefaultInboun dRequestMapper

    DefaultInboundRequestMapper has an obvious bug. stream.read() should be executed within a loop, since it returns only the number of bytes read so far. So the byte array is only populated with the bytes read so far.
    I fixed this by extending the createPayloadFromInputStream method.

    Could this please adapted and commited, so that I can download this with other bugfixes in further releases?



    private byte[] createPayloadFromInputStream(HttpServletRequest request) throws Exception {
    InputStream stream = request.getInputStream();
    int length = request.getContentLength();
    if (length == -1) {
    throw new ResponseStatusCodeException(HttpServletResponse.SC _LENGTH_REQUIRED);
    }
    if (logger.isDebugEnabled()) {
    logger.debug("received " + request.getMethod() + " request, "
    + "creating byte array payload with content lenth: " + length);
    }
    byte[] bytes = new byte[length];
    int offs = 0;
    while ( offs < length ) {
    int n = stream.read(bytes, offs, length - offs);
    if ( n < 0 ) {
    if ( offs < length ) {
    if (logger.isDebugEnabled()) {
    logger.debug("read: " + offs + " bytes from stream instead expected:" + length);
    }
    }
    break;
    }
    offs += n;
    }
    return bytes;
    }

  • #2
    Do you by any chance have something that can be isolated into a unit test. For example, something that I could pass like this:
    Code:
    mapper.toMessage(request);

    Comment

    Working...
    X