java – Restlet Directory – 未提供默认的index.html文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Restlet Directory – 未提供默认的index.html文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2393字,纯文字阅读大概需要4分钟。
内容图文
![java – Restlet Directory – 未提供默认的index.html文件](/upload/InfoBanner/zyjiaocheng/779/a82a0a507fad401783837a794d5ec70f.jpg)
我有:
Directory webdir = new Directory(getContext(), "clap://class/webapp");
webdir.setDeeplyAccessible(true);
router.attach("",webdir);
这在按名称提供目录中的所有文件时有效.
但是,它应该在您访问“/”时提供index.html而不是.我已经尝试过路径,额外路由器等的所有组合,但它仍然无法正常工作.
当您访问“/”时,您将获得200响应和应用程序/八位字节流内容类型.否则响应是空的.目录上的getIndexName确保它是索引
我也试过getMetadataService().addExtension(“html”,MediaType.TEXT_HTML,true);帮助它获取index.html文件,但无济于事,并在请求中设置接受标头为text / html.
ETA:这是同一个(未解决的)问题,如下所述:http://restlet-discuss.1400322.n2.nabble.com/Serving-static-files-using-Directory-and-CLAP-from-a-jar-td7578543.html
有人能帮忙吗?这让我疯了.
经过一番摆弄后,我现在已经有了这个解决方法,但如果可能的话我宁愿不重定向:
Redirector redirector = new Redirector(getContext(), "/index.html", Redirector.MODE_CLIENT_PERMANENT);
TemplateRoute route = router.attach("/",redirector);
route.setMatchingMode(Template.MODE_EQUALS);
解决方法:
该行为是由ClapClientHelper类将目标标识为文件或目录的方式引起的.解决方法是将ClapClientHelper类替换为另一个名为JarClapClientHelper的几乎相同的类.从ClapClientHelper复制源代码并更改handleClassLoader方法中的以下代码段.
// The ClassLoader returns a directory listing in some cases.
// As this listing is partial, it is of little value in the context
// of the CLAP client, so we have to ignore them.
if (url != null) {
if (url.getProtocol().equals("file")) {
File file = new File(url.getFile());
modificationDate = new Date(file.lastModified());
if (file.isDirectory()) {
url = null;
}
//NEW CODE HERE
} else if (url.getProtocol().equals("jar")) {
try {
JarURLConnection conn = (JarURLConnection) url.openConnection();
modificationDate = new Date(conn.getJarEntry().getLastModifiedTime().toMillis());
if (conn.getJarEntry().isDirectory()) {
url = null;
}
} catch (IOException ioe) {
getLogger().log(Level.WARNING,
"Unable to open the representation's input stream",
ioe);
response.setStatus(Status.SERVER_ERROR_INTERNAL);
}
}
}
现在您需要加载此助手而不是默认助手.
(感谢@Thierry Boileau.)
有两种方法,一种不需要任何代码,另一种是程序化的.
第一个是让ServiceLoader找到你的服务:
>将一个名为META-INF / services / org.restlet.engine.ClientHelper的文件添加到您的解决方案中.
>此文件应该有一行文本:助手类的全名(包括包)
第二个是以编程方式添加帮助程序:
Engine.getInstance().getRegisteredClients().add(0, new JarClapClientHelper(null));
内容总结
以上是互联网集市为您收集整理的java – Restlet Directory – 未提供默认的index.html文件全部内容,希望文章能够帮你解决java – Restlet Directory – 未提供默认的index.html文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。