-
Bug
-
Resolution: Done
-
Major
-
None
-
None
-
None
Lets have such a method:
@POST
@Path("/test/
")
public Response test(InputStream is, @PathParam("type") final String type) {
if ("json".equals(type))
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()