public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance)
throws InterceptionException {
boolean isViewless = method.getMethod().isAnnotationPresent(Viewless.class);
if (!isViewless && info.isAjax()) {
if (!method.getMethod().isAnnotationPresent(Remotable.class)) {
throw new InterceptionException("Unable to make an ajax result in a non-remotable method.");
}
int depth = method.getMethod().getAnnotation(Remotable.class).depth();
JsonOutjecter outjecter = (JsonOutjecter) info.getOutjecter();
CharSequence output = new JSONSerializer(depth).serialize(outjecter.contents());
response.setCharacterEncoding(UTF8);
response.setContentType("application/json");
try {
PrintWriter writer = response.getWriter();
writer.append(output);
writer.flush();
writer.close();
} catch (IOException e) {
throw new InterceptionException(e);
}
} else {
stack.next(method, resourceInstance);
}
}