byte[] response = new byte[0];
try {
if (biObject == null)
return response;
// get the engine of the biobject
Engine eng = biObject.getEngine();
// if engine is not an external it's not possible to call it using
// url
if (!EngineUtilities.isExternal(eng))
if(eng.getClassName().equals("it.eng.spagobi.engines.kpi.SpagoBIKpiInternalEngine")){
SourceBean request = null;
SourceBean resp = null;
EMFErrorHandler errorHandler = null;
try {
request = new SourceBean("");
resp = new SourceBean("");
} catch (SourceBeanException e1) {
e1.printStackTrace();
}
RequestContainer reqContainer = new RequestContainer();
ResponseContainer resContainer = new ResponseContainer();
reqContainer.setServiceRequest(request);
resContainer.setServiceResponse(resp);
DefaultRequestContext defaultRequestContext = new DefaultRequestContext(
reqContainer, resContainer);
resContainer.setErrorHandler(new EMFErrorHandler());
RequestContainer.setRequestContainer(reqContainer);
ResponseContainer.setResponseContainer(resContainer);
Locale locale = new Locale("it","IT","");
SessionContainer session = new SessionContainer(true);
reqContainer.setSessionContainer(session);
SessionContainer permSession = session.getPermanentContainer();
//IEngUserProfile profile = new AnonymousCMSUserProfile();
permSession.setAttribute(IEngUserProfile.ENG_USER_PROFILE, profile);
errorHandler = defaultRequestContext.getErrorHandler();
String className = eng.getClassName();
logger.debug("Try instantiating class " + className
+ " for internal engine " + eng.getName() + "...");
InternalEngineIFace internalEngine = null;
// tries to instantiate the class for the internal engine
try {
if (className == null && className.trim().equals(""))
throw new ClassNotFoundException();
internalEngine = (InternalEngineIFace) Class.forName(className).newInstance();
} catch (ClassNotFoundException cnfe) {
logger.error("The class ['" + className
+ "'] for internal engine " + eng.getName()
+ " was not found.", cnfe);
Vector params = new Vector();
params.add(className);
params.add(eng.getName());
errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR,
2001, params));
return response;
} catch (Exception e) {
logger.error("Error while instantiating class " + className, e);
errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR,
100));
return response;
}
try {
reqContainer.setAttribute("scheduledExecution", "true");
internalEngine.execute(reqContainer, biObject, resp);
} catch (EMFUserError e) {
logger.error("Error during engine execution", e);
errorHandler.addError(e);
} catch (Exception e) {
logger.error("Error while engine execution", e);
errorHandler.addError(new EMFUserError(EMFErrorSeverity.ERROR,
100));
}
return response;
}
else if(eng.getClassName().equals("it.eng.spagobi.engines.chart.SpagoBIChartInternalEngine")){
SourceBean request = null;
EMFErrorHandler errorHandler = null;
try {
request = new SourceBean("");
} catch (SourceBeanException e1) {
e1.printStackTrace();
}
RequestContainer reqContainer = new RequestContainer();
SpagoBIChartInternalEngine sbcie=new SpagoBIChartInternalEngine();
// Call chart engine
File file=sbcie.executeChartCode(reqContainer, biObject, null, profile);
// read input from file
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
if (length > Integer.MAX_VALUE) {
logger.error("file too large");
return null;
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
logger.warn("Could not read all the file");
}
// Close the input stream and return bytes
is.close();
return bytes;
} // end chart case
else{
return response;
}
// get driver class
String driverClassName = eng.getDriverName();
// build an instance of the driver
IEngineDriver aEngineDriver = (IEngineDriver) Class.forName(driverClassName).newInstance();
// get the map of parameter to send to the engine