使用 Java servlet 构建 firefox 扩展(XPI 包)
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
单击“添加到 Firefox”后,来自 addons.mozilla.org 的流量嗅探显示,您所需要的只是将 Content-Type 设置为 application/x-xpinstall 和正确的 Content-Length。你也可以尝试一下。以下是标题:
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:
这是一个猜测,但是,由于您返回的是压缩的 .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?
您的第二个响应
Content-Disposition
字段缺少inline
关键字,这可能是一个原因吗?另外,正如 Murali 建议的那样,您应该将
Content-Length
设置为实际值。Your second response
Content-Disposition
field is missing aninline
keyword, may this be a reason?Also as Murali suggested you should set
Content-Length
to an actual value.您应该能够使用 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 theContent-Length
field.Then send the content via
byteArrayStream.writeTo(response.getOutputStream())
.-Bipin