You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wink.apache.org by "Bryant Luk (JIRA)" <ji...@apache.org> on 2009/08/27 03:50:59 UTC

[jira] Created: (WINK-152) Automatic content encoding

Automatic content encoding
--------------------------

                 Key: WINK-152
                 URL: https://issues.apache.org/jira/browse/WINK-152
             Project: Wink
          Issue Type: New Feature
          Components: Common
            Reporter: Bryant Luk


It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.

A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WINK-152) Automatic content encoding

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12753632#action_12753632 ] 

Bryant Luk edited comment on WINK-152 at 9/10/09 7:19 AM:
----------------------------------------------------------

The way that you've described the fine grained encoding seems simple enough but I wanted to sketch out some more of it:

In the interface (say "ContentEncoder"), 

{code}
public class GZipEncoder implements ContentEncoder {
    
   private GZIPOutputStream gzipOutputStream;

   public GZipEncoder() {
      /* no arg constructor required */
   }

   public OutputStream getOutputStream(OutputStream original, MultivaluedMap<String, String> responseHeaders) {
       gzipOutputStream = new GZIPOutputStream(original);
       // add Content-Encoding and Vary header
       return gzipOutputStream;
   }

   public boolean isAcceptable(HttpHeaders requestHeaders) {
       // if this should be used. based on Accept-Encoding or other HTTP headers
    }

   public void finish() {
        gzipOutputStream.finish();
   }
}
{code}

I don't know if this is what you meant but I think it's good to have a default implementation that will "do the right thing" so you don't have to specify a class (i.e. as an application developer, I want to just encode the thing).

{code}
@EncodeContent
public Response getSomething() 
{code}

would encode it in any acceptable encoding that is supported by default (gzip, deflate, ....)

{code}
@EncodeContent(Gzipper.class, Deflater.class)
public Response 
{code}

would only encode in gzip or deflate (only encoding once and first in the list, "wins";  if multiple encoders need to be used, then the first encoder should directly call the other encoders itself).

=====

As far as a global encoding, would you be opposed to having a servlet filter that can be optionally added?  It may suffice for doing "global" automatic encoding/decoding.  That way less code has to be changed in the regular paths.  I originally wanted to have an option in cases where the application developer wants to write directly to the stream but it is probably better to give an all or nothing.

      was (Author: bluk):
    The way that you've described the fine grained encoding seems simple enough but I wanted to sketch out some more of it:

In the interface (say "ContentEncoder"), 

{code}
public class GZipEncoder implements ContentEncoder {
    
   private GZIPOutputStream gzipOutputStream;

   public GZipEncoder() {
      /* no arg constructor required */
   }

   public OutputStream getOutputStream(OutputStream original, MultivaluedMap<String, String> responseHeaders) {
       // check headers, if not acceptable return the original
       gzipOutputStream = new GZIPOutputStream(original);
       // add Content-Encoding and Vary header
       return gzipOutputStream;
   }

   public boolean isAcceptable(HttpHeaders requestHeaders) {
       // if this should be used. based on Accept-Encoding or other HTTP headers
    }

   public void finish() {
        gzipOutputStream.finish();
   }
}
{code}

I don't know if this is what you meant but I think it's good to have a default implementation that will "do the right thing" so you don't have to specify a class (i.e. as an application developer, I want to just encode the thing).

{code}
@EncodeContent
public Response getSomething() 
{code}

would encode it in any acceptable encoding that is supported by default (gzip, deflate, ....)

{code}
@EncodeContent(Gzipper.class, Deflater.class)
public Response 
{code}

would only encode in gzip or deflate (only encoding once and first in the list, "wins";  if multiple encoders need to be used, then the first encoder should directly call the other encoders itself).

=====

As far as a global encoding, would you be opposed to having a servlet filter that can be optionally added?  It may suffice for doing "global" automatic encoding/decoding.  That way less code has to be changed in the regular paths.  I originally wanted to have an option in cases where the application developer wants to write directly to the stream but it is probably better to give an all or nothing.
  
> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WINK-152) Automatic content encoding

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryant Luk updated WINK-152:
----------------------------

    Attachment: WINK-152.patch

Attaching a rough patch (mainly because my hard drive seems to be corrupting stuff).

This implements two global properties which can be enabled for requests or responses respectively (default; off).  If there's gzip/deflate encoding incoming, it will automatically decode it.  If there's gzip/deflate acceptable encoding for responses, it will automatically encode it.

I think implementing it per method is not important at this time because if it's allowable for one resource, there shouldn't be a problem for other resources.  This is an all or nothing too (so if a user provides their own Providers that do content encoding, it will be up to them to disable the content decoding part or not use this global property).

I do not remove the Content-Encoding header of the property at this time.

If the user wants the raw output stream, it is still accessible via HttpServletResponse.getOutputStream() which they can then also use a @Context Providers to send back the request.  There's no way to read in the raw input stream before a method is invoked (unless it didn't have any entity parameters and then you read it raw via an injected HttpServletRequest), but I don't think this is as likely a scenario.

> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WINK-152) Automatic content encoding

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12753632#action_12753632 ] 

Bryant Luk commented on WINK-152:
---------------------------------

The way that you've described the fine grained encoding seems simple enough but I wanted to sketch out some more of it:

In the interface (say "ContentEncoder"), 

{code}
public class GZipEncoder implements ContentEncoder {
    
   private GZIPOutputStream gzipOutputStream;

   public GZipEncoder() {
      /* no arg constructor required */
   }

