如何访问原始请求主体从JAX-RS资源方法中,作为java.io.InputStream
或byte[]
我想容器绕过任何MessageBodyReader
特定资源类或方法,但我必须在项目的其他资源,应该使用一些MessageBodyReader
。
我已经试过这一点,但它会调用注册MessageBodyReader
S和无法分配结果InputStream
(有相同的问题byte[]
@POST
public Response post(@Context HttpHeaders headers, InputStream requestBody) {
MediaType contentType = headers.getMediaType();
// ...
}
我也试过,但随后的容器失败,此错误初始化:
SEVERE: The following errors and warnings have been detected with resource and/or provider classes: SEVERE: Missing dependency for method public javax.ws.rs.core.Response SomeResource.post(javax.servlet.http.HttpServletRequest) at parameter at index 0 SEVERE: Method, public javax.ws.rs.core.Response SomeResource.post(javax.servlet.http.HttpServletRequest), annotated with POST of resource, class SomeResource, is not recognized as valid resource method.
@POST
public Response post(@Context HttpServletRequest request) {
String contentType = request.getContentType();
InputStream requestBody = request.getInputStream();
// ...
}
该方法是在一个子资源类,它是从与一个方法创建@Path
在另一资源类注释。
我使用的泽西1.11。