.entrySet())
{
resp.setHeader(e.getKey(), e.getValue());
}
RestResponse restResponse = null;
if (response.hasError())
{
Throwable e = response.getError();
if (e instanceof RestException)
{
restResponse = ((RestException) e).getResponse();
}
if (restResponse == null)
{
restResponse = RestStatus.responseForError(RestStatus.INTERNAL_SERVER_ERROR, e);
}
}
else
{
restResponse = response.getResponse();
}
resp.setStatus(restResponse.getStatus());
Map<String, String> headers = restResponse.getHeaders();
for (Map.Entry<String, String> e : headers.entrySet())
{
// TODO multi-valued headers
resp.setHeader(e.getKey(), e.getValue());
}
final ByteString entity = restResponse.getEntity();
entity.write(resp.getOutputStream());
resp.getOutputStream().close();
}