在 UndertowJaxrsServer 中提供静态内容 [英] Serving static content in UndertowJaxrsServer
本文介绍了在 UndertowJaxrsServer 中提供静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过具有 RestEasy 部署的 Undertow 服务器中的 ResourceHandler
提供静态内容.
I'm trying to serve static content through a ResourceHandler
in my Undertow server that has a RestEasy deployment.
public class Server {
public static void main(String[] args) throws Exception {
UndertowJaxrsServer server = new UndertowJaxrsServer();
Undertow.Builder serverBuilder = Undertow
.builder()
.addHttpListener(8080, "0.0.0.0")
.setHandler(
Handlers.path().addPrefixPath(
"/web",
new ResourceHandler(new PathResourceManager(Paths.get("/some/fixed/path"),100))
.setDirectoryListingEnabled(true)
.addWelcomeFiles("index.html")));
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setApplicationClass(MyRestApplication.class.getName());
DeploymentInfo deploymentInfo = server.undertowDeployment(deployment, "/")
.setClassLoader(Server.class.getClassLoader())
.setContextPath("/api").setDeploymentName("WS");
server.deploy(deploymentInfo);
server.start(serverBuilder);
}
}
使用上面的代码,只有 resteasy 部署有效,我得到了静态内容 (index.html) 的 404.
With the above code, only the resteasy deployment works and I get a 404 for the static content (index.html).
有什么指点吗?谢谢!
推荐答案
这是我的一个玩具项目:
This is from one of my toy projects:
public static void main(String[] args) {
UndertowJaxrsServer server = new UndertowJaxrsServer();
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setApplicationClass(RestEasyConfig.class.getName());
deployment.setInjectorFactoryClass(CdiInjectorFactory.class.getName());
DeploymentInfo deploymentInfo = server.undertowDeployment(deployment)
.setClassLoader(GatewayApi.class.getClassLoader())
.setContextPath("/api")
.addFilter(new FilterInfo("TokenFilter", TokenFilter.class))
.addFilterUrlMapping("TokenFilter", "/*", DispatcherType.REQUEST)
.addFilterUrlMapping("TokenFilter", "/*", DispatcherType.FORWARD)
.addListener(Servlets.listener(Listener.class))
.setDeploymentName("Undertow RestEasy Weld");
server.deploy(deploymentInfo);
server.addResourcePrefixPath("/index.htm", resource(new ClassPathResourceManager(GatewayApi.class.getClassLoader()))
.addWelcomeFiles("webapp/index.htm"));
Undertow.Builder undertowBuilder = Undertow.builder()
.addHttpListener(8080, "0.0.0.0");
server.start(undertowBuilder);
log.info(generateLogo());
}
这篇关于在 UndertowJaxrsServer 中提供静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文