   public OutputStream getOutputStream(OutputStream original, MultivaluedMap<String, String> responseHeaders) {
       // check headers, if not acceptable return the original
       gzipOutputStream = new GZIPOutputStream(original);
       // add Content-Encoding and Vary header
       return gzipOutputStream;
   }

   public boolean isAcceptable(HttpHeaders requestHeaders) {
       // if this should be used. based on Accept-Encoding or other HTTP headers
    }

   public void finish() {
        gzipOutputStream.finish();
   }
}
{code}

I don't know if this is what you meant but I think it's good to have a default implementation that will "do the right thing" so you don't have to specify a class (i.e. as an application developer, I want to just encode the thing).

{code}
@EncodeContent
public Response getSomething() 
{code}

would encode it in any acceptable encoding that is supported by default (gzip, deflate, ....)

{code}
@EncodeContent(Gzipper.class, Deflater.class)
public Response 
{code}

would only encode in gzip or deflate (only encoding once and first in the list, "wins";  if multiple encoders need to be used, then the first encoder should directly call the other encoders itself).

=====

As far as a global encoding, would you be opposed to having a servlet filter that can be optionally added?  It may suffice for doing "global" automatic encoding/decoding.  That way less code has to be changed in the regular paths.  I originally wanted to have an option in cases where the application developer wants to write directly to the stream but it is probably better to give an all or nothing.

> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WINK-152) Automatic content encoding

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12753114#action_12753114 ] 

Bryant Luk commented on WINK-152:
---------------------------------

There are cases where the deployed production environment will not support automatic content encoding/decoding but the application itself can and should support it.  Also, while some web servers and intermediaries do support content encoding, the configuration and recommended practices for each one is vastly different, so having a single solution to this is a bit easier.

> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WINK-152) Automatic content encoding

Posted by "Michael Elman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12752946#action_12752946 ] 

Michael Elman commented on WINK-152:
------------------------------------

Sorry for a late response, after a lot of work has been done,
but actually why do we need this feature?
AFAIK compression is supported automatically by most of the web servers.
For example in Tomcat, you should put {{compression}} attribute on the {{Connector}} in order to turn compression on.


> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (WINK-152) Automatic content encoding

Posted by "Mike Rheinheimer (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mike Rheinheimer closed WINK-152.
---------------------------------


Issue is resolved.  Closing per Bryant's approval to do so.

> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>             Fix For: 1.1.1
>
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WINK-152) Automatic content encoding

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryant Luk resolved WINK-152.
-----------------------------

    Fix Version/s: 1.1.1
       Resolution: Fixed

I added two filters that you can add in your web.xml to enable "automatic" Content-Encoding processing in the inbound request and outbound response.

{code}
<filter>
<filter-name>ContentEncodingRequestFilter</filter-name>
<filter-class>org.apache.wink.server.internal.servlet.contentencode.ContentEncodingRequestFilter</filter-class>
</filter>
<filter>
<filter-name>ContentEncodingResponseFilter</filter-name>
<filter-class>org.apache.wink.server.internal.servlet.contentencode.ContentEncodingResponseFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ContentEncodingRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ContentEncodingResponseFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
{code}

Note that some servlet/web containers have automatic decoding (such as WebSphere 6.1 and 7.0 and you can disable it via http://www-01.ibm.com/support/docview.wss?uid=swg1PK41619 ) but you may want to add the automatic ContentEncodingResponseFilter for outbound responses.  Also, some other products such as Apache httpd/Tomcat have different ways to handle content encoding so you may want to investigate their server documentation.

> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>             Fix For: 1.1.1
>
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (WINK-152) Automatic content encoding

Posted by "Bryant Luk (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bryant Luk reassigned WINK-152:
-------------------------------

    Assignee: Bryant Luk

> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WINK-152) Automatic content encoding

Posted by "Michael Elman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12754900#action_12754900 ] 

Michael Elman commented on WINK-152:
------------------------------------

bq. "do the right thing" 
I'm not sure we can always know what's is the right thing...
Even in your example: why should anyone perform both deflate and gzip?

We may accept shortcuts though. Like:
{code}
@EncodeContent(gzip, deflate)
public Response
{code}

bq. As far as a global encoding, would you be opposed to having a servlet filter that can be optionally added?
Servlet filter seems to be a good option for this use case.

> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WINK-152) Automatic content encoding

Posted by "Michael Elman (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WINK-152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12753429#action_12753429 ] 

Michael Elman commented on WINK-152:
------------------------------------

One of the potential problems that can occur is double encoding by both Wink and web servers.
IMO we should not duplicate a basic web server functionality.

However, it would *very* nice  to provide fine grained encoding. Something like:
consider annotation @EncodeContent that can be put on method/class.
* When put on method, the response should be encoded with the specified encoding.
* When put on class, all responses will be encoded. The annotation on method override annotation on class.
The annotation accepts class that is responsible for encoding (implements interface that receives stream and returns stream).
Of course, we can provide default implementations, like: gzip/deflate, base64 and may be more.

In addition, we may support @DecodeContent annotation that can be put on entity parameters and process decoding.

Thoughts?

> Automatic content encoding
> --------------------------
>
>                 Key: WINK-152
>                 URL: https://issues.apache.org/jira/browse/WINK-152
>             Project: Wink
>          Issue Type: New Feature
>          Components: Common
>            Reporter: Bryant Luk
>            Assignee: Bryant Luk
>         Attachments: WINK-152.patch
>
>
> It would be neat to have an automatic content encoding feature.  In particular, gzipping content for clients that support it (via Accept-Encoding header) can improve response times.
> A property for automatically compressing/decompressing content available in Wink or an annotation specified on a resource or resource method.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.