开发者

Build firefox extension (XPI package) using Java servlets

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.setHeade开发者_StackOverflowr("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.


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


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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