From f51ccf2c8db09fbd53a9b5fef846f438e1362025 Mon Sep 17 00:00:00 2001 From: deathmeat Date: Mon, 12 Mar 2007 08:09:30 +0000 Subject: [PATCH] [ 1678773 ] Java 6 and Webstart + Jasper Reports [ 1677457 ] JasperReports deployed to jboss --- .../org/compiere/report/ReportStarter.java | 151 +++++++++++++----- install/Adempiere/build.xml | 10 +- 2 files changed, 120 insertions(+), 41 deletions(-) diff --git a/JasperReports/src/org/compiere/report/ReportStarter.java b/JasperReports/src/org/compiere/report/ReportStarter.java index 99566c050e..df1530154c 100644 --- a/JasperReports/src/org/compiere/report/ReportStarter.java +++ b/JasperReports/src/org/compiere/report/ReportStarter.java @@ -21,6 +21,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; @@ -138,7 +139,7 @@ public class ReportStarter implements ProcessCall { Hashtable env = new Hashtable(); env.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); env.put(InitialContext.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); - env.put(InitialContext.PROVIDER_URL, requestURL.getHost() ); + env.put(InitialContext.PROVIDER_URL, requestURL.getHost() + ":" + CConnection.get().getAppsPort()); context = new InitialContext(env); if (isRequestedonAS(requestURL) && isMD5HomeInterfaceAvailable()) { @@ -183,12 +184,8 @@ public class ReportStarter implements ProcessCall { { try{ URL reportURL = new URL(reportLocation); - InputStream in = reportURL.openStream(); - - //String[] tmps = reportURL.getFile().split("/"); - - //String cleanFile = tmps[tmps.length-1]; - + InputStream in = reportURL.openStream(); + File downloadedFile = new File(localPath); if (downloadedFile.exists()) @@ -197,26 +194,57 @@ public class ReportStarter implements ProcessCall { } FileOutputStream fout = new FileOutputStream(downloadedFile); - - int c; - while ((c = in.read()) != -1) - { - fout.write(c); - } + + byte buf[] = new byte[1024]; + int s = 0; + long tl = 0; + + while((s = in.read(buf, 0, 1024)) > 0) + fout.write(buf, 0, s); + in.close(); fout.flush(); fout.close(); return downloadedFile; + } catch (FileNotFoundException e) { + if(reportLocation.indexOf("Subreport") == -1) // Only show the warning if it is not a subreport + log.warning("404 not found: Report cannot be found on server "+ e.getMessage()); + return null; + } catch (IOException e) { + log.severe("I/O error when trying to download (sub)report from server "+ e.getMessage()); + return null; } - catch (FileNotFoundException e) { - log.severe("404 not found: Report cannot be found on server "+ e.getMessage()); - return null; - } - catch (IOException e) { - log.severe("IO error when trying to download report from server "+ e.getMessage()); - return null; - } } + + /** + * Search for additional subreports deployed to a webcontext if + * the parent report is located there + * @author deathmeat + * @param reportName The original reportname + * @param reportPath The full path to the parent report + * @param fileExtension The file extension of the parent report + * @return An Array of File objects referencing to the downloaded subreports + */ + private File[] getHttpSubreports(String reportName, String reportPath, String fileExtension) + { + ArrayList subreports = new ArrayList(); + String remoteDir = reportPath.substring(0, reportPath.lastIndexOf("/")); + + // Currently check hardcoded for max. 10 subreports + for(int i=1; i<10; i++) + { + // Check if subreport number i exists + File subreport = httpDownloadedReport(remoteDir + "/" + reportName + i + fileExtension); + if(subreport == null) // Subreport doesn't exist, abort further approaches + break; + + subreports.add(subreport); + } + + File[] subreportsTemp = new File[0]; + subreportsTemp = subreports.toArray(subreportsTemp); + return subreportsTemp; + } /** * @author rlemeill @@ -359,9 +387,20 @@ public class ReportStarter implements ProcessCall { File reportDir = data.getReportDir(); if (jasperReport != null) { - + File[] subreports; + // Subreports - File[] subreports = reportDir.listFiles( new FileFilter( jasperName+"Subreport", reportDir, fileExtension)); + if(reportPath.startsWith("http://") || reportPath.startsWith("https://")) + { + // Locate and download subreports from remote webcontext + subreports = getHttpSubreports(jasperName + "Subreport", reportPath, fileExtension); + } + else + { + // Locate subreports from local/remote filesystem + subreports = reportDir.listFiles( new FileFilter( jasperName+"Subreport", reportDir, fileExtension)); + } + for( int i=0; i 0)) + { + try{ + URL reqLibURL = new URL(jasperreportsAbsolutePath); + InputStream in = reqLibURL.openStream(); + FileOutputStream fout = new FileOutputStream(reqLib); + + byte buf[] = new byte[1024]; + int s = 0; + long tl = 0; + + while((s = in.read(buf, 0, 1024)) > 0) + fout.write(buf, 0, s); + + in.close(); + fout.flush(); + fout.close(); + } catch (FileNotFoundException e) { + log.warning("Required library not found "+ e.getMessage()); + reqLib.delete(); + reqLib = null; + } catch (IOException e) { + log.severe("I/O error downloading required library from server "+ e.getMessage()); + reqLib.delete(); + reqLib = null; + } + } + + jasperreportsAbsolutePath = reqLib.getAbsolutePath(); } - catch (ClassNotFoundException e) + else { + // Jasper classes are locally available (Local client) + jasperreportsAbsolutePath = jasperreportsAbsoluteURL.toString().split("!")[0].split("file:")[1]; + } + + if(jasperreportsAbsolutePath != null && !jasperreportsAbsolutePath.trim().equals("")) + { + System.setProperty("java.class.path", + System.getProperty("java.class.path") + + System.getProperty("path.separator") + + jasperreportsAbsolutePath); + log.info("Classpath has been corrected to " + System.getProperty("java.class.path")); } } + /** * @author rlemeill * @param reportFile diff --git a/install/Adempiere/build.xml b/install/Adempiere/build.xml index 174a73877c..8b14c5cc99 100644 --- a/install/Adempiere/build.xml +++ b/install/Adempiere/build.xml @@ -118,8 +118,13 @@ + + + + + @@ -173,9 +178,6 @@ - - - @@ -271,7 +273,7 @@ -