cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fabien Thouny (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-5349) Provide ability to disable chunked transfer encoding for java.io.File entity
Date Wed, 23 Oct 2013 21:56:44 GMT

    [ https://issues.apache.org/jira/browse/CXF-5349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13803385#comment-13803385
] 

Fabien Thouny commented on CXF-5349:
------------------------------------

I just tested it with Jersey 2.x and you were right, Jersey 2.x doesn't support it anymore.

However, to be complete, either with Jersey 2.x or CXF, if we provides the "Content-Length"
manually, it disables the Chunked Transfer Encoding.

If this behavior is maintained with CXF 3.0.0, thus it's perfectly fine for me to close this
ticket.

We can provide the "Content-Length" directly in the resource (or in a ContainerResponseFilter
to be cleaner) :
{code}
@GET
@Path("/file")
public Response getResource() throws URISyntaxException {
        File file = [...];
        return Response.ok(file)
                .type("audio/mp3")
                .header("Content-Disposition", "filename=my_file.mp3")
                .header(HttpHeaders.CONTENT_LENGTH, file.length())
                .build();
}
{code}

Thanks,

Fabien

> Provide ability to disable chunked transfer encoding for java.io.File entity
> ----------------------------------------------------------------------------
>
>                 Key: CXF-5349
>                 URL: https://issues.apache.org/jira/browse/CXF-5349
>             Project: CXF
>          Issue Type: Improvement
>          Components: JAX-RS
>    Affects Versions: 2.7.7
>            Reporter: Fabien Thouny
>            Assignee: Sergey Beryozkin
>
> As it was done for byte array in CXF-4760, it will be nice to be able to disable chunked
transfer encoding for java.io.File 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
(v6.1#6144)

Mime
View raw message