HttpComponents HttpCore
  1. HttpComponents HttpCore
  2. HTTPCORE-278

Making CharsetEncoder/CharsetDecoder CodingErrorAction to be configurable

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.2-beta1
    • Component/s: None
    • Labels:
      None

      Description

      Due to various character encoding complexities such as the system is configured to receive UTF-16 and but receives UTF-8 streams etc.. following exception throws by the httpcore library[0].

      At this point the connection will be dropped. But upon receiving this kind of errors we can recover if we configure CharsetEncoder/CharsetDecoder with a CodingErrorAction [1] where the action can be report (default), ignore and resume or replace and resume the coding logic. I think this choice should be a configuration option in SessionInputBufferImpl/SessionOutputBufferImpl constructors.

      A possible patch will follow.

      Rajika

      [0] - java.nio.charset.MalformedInputException: Input length = 1
      at java.nio.charset.CoderResult.throwException(Unknown Source)
      at org.apache.http.impl.nio.reactor.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:189)
      at org.apache.http.impl.nio.codecs.AbstractMessageParser.parse(AbstractMessageParser.java:169)
      at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:154)
      at org.apache.http.impl.nio.DefaultClientIOEventDispatch.inputReady(DefaultClientIOEventDispatch.java:148)
      at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:161)
      at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:339)
      at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:319)
      at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:275)
      at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
      at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:528)
      at java.lang.Thread.run(Unknown Source)

      [1] - http://download.oracle.com/javase/6/docs/api/java/nio/charset/CodingErrorAction.html

      1. HTTPCORE-278.patch
        17 kB
        Rajika Kumarasiri
      2. HTTPCORE-278.patch
        6 kB
        Rajika Kumarasiri
      3. HTTPCORE-278.patch
        6 kB
        Rajika Kumarasiri

        Activity

        Rajika Kumarasiri created issue -
        Hide
        Rajika Kumarasiri added a comment -

        A small patch for the issue.

        Show
        Rajika Kumarasiri added a comment - A small patch for the issue.
        Rajika Kumarasiri made changes -
        Field Original Value New Value
        Attachment HTTPCORE-278.patch [ 12496631 ]
        Hide
        Rajika Kumarasiri added a comment -

        An updated version of the patch.

        Show
        Rajika Kumarasiri added a comment - An updated version of the patch.
        Rajika Kumarasiri made changes -
        Attachment HTTPCORE-278.patch [ 12496639 ]
        Hide
        Oleg Kalnichevski added a comment -

        Hi Rajika,

        The patch looks good. However, for the completeness and consistency sake it would be nice to make the new parameters apply to the blocking AbstractSessionInputBuffer / AbstractSessionOutputBuffer as well, and to have test cases for both i/o models

        Oleg

        Show
        Oleg Kalnichevski added a comment - Hi Rajika, The patch looks good. However, for the completeness and consistency sake it would be nice to make the new parameters apply to the blocking AbstractSessionInputBuffer / AbstractSessionOutputBuffer as well, and to have test cases for both i/o models Oleg
        Hide
        Rajika Kumarasiri added a comment -

        Ok, Oleg. I'll attach a new patch with the changes + test cases.

        Rajika

        Show
        Rajika Kumarasiri added a comment - Ok, Oleg. I'll attach a new patch with the changes + test cases. Rajika
        Rajika Kumarasiri made changes -
        Attachment HTTPCORE-278.patch [ 12497374 ]
        Hide
        Rajika Kumarasiri added a comment -

        The updated patch with the changes + test cases for both I/O models.

        Rajika

        Show
        Rajika Kumarasiri added a comment - The updated patch with the changes + test cases for both I/O models. Rajika
        Hide
        Oleg Kalnichevski added a comment -

        Patch checked in. Many thanks, Rajika, for contributing it.

        Oleg

        Show
        Oleg Kalnichevski added a comment - Patch checked in. Many thanks, Rajika, for contributing it. Oleg
        Oleg Kalnichevski made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 4.2-alpha3 [ 12317978 ]
        Resolution Fixed [ 1 ]
        Hide
        Rajika Kumarasiri added a comment -

        Issue verified.

        Rajika

        Show
        Rajika Kumarasiri added a comment - Issue verified. Rajika
        Rajika Kumarasiri made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Rajika Kumarasiri
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development