jersey
  1. jersey
  2. JERSEY-1516

An application class cannot extend Response class directly

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0-m09
    • Fix Version/s: 2.0-m13, 2.0
    • Component/s: core
    • Labels:
      None

      Description

      javadoc of Response says:

      An application class can extend this class directly or can use one of the static methods to create an instance using a ResponseBuilder.

      But on a resource method:

      @Path("resource")
      public class Resource {
      	@GET
      	@Path("subresponse")
      	public OkResponse subresponse() {
      		return new OkResponse("subresponse");
      	}
      }
      public class OkResponse extends Response {
      
      	Response r;
      
      	public OkResponse(String entity) {
      		r = Response.ok(entity).build();
      	}
      
      	@Override
      	public Object getEntity() {
      		return r.getEntity();
      	}
      
      	@Override
      	public int getStatus() {
      		return r.getStatus();
      	}
      
      	@Override
      	public MultivaluedMap<String, Object> getMetadata() {
      		return r.getMetadata();
      	}
      
      	@Override
      	public boolean hasEntity() {
      		return r.hasEntity();
      	}
      
      	@Override
      	public Set<String> getAllowedMethods() {
      		return r.getAllowedMethods();
      	}
      
      	@Override
      	public Map<String, NewCookie> getCookies() {
      		return r.getCookies();
      	}
      
      	@Override
      	public Date getDate() {
      		return null;
      	}
      
      	@Override
      	public EntityTag getEntityTag() {
      		return r.getEntityTag();
      	}
      
      	@Override
      	public String getHeaderString(String arg0) {
      		return r.getHeaderString(arg0);
      	}
      
      	@Override
      	public Locale getLanguage() {
      		return r.getLanguage();
      	}
      
      	@Override
      	public Date getLastModified() {
      		return r.getDate();
      	}
      
      	@Override
      	public int getLength() {
      		return r.getLength();
      	}
      
      	@Override
      	public Link getLink(String arg0) {
      		return r.getLink(arg0);
      	}
      
      	@Override
      	public Builder getLinkBuilder(String arg0) {
      		return r.getLinkBuilder(arg0);
      	}
      
      	@Override
      	public Set<Link> getLinks() {
      		return r.getLinks();
      	}
      
      	@Override
      	public URI getLocation() {
      		return r.getLocation();
      	}
      
      	@Override
      	public MediaType getMediaType() {
      		return r.getMediaType();
      	}
      
      	@Override
      	public StatusType getStatusInfo() {
      		return r.getStatusInfo();
      	}
      
      	@Override
      	public boolean hasLink(String arg0) {
      		return r.hasLink(arg0);
      	}
      
      	@Override
      	public boolean bufferEntity() throws MessageProcessingException {
      		return r.bufferEntity();
      	}
      
      	@Override
      	public void close() throws MessageProcessingException {
      		r.close();
      	}
      
      	@Override
      	public <T> T readEntity(Class<T> arg0) throws MessageProcessingException,
      			IllegalStateException {
      		return r.readEntity(arg0);
      	}
      
      	@Override
      	public <T> T readEntity(GenericType<T> arg0)
      			throws MessageProcessingException, IllegalStateException {
      		return r.readEntity(arg0);
      	}
      
      	@Override
      	public <T> T readEntity(Class<T> arg0, Annotation[] arg1)
      			throws MessageProcessingException, IllegalStateException {
      		return r.readEntity(arg0, arg1);
      	}
      
      	@Override
      	public <T> T readEntity(GenericType<T> arg0, Annotation[] arg1)
      			throws MessageProcessingException, IllegalStateException {
      		return r.readEntity(arg0, arg1);
      	}
      
      	@Override
      	public MultivaluedMap<String, String> getStringHeaders() {
      		return r.getStringHeaders();
      	}
      
      }
      

      an IllegalArgumentException is thrown on OutboundJaxrsResponse#unwrap.

        Issue Links

          Activity

          Hide
          jan.supol added a comment -

          Currently, Response.ok(entity).build() creates OutboundJaxrsResponse and it fails on static fail method, calling context.setEntity(response.readEntity(InputStream.class));
          However, this calls OutboundJaxrsResponse#readEntity and where there is

          // TODO implement additional support if entity object is InputStream ?
          throw new IllegalStateException("Not supported on an outbound message");

          So this issue is about implementing TODOs.

          Show
          jan.supol added a comment - Currently, Response.ok(entity).build() creates OutboundJaxrsResponse and it fails on static fail method, calling context.setEntity(response.readEntity(InputStream.class)); However, this calls OutboundJaxrsResponse#readEntity and where there is // TODO implement additional support if entity object is InputStream ? throw new IllegalStateException("Not supported on an outbound message"); So this issue is about implementing TODOs.

            People

            • Assignee:
              Marek Potociar
              Reporter:
              jan.supol
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 3 hours
                3h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour Time Not Required
                1h