result = new Exception("服务端没有提供{" + accept + "}类型的数据返回");
mimeType = MimeType.MIME_OF_ALL;
}
// 向客户端写回结果数据
ResponseWriter responseWriter = responseWriterRegister
.getResponseWriter(mimeType);
if (responseWriter != null) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
//将结果写入缓冲区
responseWriter.writeResult(method, out, result, charset, this.options);
final byte[] bytes = out.toByteArray();
if (bytes.length > 0) {
//将结果写回客户端
response.setCharacterEncoding(charset);
response.setContentType(responseWriter.getMimeType()+";charset="+charset);
response.getOutputStream().write(bytes);
//如果方法打开了缓存声明,则将结果缓存到服务器
if (method.isAnnotationPresent(Cache.class)) {
ResourceCacheManager.getInstance().cacheStaticResource(
RestContextManager.getCurrentRestUri(),
responseWriter.getMimeType(), bytes, request);
}
}
} catch (Need2RedirectException e) {
try {
response.sendRedirect(e.getRedirectUrl());