HTTP Handler and Resteasy Deployment with undertow and resteasy

大兔子大兔子 提交于 2019-12-05 06:31:34

The UndertowJaxrsServer is overriding the filehandler of your builder:

public UndertowJaxrsServer start(Undertow.Builder builder)
{
    server = builder.setHandler(root).build();
    server.start();
    return this;
}

Seems like there is no way to pass another handler to the UndertowJaxrsServer. Possible workarounds might be:

  • Deploy another application with one resource class which simply serves files.
  • Use the blank Undertow and loose the comfort of easy JAX-RS deployments.

From version 3.1.0.Beta2 and higher you can try this

UndertowJaxrsServer server = new UndertowJaxrsServer();

ResteasyDeployment deployment = new ResteasyDeployment();

deployment.setApplicationClass(ExampleApplication.class.getName());

DeploymentInfo deploymentInfo = server.undertowDeployment(deployment, "/");
deploymentInfo.setClassLoader(MyServer.class.getClassLoader());

deploymentInfo.setContextPath("/api");

server.deploy(deploymentInfo);

server.addResourcePrefixPath("/",
        resource(new PathResourceManager(Paths.get(STATIC_PATH),100)).
            addWelcomeFiles("index.html"));

server.start();

RestEasy app will be available at /api/* and static files at /*

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!