Java Wildfly Swarm RESTeasy隐藏webapp/index.html
我正在从事一个基于Wildfly Swarm的项目。我目前的问题是RESTeasy隐藏了index.html(以及其他html文件),这些文件位于/webapp下面,因为RESTeasy正在根级别上侦听 我的主要申请:Java Wildfly Swarm RESTeasy隐藏webapp/index.html,java,rest,jboss,resteasy,wildfly-swarm,Java,Rest,Jboss,Resteasy,Wildfly Swarm,我正在从事一个基于Wildfly Swarm的项目。我目前的问题是RESTeasy隐藏了index.html(以及其他html文件),这些文件位于/webapp下面,因为RESTeasy正在根级别上侦听 我的主要申请: @ApplicationPath("/") public class XYZnlineApplication extends Application { } 我的资源之一: @Path("protected/api/admin") public class AdminResou
@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() {
...
}
}
@Path(“受保护的/api/admin”)
公共类管理员资源{
@得到
@路径(“公共/api/提供/减少”)
@生成(“应用程序/json”)
公共列表getXYZ(){
...
}
@得到
@路径(“受保护/api/提供/完整”)
@生成(“应用程序/json”)
公共列表getAllXYZ(){
...
}
}
事情是这样的。如果我启动我的wildfly swarm应用程序并访问上面的一个restendpoint,一切正常(例如)
但是,如果我想访问/webapp正下方的某个html(例如login.html)文件,我会得到404,尽管该文件捆绑正确(例如尝试访问)。所以在我看来,RESTeasy隐藏了这个html文件,因为它监听根(/)
由于url的第一部分是上下文(由代理注入),因此在XYZApplication中,除了root(/)之外,我不能将任何内容设置为ApplicationPath
你知道我怎样才能解决这个问题吗
非常感谢您的帮助。您需要将应用程序路径更改为类似于“/services”或“/svc”或任何适合您的内容。最终,您需要在静态资源和服务之间划分URL名称空间。在指定ApplicationPath时,您不需要担心上下文 主要编辑:
你的评论真的解释了发生的事情。我不确定您使用的是哪种类型的安全性,但最终您可能需要在您的服务前面安装某种过滤器。我想要的是:
@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);
}
}
同样,这是一种猜测,但这是处理挑战的一种非常常见的方法。您需要将应用程序路径更改为类似“/services”或“/svc”或任何适合您的方式。最终,您需要在静态资源和服务之间划分URL名称空间。在指定ApplicationPath时,您不需要担心上下文 主要编辑:
你的评论真的解释了发生的事情。我不确定您使用的是哪种类型的安全性,但最终您可能需要在您的服务前面安装某种过滤器。我想要的是:
@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);
}
}
同样,这是一种猜测,但这是处理挑战的一种非常常见的方法。如果您无法设置不同的应用程序路径,这确实会让您感到困难。你能用一个简单的项目提出一个问题吗?我们可以看一下,如果你不能设置不同的应用程序路径,这确实会使它变得困难。你能用一个简单的项目提出一个问题吗?我们可以看一下,非常感谢你的想法。重要的是,对于我们的应用程序来说,在ApplicationPath之前有上下文是很重要的。因此,我们可以设置一个应用程序路径,如/api。但是在swarm上下文(即“app”)和ApplicationPath(“api”)之间,我们需要一个子上下文,它通过添加“public”或“protected”来告知代理是否对用户进行了身份验证,具体取决于用户所在的区域。你对我们如何做到这一点有什么想法吗?非常感谢你的想法。重要的是,对于我们的应用程序来说,在ApplicationPath之前有上下文是很重要的。因此,我们可以设置一个应用程序路径,如/api。但是在swarm上下文(即“app”)和ApplicationPath(“api”)之间,我们需要一个子上下文,它通过添加“public”或“protected”来告知代理是否对用户进行了身份验证,具体取决于用户所在的区域。你知道我们怎样才能做到这一点吗?