java - 在 JBoss 7.1.1 上运行 Tapestry 5.3.8
问题描述
在 JBoss 5 到 7.1.1 的迁移过程中,我遇到了多个问题。其中之一是 Tapestry 根本不工作。
此错误的唯一“有用”迹象是,当我尝试访问我的 Web 应用程序(EAR 中捆绑的 WAR)并在浏览器中显示“未找到”时,服务器会响应 404。
即使将每个 LOG4J 输出都转换为 DEBUG,服务器日志也没有提供任何有用的信息。
我尝试升级不同的依赖项,改变战争结构以符合 Tapestry 规范等。
我注意到我的应用程序ClasspathURLConverter
与此处的应用程序相对应:https ://wiki.apache.org/tapestry/HowToRunTapestry5OnJBoss5
但是转换器在 JBoss 7 上无法正常工作
解决方案
这个问题的解决方案确实是在 Tapestry 查找页面、组件等时的错误 URL 翻译(我必须深入挖掘 Tapestry 源代码并一直调试它)。
所以我试图深入研究 VFS 系统和 URL 转换。我找到了 5 个以上的链接,其中包含相同的代码供转换器使用(例如http://www.voidcn.com/article/p-mpuwwlxm-eh.html)。这个实现的问题是如果我的 JAR 直接位于{myEar}/lib/
文件夹中。我修改了代码,但导致路径指向文件系统中已爆炸但为空的 jar。
然后我在这里找到了另一个解决方案:https ://developer.jboss.org/thread/172599 - 更简单且有效。
所以这是最终的解决方案:
AppModule.java:
public static void contributeServiceOverride(MappedConfiguration<Class, Object> configuration) {
configuration.add(ClasspathURLConverter.class, new MyClasspathURLConverterImpl());
}
MyClasspathURLConverterImpl.java:
public URL convert(URL url) {
if (url != null && url.getProtocol().startsWith("vfs")) {
try {
return getRealFilePath(url.getPath());
} catch (Exception e) {
log.error(e.getCause());
}
}
return url;
}
private URL getRealFilePath(String urlString) throws IOException {
VirtualFile vFile = VFS.getChild(urlString);
URL physicalUrl = VFSUtils.getPhysicalURI(vFile).toURL();
String physicalUrlStr = physicalUrl.toString();
if (physicalUrlStr.contains(".jar")) {
int jarIdx = physicalUrlStr.indexOf(".jar");
String part1 = physicalUrlStr.substring(0, jarIdx + 4);
String part2 = physicalUrlStr.substring(jarIdx + 4);
String jarName = part1.substring(part1.lastIndexOf("/") + 1, jarIdx + 4);
String dir = part1 + part2.substring(0, part2.indexOf("/"));
String jarLocation = dir + "/" + jarName;
String packageName = part2.substring(part2.indexOf("/"));
if (packageName.startsWith("/contents")) {
packageName = packageName.substring(9);
}
String result = "jar:" + jarLocation + "!" + packageName;
physicalUrl = new URL(result);
}
return physicalUrl;
}
pom.xml
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
<version>3.2.14.Final</version>
<scope>provided</scope>
</dependency>
推荐阅读
- javascript - (Angular 2/4/5/6) 将 tawk 小部件添加到 Angular 6 中的特定页面
- c++ - 如何在 Qt 中处理用于加密的 MinGM32 位编译器中的 128 位变量(Diffie Hellman 算法)
- firebase-authentication - 来自 HTTPS 可调用 Cloud Functions 的“上下文”是否可信?
- php - 如何为使用 codeigniter 框架构建的门户执行数据库跟踪
- java - 在两个 ArrayList 对象之间创建关系
- reactjs - 返回新组件,但前一个组件在 ReactJs 中保持不变
- cumulocity - 如何安装最新的 1004.x cumulocity UI 包 [ng1]?
- angular - 角度更新后组件加载问题
- python - Python,用于查找和提取相似性的结构。列表。字典还是数据框?
- javascript - 为什么路径在