public void service(GrizzlyRequest req, GrizzlyResponse res) {
LogHelper.getDefaultLogger().finer("Rest monitoring adapter !");
LogHelper.getDefaultLogger().finer("Received monitoring resource request: " + req.getRequestURI());
String requestURI = req.getRequestURI();
ActionReport report = getClientActionReport(requestURI, req);
try {
if (!latch.await(20L, TimeUnit.SECONDS)) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
String msg = localStrings.getLocalString("rest.adapter.server.wait",
"Server cannot process this command at this time, please wait");
report.setMessage(msg);
reportError(res, report, HttpURLConnection.HTTP_UNAVAILABLE);
return;
} else {
Cookie[] cookies = req.getCookies();
boolean isAdminClient = false;
String uid = RestService.getRestUID();
if (uid != null) {
if (cookies != null) {
for (Cookie cookie: cookies) {
if (cookie.getName().equals("gfrestuid")) {
if (cookie.getValue().equals(uid)) {
isAdminClient = true;
break;
}
}
}
}
}
if (!isAdminClient) { //authenticate all clients except admin client
if (!authenticate(req, report, res)) //admin client - client with valid rest interface uid
return;
}
//delegate to adapter managed by Jersey.
if (adapter == null) {
exposeContext();
}
((GrizzlyAdapter)adapter).service(req, res);
}
} catch(InterruptedException e) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
String msg = localStrings.getLocalString("rest.adapter.server.wait",
"Server cannot process this command at this time, please wait");
report.setMessage(msg);
reportError(res, report, HttpURLConnection.HTTP_UNAVAILABLE); //service unavailable
return;
} catch (Exception e) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
String msg = localStrings.getLocalString("rest.adapter.auth.error",
"Error authenticating");
report.setMessage(msg);
///report.setActionDescription("Authentication error");
///res.setHeader("WWW-Authenticate", "BASIC");
reportError(res, report, HttpURLConnection.HTTP_UNAUTHORIZED); //authentication error
return;
}