}else{
maptmpfile = geoInstance.renderMap( outputFormat );
}
} catch (Throwable t) {
throw new DrawMapServiceException(getActionName(), "Impossible to render map", t);
}
responseFileName = "map.svg";
IStreamEncoder encoder = null;
File tmpFile = null;
if(outputFormat.equalsIgnoreCase(GeoEngineConstants.JPEG)) {
encoder = new SVGMapConverter();
responseFileName = "map.jpeg";
}else if(outputFormat.equalsIgnoreCase(GeoEngineConstants.PDF)){
encoder = new SVGMapConverter();
BufferedInputStream bis = null;
String dirS = System.getProperty("java.io.tmpdir");
File imageFile = null;
bis = new BufferedInputStream( new FileInputStream(maptmpfile) );
try {
int contentLength = 0;
int b = -1;
String contentFileName = "tempJPEGExport";
freezeHttpResponse();
File dir = new File(dirS);
imageFile = File.createTempFile("tempJPEGExport", ".jpeg" , dir);
FileOutputStream stream = new FileOutputStream(imageFile);
encoder.encode(bis,stream);
stream.flush();
stream.close();
File dirF = new File(dirS);
tmpFile = File.createTempFile("tempPDFExport", ".pdf", dirF);
Document pdfDocument = new Document();
PdfWriter docWriter = PdfWriter.getInstance(pdfDocument, new FileOutputStream(tmpFile));
pdfDocument.open();
Image jpg = Image.getInstance(imageFile.getPath());
jpg.setRotation(new Double(Math.PI/2).floatValue());
jpg.scaleAbsolute(770, 520);
pdfDocument.add(jpg);
pdfDocument.close();
docWriter.close();
maptmpfile = tmpFile;
} finally {
bis.close();
if(imageFile!=null)imageFile.delete();
}
responseFileName = "map.pdf";
encoder = null;
}
try {
flushingResponseTotalTimeMonitor = MonitorFactory.start("GeoEngine.drawMapAction.flushResponse.totalTime");
writeBackToClient(maptmpfile, encoder, inlineResponse, responseFileName, getContentType(outputFormat));
} catch(IOException e) {
logger.error("error while flushing output", e);
if(getAuditServiceProxy() != null) getAuditServiceProxy().notifyServiceErrorEvent( "Error while flushing output" );
throw new DrawMapServiceException(getActionName(), "Error while flushing output", e);
}
if(getAuditServiceProxy() != null) getAuditServiceProxy().notifyServiceEndEvent( );
maptmpfile.delete();
if(tmpFile!=null)tmpFile.delete();
} catch (Throwable t) {
errorHitsMonitor = MonitorFactory.start("GeoEngine.errorHits");
errorHitsMonitor.stop();
DrawMapServiceException wrappedException;
if(t instanceof DrawMapServiceException) {
wrappedException = (DrawMapServiceException)t;
} else {
wrappedException = new DrawMapServiceException(getActionName(), "An unpredicted error occurred while executing " + getActionName() + " service", t);
}
wrappedException.setDescription(wrappedException.getRootCause());
Throwable rootException = wrappedException.getRootException();
if(rootException instanceof SpagoBIEngineRuntimeException) {
wrappedException.setHints( ((SpagoBIEngineRuntimeException)rootException).getHints() );
}
throw wrappedException;
} finally {
if(flushingResponseTotalTimeMonitor != null) flushingResponseTotalTimeMonitor.stop();