}
@Override
@SuppressWarnings({ "PMD.AvoidCatchingThrowable", "PMD.AvoidInstanceofChecksInCatchClause" })
public void handle(HttpExchange pExchange) throws IOException {
JSONAware json = null;
URI uri = pExchange.getRequestURI();
ParsedUri parsedUri = new ParsedUri(uri,context);
try {
// Check access policy
InetSocketAddress address = pExchange.getRemoteAddress();
requestHandler.checkClientIPAccess(address.getHostName(),address.getAddress().getHostAddress());
String method = pExchange.getRequestMethod();
// Dispatch for the proper HTTP request method
if ("GET".equalsIgnoreCase(method)) {
json = executeGetRequest(parsedUri);
} else if ("POST".equalsIgnoreCase(method)) {
json = executePostRequest(pExchange, parsedUri);
} else {
throw new IllegalArgumentException("HTTP Method " + method + " is not supported.");
}
if (backendManager.isDebug()) {
backendManager.info("Response: " + json);
}
} catch (Throwable exp) {
JSONObject error = requestHandler.handleThrowable(
exp instanceof RuntimeMBeanException ? ((RuntimeMBeanException) exp).getTargetException() : exp);
json = error;
} finally {
sendResponse(pExchange,parsedUri, json.toJSONString());
}
}