Thanks Douglas. As I mentioned, it is not possible for me to return a Response. So it sounds like setting the status is impossible?
On Mon, Oct 19, 2020 at 2:32 PM Douglas Patriarche <[email protected]> wrote: > Hi Aditya, > > They way I accomplish what you're trying to do is to return a Response > object, like this: > > return Response.ok(file, mimeType) > .header(HttpHeaders.CONTENT_LENGTH, file.length()) > .header(HttpHeaders.CONTENT_DISPOSITION, > "attachment; filename=" + file.getName()) > .build(); > > If you wanted to respond with something other than a 200 then you could do > so with: > > return Response.status(202).entity(file).type(mimeType).build(); > > I hope this helps. > On Monday, October 19, 2020 at 1:29:32 PM UTC-4 Aditya Prasad wrote: > >> Hi there, >> >> I have a resource file that looks like this: >> >> @Context >> private HttpServletResponse httpServletResponse; >> ... >> public User getUser() { >> // stuff >> return user; >> } >> >> I want to set status code 202. Unfortunately, calling >> httpServletResponse.setStatusCode() doesn't work, because it gets >> overridden. One suggestion I've heard is to call >> httpServletResponse.getOutputStream().close(), but that prevents the >> object from being written. Another suggestion I've heard is >> httpServletResponse.getOutputStream().flushBuffer(), but in that case it >> looks like the content type is being set wrong. My client reports: >> >> org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: >> MessageBodyReader not found for media type=application/octet-stream, >> type=foo.User, genericType=foo.User >> >> Is there any way to set the status and return an object without >> serializing it myself? My code is auto-generated in such a way that I'm >> forced to return User (and not Response). >> >> Thanks, >> Aditya >> > -- > You received this message because you are subscribed to the Google Groups > "dropwizard-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/dropwizard-user/f2e4dc63-fd95-40fb-b437-f8483870c332n%40googlegroups.com > <https://groups.google.com/d/msgid/dropwizard-user/f2e4dc63-fd95-40fb-b437-f8483870c332n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dropwizard-user/CAMx7i473_P1Fm29q02FPW-Ow1ZgRV37r33ZUoD9d1vYBOksEMQ%40mail.gmail.com.
