简体   繁体   中英

Wildfly Swarm RESTeasy hides webapp/index.html

I am working on a project based on Wildfly Swarm. The problem I currently have is that RESTeasy hides my index.html (and other html files) which are placed below /webapp since RESTeasy is listening on root level.

My Main Application:

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

One of my resources:

@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() {
        ...
    }
}

The thing is. If I start my wildfly swarm app and access one of the restendpoint above, everything works fine (eg http://localhost:8080/app/public/api/offer/reduced )

But if I d'like to access one of my html (eg login.html) files which are directly below /webapp, I get a 404 although the file is bundled correctly (eg on trying to access http://localhost:8080/app/login.html ). So in my opinion what happens is that RESTeasy hides this html file cause it listens on root (/).

Since the first part of my url is the context (which is injected by a proxy) I can't set anything else than root (/) as ApplicationPath in my XYZApplication.

Do you have any idea on how I could solve this issue?

Thanks a lot in advance for your help.

You'll need to change the ApplicationPath to be something like "/services" or "/svc" or whatever works for you. Ultimately you need to partition the URL namespace between static resources and services. You don't need to worry about the context when specifying the ApplicationPath.


Your comment really explains what's going on. I'm not sure what type of security you're using exactly but ultimately you likely need to have a filter of some sort in front of your services. I would have something like:

@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);   
    }
}

Again, this is a bit of a guess but this is a pretty common way of handling your challenge.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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