简体   繁体   English

如何将 map 所有 http 请求以 /rest/* 形式发送到 RestEasy 中的 @Path 资源

[英]How to map all http requests of the form /rest/* to @Path resource in RestEasy

I am new to RestEasy framework and I am looking for a way to match all my http requests of the form /rest/* to my @Path annotated resource class PassThroughController.我是 RestEasy 框架的新手,我正在寻找一种方法来将我的所有 http 请求与我的 @Path 注释资源 class PassThroughController 匹配。 I could not find similar resources to help me.我找不到类似的资源来帮助我。 May be I am not sure of what and how to search for my requirement.可能是我不确定什么以及如何搜索我的要求。

Here is my application class:这是我的应用程序 class:

@ApplicationPath("rest")
public class PassThroughService extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> clazzes = new HashSet();
        clazzes.add(PassThroughController.class);

        return clazzes;
    }
}

PassThroughController.java直通控制器.java

@Path("/*")
public class PassThroughController
{

    @GET
    public Response all(@Context SecurityContext ctx) {
        Response resp = Response.
                ok("Welcome! "+ ctx.getUserPrincipal().getName()).
                build();

        return resp;
    }
}

When I send a request: http://localhost:8080/{web-context}/rest/userservice/getuserdetails当我发送请求时: http://localhost:8080/{web-context}/rest/userservice/getuserdetails
I get 404 error.我收到 404 错误。 But, I want that any request of the format /rest/* should be intercepted at my PassThroughController class.但是,我希望 /rest/* 格式的任何请求都应该在我的 PassThroughController class 处被拦截。 Once there, I want HTTPServletRequest object so that I can get pathInfo, headers, parametermap and request parameters and call different services using those details.在那里,我想要 HTTPServletRequest object 以便我可以获取路径信息、标头、参数映射和请求参数,并使用这些详细信息调用不同的服务。

So, basically I have two requirements:所以,基本上我有两个要求:

  1. How to call my method?如何调用我的方法?
  2. How to get HTTPServletRequest object once the method is invoked?调用方法后如何获取 HTTPServletRequest object?

You want to use a ContainerRequestFilter .您想使用ContainerRequestFilter You can't have an endpoint itself intercept calls.您不能让端点本身拦截呼叫。 See the JavaDoc for more details.有关更多详细信息,请参阅JavaDoc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM