[ 1678773 ] Java 6 and Webstart + Jasper Reports
[ 1677457 ] JasperReports deployed to jboss
This commit is contained in:
parent
4bba47ce74
commit
f51ccf2c8d
|
|
@ -21,6 +21,7 @@ import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -138,7 +139,7 @@ public class ReportStarter implements ProcessCall {
|
||||||
Hashtable env = new Hashtable();
|
Hashtable env = new Hashtable();
|
||||||
env.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
|
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.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);
|
context = new InitialContext(env);
|
||||||
if (isRequestedonAS(requestURL) && isMD5HomeInterfaceAvailable())
|
if (isRequestedonAS(requestURL) && isMD5HomeInterfaceAvailable())
|
||||||
{
|
{
|
||||||
|
|
@ -183,12 +184,8 @@ public class ReportStarter implements ProcessCall {
|
||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
URL reportURL = new URL(reportLocation);
|
URL reportURL = new URL(reportLocation);
|
||||||
InputStream in = reportURL.openStream();
|
InputStream in = reportURL.openStream();
|
||||||
|
|
||||||
//String[] tmps = reportURL.getFile().split("/");
|
|
||||||
|
|
||||||
//String cleanFile = tmps[tmps.length-1];
|
|
||||||
|
|
||||||
File downloadedFile = new File(localPath);
|
File downloadedFile = new File(localPath);
|
||||||
|
|
||||||
if (downloadedFile.exists())
|
if (downloadedFile.exists())
|
||||||
|
|
@ -197,26 +194,57 @@ public class ReportStarter implements ProcessCall {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOutputStream fout = new FileOutputStream(downloadedFile);
|
FileOutputStream fout = new FileOutputStream(downloadedFile);
|
||||||
|
|
||||||
int c;
|
byte buf[] = new byte[1024];
|
||||||
while ((c = in.read()) != -1)
|
int s = 0;
|
||||||
{
|
long tl = 0;
|
||||||
fout.write(c);
|
|
||||||
}
|
while((s = in.read(buf, 0, 1024)) > 0)
|
||||||
|
fout.write(buf, 0, s);
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
fout.flush();
|
fout.flush();
|
||||||
fout.close();
|
fout.close();
|
||||||
return downloadedFile;
|
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<File> subreports = new ArrayList<File>();
|
||||||
|
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
|
* @author rlemeill
|
||||||
|
|
@ -359,9 +387,20 @@ public class ReportStarter implements ProcessCall {
|
||||||
File reportDir = data.getReportDir();
|
File reportDir = data.getReportDir();
|
||||||
|
|
||||||
if (jasperReport != null) {
|
if (jasperReport != null) {
|
||||||
|
File[] subreports;
|
||||||
|
|
||||||
// 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<subreports.length; i++) {
|
for( int i=0; i<subreports.length; i++) {
|
||||||
JasperData subData = processReport( subreports[i]);
|
JasperData subData = processReport( subreports[i]);
|
||||||
if (subData.getJasperReport()!=null) {
|
if (subData.getJasperReport()!=null) {
|
||||||
|
|
@ -453,7 +492,7 @@ public class ReportStarter implements ProcessCall {
|
||||||
File reportFile = null;
|
File reportFile = null;
|
||||||
|
|
||||||
// Reports deployement on web server Thanks to Alin Vaida
|
// Reports deployement on web server Thanks to Alin Vaida
|
||||||
if (reportPath.startsWith("http://")) {
|
if (reportPath.startsWith("http://") || reportPath.startsWith("https://")) {
|
||||||
reportFile = httpDownloadedReport(reportPath);
|
reportFile = httpDownloadedReport(reportPath);
|
||||||
} else if(reportPath.startsWith("/")) {
|
} else if(reportPath.startsWith("/")) {
|
||||||
reportFile = new File(reportPath);
|
reportFile = new File(reportPath);
|
||||||
|
|
@ -589,25 +628,63 @@ public class ReportStarter implements ProcessCall {
|
||||||
*/
|
*/
|
||||||
private void JWScorrectClassPath()
|
private void JWScorrectClassPath()
|
||||||
{
|
{
|
||||||
try
|
URL jasperreportsAbsoluteURL = Thread.currentThread().getContextClassLoader().getResource("net/sf/jasperreports/engine");
|
||||||
|
String jasperreportsAbsolutePath = "";
|
||||||
|
|
||||||
|
if(jasperreportsAbsoluteURL.toString().startsWith("jar:http:") || jasperreportsAbsoluteURL.toString().startsWith("jar:https:"))
|
||||||
{
|
{
|
||||||
Class jnlpClass = Class.forName("javax.jnlp.BasicService");
|
// Jasper classes are deployed to a webserver (Java Webstart)
|
||||||
URL jasperreportsAbsoluteURL = Thread.currentThread().getContextClassLoader().getResource("net/sf/jasperreports/engine");
|
jasperreportsAbsolutePath = jasperreportsAbsoluteURL.toString().split("!")[0].split("jar:")[1];
|
||||||
URL compiereJasperAbsoluteURL = Thread.currentThread().getContextClassLoader().getResource("org/compiere/utils");
|
|
||||||
String jasperreportsAbsolutePath = jasperreportsAbsoluteURL.toString().split("!")[0].split("file:")[1];
|
// Download the required jasper libraries if they are not already existing
|
||||||
String compiereJasperAbsolutePath = compiereJasperAbsoluteURL.toString().split("!")[0].split("file:")[1];
|
File reqLib = new File(System.getProperty("java.io.tmpdir"), "CompiereJasperReqs.jar");
|
||||||
compiereJasperAbsolutePath = compiereJasperAbsolutePath.replaceAll("%20"," ");
|
if(!reqLib.exists() && !(reqLib.length() > 0))
|
||||||
jasperreportsAbsolutePath = jasperreportsAbsolutePath.replaceAll("%20"," ");
|
{
|
||||||
String newClassPath = jasperreportsAbsolutePath + System.getProperty("path.separator") + compiereJasperAbsolutePath;
|
try{
|
||||||
log.info("JasperReports compilation is probably started from JavaWebStart");
|
URL reqLibURL = new URL(jasperreportsAbsolutePath);
|
||||||
log.info("Classpath is corrected to "+newClassPath);
|
InputStream in = reqLibURL.openStream();
|
||||||
System.setProperty("java.class.path",newClassPath) ;
|
|
||||||
|
|
||||||
|
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
|
* @author rlemeill
|
||||||
* @param reportFile
|
* @param reportFile
|
||||||
|
|
|
||||||
|
|
@ -118,8 +118,13 @@
|
||||||
<unjar src="lib/Adempiere.jar" dest="buildALib" />
|
<unjar src="lib/Adempiere.jar" dest="buildALib" />
|
||||||
<unjar src="lib/patches.jar" dest="buildALib" />
|
<unjar src="lib/patches.jar" dest="buildALib" />
|
||||||
<unjar src="lib/customization.jar" dest="buildALib" />
|
<unjar src="lib/customization.jar" dest="buildALib" />
|
||||||
|
|
||||||
<jar jarfile="lib/Adempiere.jar" index="yes">
|
<jar jarfile="lib/Adempiere.jar" index="yes">
|
||||||
<fileset dir="buildALib" />
|
<fileset dir="buildALib" />
|
||||||
|
<indexjars>
|
||||||
|
<pathelement path="lib/AdempiereCLib.jar"/>
|
||||||
|
<pathelement path="lib/CompiereJasperReqs.jar"/>
|
||||||
|
</indexjars>
|
||||||
<manifest>
|
<manifest>
|
||||||
<attribute name="Specification-Title" value="Adempiere"/>
|
<attribute name="Specification-Title" value="Adempiere"/>
|
||||||
<attribute name="Specification-Version" value="${env.ADEMPIERE_VERSION}"/>
|
<attribute name="Specification-Version" value="${env.ADEMPIERE_VERSION}"/>
|
||||||
|
|
@ -173,9 +178,6 @@
|
||||||
<unjar src="lib/postgresql.jar" dest="buildCLib" />
|
<unjar src="lib/postgresql.jar" dest="buildCLib" />
|
||||||
<!--end vpj-cd e-evolution-->
|
<!--end vpj-cd e-evolution-->
|
||||||
<unjar src="lib/fyracle.jar" dest="buildCLib" />
|
<unjar src="lib/fyracle.jar" dest="buildCLib" />
|
||||||
|
|
||||||
<!-- adding the specific CompiereJasper libs -->
|
|
||||||
<unjar src="lib/CompiereJasperReqs.jar" dest="buildCLib" />
|
|
||||||
|
|
||||||
<unjar src="lib/${ADEMPIERE_APPS_TYPE}.jar" dest="buildCLib" />
|
<unjar src="lib/${ADEMPIERE_APPS_TYPE}.jar" dest="buildCLib" />
|
||||||
|
|
||||||
|
|
@ -271,7 +273,7 @@
|
||||||
<!-- ==================================================== -->
|
<!-- ==================================================== -->
|
||||||
<!-- Setup Lib -->
|
<!-- Setup Lib -->
|
||||||
<!-- ==================================================== -->
|
<!-- ==================================================== -->
|
||||||
<target name="setupLib" depends="setupInit, setupWin, setupNonWin, setupALib, setupCLib, setupSLib, signOtherJars"
|
<target name="setupLib" depends="setupInit, setupWin, setupNonWin, setupCLib, setupSLib, setupALib, signOtherJars"
|
||||||
description="Setup Adempiere Lib directory">
|
description="Setup Adempiere Lib directory">
|
||||||
|
|
||||||
<!-- Filter files Overwrite -->
|
<!-- Filter files Overwrite -->
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue