[GLASSFISH-20591] JAX-RSResponse.status(404) is overwritten by WebContainer Created: 29/May/13  Updated: 19/Sep/14

Status: Open
Project: glassfish
Component/s: jax-rs, web_container
Affects Version/s: 4.0_b89_RC5
Fix Version/s: 4.1

Type: Bug Priority: Major
Reporter: Aslak Knutsen Assignee: Miroslav Fuksa
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to JERSEY-1909 JAX-RSResponse.status(404) is overwri... Resolved

 Description   

Given:

@Path("/conference")
public class ConferenceResource implements Resource {
 
    private static final String BASE_MEDIA_TYPE = "application/vnd.ced+xml";
    private static final String CONFERENCE_MEDIA_TYPE = BASE_MEDIA_TYPE + ";type=conference";
    private static final String SESSION_MEDIA_TYPE = BASE_MEDIA_TYPE + ";type=session";
 
...
 
    @GET
    @Path("/{id}")
    @Produces("application/vnd.ced+xml")
    public Response get(@PathParam("id") String id) {
        Conference conference = repository.get(id);
        if(conference == null) {
            return Response.status(Status.NOT_FOUND).type(CONFERENCE_MEDIA_TYPE).build();
        }
        return Response.ok(
                new ConferenceRepresentation(conference, uriInfo.getAbsolutePathBuilder()))
                .type(CONFERENCE_MEDIA_TYPE).build();
    }
...
}

Expected:

Content-Type: application/vnd.ced+xml; type=conference
[Empty Body]

Result:

When the Resource is not found (http 404 is returned by JAX-RS), the WebContainer takes over and returns Content-Type: text/html and the standard Error page as a body.

wire log

DEBUG [org.apache.http.wire] >> "GET /3998f027-d794-4650-9144-aac9990f26bd/api/conference/b849d477-fb42-4e93-9902-84e0741d1ffb HTTP/1.1[\r][\n]"
DEBUG [org.apache.http.wire] >> "Accept: application/vnd.ced+xml; type=conference[\r][\n]"
DEBUG [org.apache.http.wire] >> "Host: localhost:8080[\r][\n]"
DEBUG [org.apache.http.wire] >> "Connection: Keep-Alive[\r][\n]"
DEBUG [org.apache.http.wire] >> "Accept-Encoding: gzip,deflate[\r][\n]"
DEBUG [org.apache.http.wire] >> "[\r][\n]"
DEBUG [org.apache.http.wire] << "HTTP/1.1 404 Not Found[\r][\n]"
DEBUG [org.apache.http.wire] << "X-Powered-By: Servlet/3.1 JSP/2.3 (GlassFish Server Open Source Edition  4.0  Java/Oracle Corporation/1.7)[\r][\n]"
DEBUG [org.apache.http.wire] << "Server: GlassFish Server Open Source Edition  4.0 [\r][\n]"
DEBUG [org.apache.http.wire] << "Content-Language: [\r][\n]"
DEBUG [org.apache.http.wire] << "Content-Type: text/html[\r][\n]"
DEBUG [org.apache.http.wire] << "Date: Wed, 29 May 2013 23:29:43 GMT[\r][\n]"
DEBUG [org.apache.http.wire] << "Content-Length: 1082[\r][\n]"
DEBUG [org.apache.http.wire] << "[\r][\n]"
DEBUG [org.apache.http.wire] << "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>GlassFish Server Open Source Edition  4.0  - Error report</title><style type="text/css"><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - Not Found</h1><hr/><p><b>type</b> Status report</p><p><b>message</b>Not Found</p><p><b>description</b>The requested resource is not available.</p><hr/><h3>GlassFish Server Open Source Edition  4.0 </h3></body></html>"





Generated at Mon May 25 10:35:59 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.