使用 undertow 和 resteasy 进行 HTTP 处理程序和 Resteasy 部署 [英] HTTP Handler and Resteasy Deployment with undertow and resteasy
本文介绍了使用 undertow 和 resteasy 进行 HTTP 处理程序和 Resteasy 部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试同时运行 HTTPServer 和 REST 处理程序.一次只能工作一个,不能同时工作.我需要提供 html 页面和 api.
I am trying to run both HTTPServer and also the REST Handler. Only one works at a time not able to make it work both at same time. I need to serve html pages and also the api.
这是我的代码.
public class HttpServer {
private final UndertowJaxrsServer server = new UndertowJaxrsServer();
private static String rootPath = System.getProperty("user.dir");
private final Undertow.Builder serverBuilder;
public HttpServer(Integer port, String host) {
serverBuilder = Undertow
.builder()
.addHttpListener(port, host)
.setHandler(
Handlers.path().addPrefixPath(
"/",
Handlers.resource(
new FileResourceManager(new File(
rootPath + "/web"), 100))
.addWelcomeFiles(
rootPath + "/web/index.html")));
server.start(serverBuilder);
}
public DeploymentInfo deployApplication(String appPath,
Class<? extends Application> applicationClass) {
ResteasyDeployment deployment = new ResteasyDeployment();
deployment.setApplicationClass(applicationClass.getName());
return server.undertowDeployment(deployment, appPath);
}
public void deploy(DeploymentInfo deploymentInfo) throws ServletException {
server.deploy(deploymentInfo);
}
public static void main(String[] args) throws ServletException {
HttpServer myServer = new HttpServer(8080, "0.0.0.0");
DeploymentInfo di = myServer
.deployApplication("/rest", MyApplication.class)
.setClassLoader(HttpServer.class.getClassLoader())
.setContextPath("/my").setDeploymentName("My Application");
myServer.deploy(di);
}
}
推荐答案
UndertowJaxrsServer 正在覆盖您的构建器的文件处理程序:
The UndertowJaxrsServer is overriding the filehandler of your builder:
public UndertowJaxrsServer start(Undertow.Builder builder)
{
server = builder.setHandler(root).build();
server.start();
return this;
}
似乎无法将另一个处理程序传递给 UndertowJaxrsServer.可能的解决方法可能是:
Seems like there is no way to pass another handler to the UndertowJaxrsServer. Possible workarounds might be:
- 使用一个仅提供文件的资源类部署另一个应用程序.
- 使用空白的 Undertow,摆脱简单的 JAX-RS 部署带来的舒适感.
这篇关于使用 undertow 和 resteasy 进行 HTTP 处理程序和 Resteasy 部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文