injector.getInstance(HttpServletRequest.class).setAttribute(Reply.NO_REPLY_ATTR, Boolean.TRUE);
return;
}
// This is where we take all the builder values and encode them in the response.
Transport transport = injector.getInstance(this.transport);
// Set any headers (we do this first, so we can override any cheekily set headers).
if (!headers.isEmpty()) {
for (Map.Entry<String, String> header : headers.entrySet()) {
response.setHeader(header.getKey(), header.getValue());
}
}
// If the content type was already set, do nothing.
if (response.getContentType() == null) {
// By default we use the content type of the transport.
if (null == contentType) {
response.setContentType(transport.contentType());
} else {
response.setContentType(contentType);
}
}
// Send redirect
if (null != redirectUri) {
response.sendRedirect(redirectUri);
response.setStatus(status); // HACK to override whatever status the redirect sets.
return;
}
// Write out data.
response.setStatus(status);
if (null != templateKey) {
response.getWriter().write(injector.getInstance(Templates.class).render(templateKey, entity));
} else if (null != entity) {
if (entity instanceof InputStream) {
// Stream the response rather than marshalling it through a transport.
InputStream inputStream = (InputStream) entity;
try {
ByteStreams.copy(inputStream, response.getOutputStream());
} finally {
inputStream.close();
}
} else {
// TODO(dhanji): This feels wrong to me. We need a better way to obtain the entity type.
transport.out(response.getOutputStream(), (Class<E>) entity.getClass(), entity);
}
}
}