Uploaded image for project: 'Sakai'
  1. Sakai
  2. SAK-16491

ActionReturn entities not setting encoding for large binary entities reliably

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: RESOLVED
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.7.0, 2.7.1, 2.8.0
    • Fix Version/s: None
    • Component/s: Entity Broker
    • Labels:
      None

      Description

      I have a custom entity that returns binary as it's requesting an image, but could be any resource.

      I am using the ActionReturn object to return my OutputSteam of bytes:
      eg:
      ActionReturn actionReturn = new ActionReturn("BASE64", "image/jpeg", out);

      When I made a request for this entity, for large resources, the encoded binary is displayed on screen. Inspecting the response headers has this:
      Content-Type:text/html;charset=UTF-8

      ie its ignoring my encoding and mimetype.

      However for smaller resources, it is working correctly, the image displays as an image, and the headers correctly show:
      Content-Type:image/jpeg;charset=BASE64

      After investigating EntityActionsManager.java and LazyResponseOutputStream.java and adding a bunch of println statements everywhere, I get this:

      Thumbnail:
      resource.getMimeType(): image/jpeg
      resource.getLength(): 3050
      actionReturn.encoding: BASE64
      actionReturn.mimeType: image/jpeg
      not null, setting inputs into response...
      response.isCommitted.1: false
      //SETTERS HERE

      response.isCommitted.2: false
      response.getCharacterEncoding: BASE64
      response.getContentType: image/jpeg;charset=BASE64
      response.isCommitted.3: false

      actionReturn.encoding: BASE64
      actionReturn.mimeType: image/jpeg
      response.getCharacterEncoding: BASE64
      response.getContentType: image/jpeg;charset=BASE64

      Larger image:
      resource.getMimeType(): image/jpeg
      resource.getLength(): 33328
      actionReturn.encoding: BASE64
      actionReturn.mimeType: image/jpeg
      not null, setting inputs into response...
      response.isCommitted.1: true
      // SETTERS HERE

      response.isCommitted.2: true
      response.getCharacterEncoding: UTF-8
      response.getContentType: text/html;charset=UTF-8
      response.isCommitted.3: true

      actionReturn.encoding: BASE64
      actionReturn.mimeType: image/jpeg
      response.getCharacterEncoding: UTF-8
      response.getContentType: text/html;charset=UTF-8

      In the above output, the SETTERS HERE is where EntityActionsManager sets the supplied values into the response. In some cases, the response is already committed, so it will do nothing. actionReturn still has the right info, but it can't set it into the response.

      It may be due to this:
      http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletResponse.html#setCharacterEncoding(java.lang.String)
      This method can be called repeatedly to change the character encoding. This method has no effect if it is called after getWriter has been called or after the response has been committed.

      Could it be in LazyResponseOutputStream ?

      Also, when it works the content length was 3050 because I requested a thumbnail of the image as the entity, when it fails the contentLength was 33328. Both image/jpeg and both BASE64.

      Discussed with Aaron over email. Hopefully this captures it all in one post.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  steve.swinsburg Steve Swinsburg
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Git Source Code