Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content type for Viewable can be wrong #4446

Closed
michal-trnka opened this issue Apr 21, 2020 · 1 comment
Closed

Content type for Viewable can be wrong #4446

michal-trnka opened this issue Apr 21, 2020 · 1 comment

Comments

@michal-trnka
Copy link

I am using Viewable in ExceptionMapper. I cannot specify the correct content-type as it always gets overridden by */*.

The ExceptionMapper

 public Response toResponse(NotFoundException e) {
        if (headers.getAcceptableMediaTypes().contains(MediaType.TEXT_HTML_TYPE)) {
            return Response
                    .status(Response.Status.NOT_FOUND)
                    .type(MediaType.TEXT_HTML)
                    .entity(new Viewable("/errors/error_404.ftl", new HashMap<String, Object>()))
                    .build();
        }
        return Response.status(Response.Status.NOT_FOUND).entity("Not found").build();
    }

I have dug into the source code and I found that content type defined on the resource is used and if not found, */* is default one. It completely ignores the type set on the Response object.
Link to the place, where */* is set:

@michalhabala
Copy link

I have the exact same issue and really would appreciate a fix or some workaround. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants