You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Sebastian A. Vik" <se...@learningwell.se> on 2012/03/06 13:53:38 UTC

IResourceStream.contentType ignored

Hi everybody,

I'm using this code to send a data stream to the client:

ResourceStreamRequestHandler handler = new 
ResourceStreamRequestHandler(new IResourceStream() {
[...]
     @Override
     public String getContentType() {
         return 
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
     }
[...]
}, "data.xlsx");
component.getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);

The content type is completely ignored. It comes out as text/plain. It 
works with xml Content-Type+filename but I believe only because the 
filename pattern .xml results in application/xml content type being 
generated in ResourceStreamResource.newResourceResponse(Attributes 
attributes) which calls Application.getMimeType(String fileName):

             final String contentType;
             if (fileName != null && Application.exists())
             {
                 contentType = *Application.get().getMimeType(fileName);*
             }
             else
             {
                 contentType = stream.getContentType();
             }


The javadoc for IResourceStream.getContentType()**says "Return null to 
let ResourceStreamRequestHandler handle the Content-Type automatically".

Am I missing something? Shouldn't 
ResourceStreamResource.newResourceResponse(Attributes attributes) check 
for null value returned from stream.getContentType() before calling 
Application.getMimeType()?

Thank you very much,
Sebastian