簡體   English   中英

如何將 map 所有 http 請求以 /rest/* 形式發送到 RestEasy 中的 @Path 資源

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

我是 RestEasy 框架的新手,我正在尋找一種方法來將我的所有 http 請求與我的 @Path 注釋資源 class PassThroughController 匹配。 我找不到類似的資源來幫助我。 可能是我不確定什么以及如何搜索我的要求。

這是我的應用程序 class:

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

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

        return clazzes;
    }
}

直通控制器.java

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

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

        return resp;
    }
}

當我發送請求時: http://localhost:8080/{web-context}/rest/userservice/getuserdetails
我收到 404 錯誤。 但是,我希望 /rest/* 格式的任何請求都應該在我的 PassThroughController class 處被攔截。 在那里,我想要 HTTPServletRequest object 以便我可以獲取路徑信息、標頭、參數映射和請求參數,並使用這些詳細信息調用不同的服務。

所以,基本上我有兩個要求:

  1. 如何調用我的方法?
  2. 調用方法后如何獲取 HTTPServletRequest object?

您想使用ContainerRequestFilter 您不能讓端點本身攔截呼叫。 有關更多詳細信息,請參閱JavaDoc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM