首页 文章

Wildfly Swarm RESTeasy隐藏了webapp / index.html

提问于
浏览
1

我正在开发一个基于Wildfly Swarm的项目 . 我目前遇到的问题是RESTeasy隐藏了我的index.html(以及其他html文件),这些文件放在/ webapp下面,因为RESTeasy正在监听根级别 .

我的主要应用:

@ApplicationPath("/")
public class XYZnlineApplication extends Application {
}

我的一个资源:

@Path("protected/api/admin")
public class AdminResource {
    @GET
    @Path("public/api/offer/reduced")
    @Produces("application/json")
    public List<XYZ> getXYZ() {
        ...
    }

    @GET
    @Path("protected/api/offer/full")
    @Produces("application/json")
    public List<XYZ> getAllXYZ() {
        ...
    }
}

事情是 . 如果我启动我的wildfly swarm app并访问上面的一个转发点,一切正常(例如http://localhost:8080/app/public/api/offer/reduced

但是,如果我想访问我的一个直接位于/ webapp下面的html(例如login.html)文件,我会得到一个404虽然该文件已正确捆绑(例如,试图访问http://localhost:8080/app/login.html) . 所以在我看来,RESTeasy会隐藏这个html文件,因为它会监听root(/) .

由于我的url的第一部分是上下文(由代理注入),因此我无法在我的XYZApplication中将根目录(/)设置为ApplicationPath .

你对我如何解决这个问题有任何想法吗?

非常感谢您的帮助 .

1 回答

  • 0

    您需要将ApplicationPath更改为“/ services”或“/ svc”或适用于您的任何内容 . 最终,您需要在静态资源和服务之间对URL命名空间进行分区 . 指定ApplicationPath时无需担心上下文 .

    Major Edit:
    您的评论确实解释了's going on. I'我不确定您正在使用的安全类型,但最终您可能需要在服务前面安装某种类型的过滤器 . 我会有类似的东西:

    @Provider
    @Priority(Priorities.AUTHENTICATION)
    @PreMatching
    public class AuthFilter implements ContainerRequestFilter {
        @Context
        private HttpServletRequest httpServletRequest;
    
        @Context
        private HttpServletResponse httpServletResponse;
    
        @Override
        public void filter(ContainerRequestContext containerRequestContext) throws IOException  {
            if( containerRequestContext.getUriInfo().getPath().contains("/public/") )
                return; // user is in public area - doesn't matter if they are authenticated
    
            // guess at how to check if user is authenticated
            if( httpServletRequest.getSession().get("user_is_ok") )
                return;
    
            httpServletResponse.sendRedirect("/login");
            // or maybe
            httpServletResponse.sendError(SC_UNAUTHORIZED);   
        }
    }
    

    同样,这是一个猜测,但这是处理挑战的一种非常常见的方式 .

相关问题