views:

381

answers:

4

I am trying to build a xpi file using Java servlet. If I return the xpi as a zip using the following code in the servlet -

response.setContentType("application/zip");
response.setHeader("Content-Disposition","inline;filename=xpitest.xpi;");

Everything works fine with above code. I can save the file to the filesystem and install it.

However, if I try to return the file with the following header and contenttype -

response.setContentType("application/x-xpinstall");
response.setHeader("Content-Disposition","filename=xpitest.xpi;");

On the client side, firefox recognizes that the file is an xpi package and shows the Install option. But, when I try to install it, I get this error - "Not a valid install package - 207"

Can someone suggest what I need to use for setContentType() and setHeader()?

Thanks.

+1  A: 

A traffic sniff from addons.mozilla.org upon clicking on "Add to Firefox" shows that all you need is the Content-Type set to application/x-xpinstall and the right Content-Length. You could try the same. Here are the headers:

HTTP/1.1 200 OK
Date: Wed, 11 Nov 2009 04:51:03 GMT
Server: Apache
Last-Modified: Thu, 05 Nov 2009 15:10:39 GMT
Accept-Ranges: bytes
Content-Length: 4248
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: application/x-xpinstall
Murali VP
A: 

This is a guess, but, since you are returning a zipped .xpi, not an .xpi, I imagine you must use application/zip? if an .xpi is not by nature zipped then indeed a zipped .xpi is not valid by itself. How about sending it uncompressed?

Sean Owen
xpi is just an extension it is a zip files, much like a jar file they are all glorified zip files.
Hamza Yerlikaya
A: 

Your second response Content-Disposition field is missing an inline keyword, may this be a reason?

Also as Murali suggested you should set Content-Length to an actual value.

Alexander Pogrebnyak
A: 

You should be able to get the content lenght using the ByteArrayOutputStream.

your servlet should write the document into a ByteArrayOutputStream, look up its size when done, put that into the Content-Length field.

Then send the content via byteArrayStream.writeTo(response.getOutputStream()).

-Bipin

coolest_head