jersey
  1. jersey
  2. JERSEY-1511

MessageBodyReader does not set default content-type

    Details

    • Type: Bug Bug
    • Status: Resolved
    • 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

      suppose

      @Path("resource")
      public class Resource {
      	@Context
      	HttpHeaders headers;
      
      	@Path("plain")
      	@POST
      	public String plain(EntityForReader efr) {
      		return efr.toString() + ";"
      				+ headers.getHeaderString(HttpHeaders.CONTENT_TYPE);
      	}
      }
      @Provider
      @Consumes(MediaType.APPLICATION_OCTET_STREAM)
      public class AppOctetReader extends AbstractReader implements MessageBodyReader<EntityForReader> {
      
      	@Override
      	public boolean isReadable(Class<?> type, Type genericType,
      			Annotation[] annotations, MediaType mediaType) {
      		return MediaType.APPLICATION_OCTET_STREAM_TYPE.equals(mediaType);
      	}
      
      	@Override
      	public EntityForReader readFrom(Class<EntityForReader> type,
      			Type genericType, Annotation[] annotations, MediaType mediaType,
      			MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
      			throws IOException, WebApplicationException {
      		return null;
      	}
      
      }
      public class EntityForReader {
      	private String value;
      	public EntityForReader(String value) {
      		this.value = value;
      	}
      	
      	@Override
      	public String toString() {
      		return value;
      	}
      }
      

      AppOctetReader is used as appropriate, but mediaType is null, so isReadable returns false;
      But the Spec. 4.2.1 Message Body Reader, paragraph 1, says:

      Obtain the media type of the request. If the request does not contain a Content-Type header then
      use application/octet-stream.

      Hence, mediaType should be application/octet-stream.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Michal Gajdos
            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 - 3 hours
              3h