使用 Java servlet 构建 firefox 扩展(XPI 包)

发布于 2024-08-10 07:11:45 字数 585 浏览 11 评论 0原文

我正在尝试使用 Java servlet 构建 xpi 文件。 如果我在 servlet 中使用以下代码将 xpi 作为 zip 返回 -

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

上面的代码一切正常。我可以将文件保存到文件系统并安装它。

但是,如果我尝试返回具有以下标头和内容类型的文件 -

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

在客户端,firefox 会识别该文件是 xpi 包并显示“安装”选项。但是,当我尝试安装它时,出现此错误 - “不是有效的安装包 - 207”

有人可以建议我需要使用 setContentType() 和 setHeader() 吗?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

妳是的陽光 2024-08-17 07:11:45

单击“添加到 Firefox”后,来自 addons.mozilla.org 的流量嗅探显示,您所需要的只是将 Content-Type 设置为 application/x-xpinstall 和正确的 Content-Length。你也可以尝试一下。以下是标题:

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

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
临走之时 2024-08-17 07:11:45

这是一个猜测,但是,由于您返回的是压缩的 .xpi,而不是 .xpi,我想您必须使用 application/zip?如果 .xpi 本质上不是压缩的,那么压缩的 .xpi 本身是无效的。不压缩发送怎么样?

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?

那片花海 2024-08-17 07:11:45

您的第二个响应 Content-Disposition 字段缺少 inline 关键字,这可能是一个原因吗?

另外,正如 Murali 建议的那样,您应该将 Content-Length 设置为实际值。

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.

得不到的就毁灭 2024-08-17 07:11:45

您应该能够使用 ByteArrayOutputStream 获取内容长度。

您的 servlet 应该将文档写入 ByteArrayOutputStream,完成后查找其大小,将其放入 Content-Length 字段中。

然后通过 byteArrayStream.writeTo(response.getOutputStream()) 发送内容。

-比平

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文