private void handle(final ServletRequestHandler reqHandler, final HttpServletRequest req, final HttpServletResponse resp) throws IOException
{
JSONAware json = null;
try {
requestHandler.checkClientIPAccess(req.getRemoteHost(), req.getRemoteAddr());
json = reqHandler.handleRequest(req, resp);
if (backendManager.isDebug()) {
backendManager.debug("Response: " + json);
}
} catch (RuntimeMBeanException rme) {
json = requestHandler.handleThrowable(rme.getTargetException());
} catch (Throwable exp) {
json = requestHandler.handleThrowable(exp);
} finally {
final String callback = req.getParameter(ConfigKey.CALLBACK.getKeyValue());
if (callback != null) {
sendResponse(resp, "text/javascript", callback + "(" + json.toJSONString() + ");");
} else {
sendResponse(resp, "application/json", json.toJSONString());
}
}
}