Assert.assertNotNull(records, "Parameter [" + RECORDS + "] cannot be null in oder to execute " + this.getActionName() + " service");
// if no records are selected, send a message to the client
if (records.length() == 0) {
try {
writeBackToClient( new JSONFailure(new SpagoBIEngineServiceException(getActionName(), "No records selected!!")) );
return;
} catch (IOException e) {
String message = "Impossible to write back the responce to the client";
throw new SpagoBIEngineServiceException(getActionName(), message, e);
}
}
// if some columns are missing, send a message to the client
List<String> missingColumns = getMissingColumns(serviceConfig, records);
logger.debug("Missing columns : " + join(missingColumns, ","));
if (missingColumns.size() > 0) {
logger.debug("The following columns are required in order to invoke " +
"the required service: " + join(missingColumns, ","));
try {
JSONObject obj = new JSONObject();
obj.put("missingcolumns", join(missingColumns, ","));
writeBackToClient( new JSONSuccess(obj) );
return;
} catch (IOException e) {
String message = "Impossible to write back the responce to the client";
throw new SpagoBIEngineServiceException(getActionName(), message, e);
}
}
// invoke external service
String serviceResponse = null;
try {
extServiceMonitor = MonitorFactory.start("QbeEngine.externalService");
serviceResponse = invokeExternalService(serviceConfig, records);
} finally {
extServiceMonitor.stop();
}
logger.debug("Service has returned this message response:\n" + serviceResponse);
try {
JSONObject obj = new JSONObject();
obj.put("serviceresponse", serviceResponse);
writeBackToClient( new JSONSuccess(obj) );
} catch (IOException e) {
String message = "Impossible to write back the responce to the client";
throw new SpagoBIEngineServiceException(getActionName(), message, e);
}
} catch(Throwable t) {
errorHitsMonitor = MonitorFactory.start("QbeEngine.errorHits");
errorHitsMonitor.stop();