cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin (JIRA)" <>
Subject [jira] [Commented] (CXF-5349) Provide ability to disable chunked transfer encoding for entity
Date Tue, 22 Oct 2013 13:54:42 GMT


Sergey Beryozkin commented on CXF-5349:

Originally the default provider was returning a length of byte[] arrays but that interfered
with GZIP and similar compressions. On top of that JAX-RS 2.0 has actually deprecated getSize(),
the idea being that if you want  then you can set Content-Length from response filter or writer
interceptors. I thought it was reasonable to deprecate the default providers trying to return
a length because only the user knows if GZIP or something would be applied afterwards, but
deprecating even custom providers returning the length was wrong - again if the users know
they won;t use GZIP then why don't return the length from getSize, but it ended up being deprecated
across the board. That is why I added that specific code - that can only work if the user
has done a custom byte[] provider => the user wants the custom provider set the length/size.
The risk there is that relying on getSize() may end up being not-portable across JAX-RS 2.0

Now, getSize() was only deprecated in the text - so it will probably be portable to use when
it is done with caution anyway. Do you know if Jersey (the one which implements JAX-RS 2.0)
still supports it ? If it does then I can tweak that 'if' check to recognize File objects

> Provide ability to disable chunked transfer encoding for entity
> ----------------------------------------------------------------------------
>                 Key: CXF-5349
>                 URL:
>             Project: CXF
>          Issue Type: Improvement
>          Components: JAX-RS
>    Affects Versions: 2.7.7
>            Reporter: Fabien Thouny
> As it was done for byte array in CXF-4760, it will be nice to be able to disable chunked
transfer encoding for entity in BinaryDataProvider.
> I tried to provide a custom BinaryDataProvider as a workaround :
> {code}
> @Component
> @Provider
> public class CustomBinaryDataProvider extends BinaryDataProvider<Object> {
>     @Override
>     public long getSize(Object t, Class<?> type, Type genericType, Annotation[]
annotations, MediaType mt) {
>         if (File.class.isAssignableFrom(t.getClass())) {
>             return ((File) t).length();
>         }
>         return super.getSize(t, type, genericType, annotations, mt);
>     }
> }
> {code}
> but it seems not to be enough because there's an explicit check in JAXRSUtils#writeMessageBody
to put the "Content-Length" header only for byte arrays :
> {code}
> MessageBodyWriter<Object> writer = ((WriterInterceptorMBW)writers.get(0)).getMBW();
>             if (type == byte[].class) {
>                 long size = writer.getSize(entity, type, genericType, annotations, mediaType);
>                 if (size != -1) {
>                     httpHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, Long.toString(size));
>                 }
>             }
>             writer.writeTo(entity, type, genericType, annotations, mediaType,
>                            httpHeaders, entityStream);
> {code}
> Thanks for your help,
> Fabien

This message was sent by Atlassian JIRA

View raw message