Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-534

Missing Content-type in request should not throw exception when injecting InputStream parameter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.2.1
    • None
    • None
    • None

      Lets have such a method:

      @POST
      @Path("/test/

      {type}

      ")
      public Response test(InputStream is, @PathParam("type") final String type) {
      if ("json".equals(type))

      { // read json }

      else if ("binary".equals(type))

      { // read binary }

      // ...

      return Response.ok().build();
      }

      If Content-Type is not set in the request, resteasy throws an exception while injecting input stream as a method parameter:
      org.jboss.resteasy.spi.BadRequestException: content-type was null and expecting to extract a body
      at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:105)
      at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:93)

      However, according to the RFC2616 (see below) if Content-Type is unset it should be treated as application/octet-stream and hence the exception should not be thrown.

      Any HTTP/1.1 message containing an entity-body SHOULD include a
      Content-Type header field defining the media type of that body. If
      and only if the media type is not given by a Content-Type field, the
      recipient MAY attempt to guess the media type via inspection of its
      content and/or the name extension(s) of the URI used to identify the
      resource. If the media type remains unknown, the recipient SHOULD
      treat it as type "application/octet-stream".

      The only workaround is to replace method parameter InputStream with
      @Context HttpServletRequest httpServletRequest
      and then get the input stream with httpServletRequest.getInputStream()

              patriot1burke@gmail.com Bill Burke (Inactive)
              coresystems_pem Martin Petras (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: