Author: heiko.braun(a)jboss.com
Date: 2009-05-30 13:21:27 -0400 (Sat, 30 May 2009)
New Revision: 4956
Modified:
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtService.java
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/ReportFacade.java
projects/report-server/trunk/report-server.iml
projects/report-server/trunk/server/src/main/webapp/loadffw.html
Log:
Graceful reposne upon init error
Modified:
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtService.java
===================================================================
---
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtService.java 2009-05-30
17:17:47 UTC (rev 4955)
+++
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/BirtService.java 2009-05-30
17:21:27 UTC (rev 4956)
@@ -165,7 +165,7 @@
}
catch (EngineException e)
{
- throw new RuntimeException("Failed to render report", e);
+ throw new RuntimeException("Failed to render report: "+e.getMessage(),
e);
}
return outputFileName;
Modified:
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/ReportFacade.java
===================================================================
---
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/ReportFacade.java 2009-05-30
17:17:47 UTC (rev 4955)
+++
projects/report-server/trunk/core/src/main/java/org/jboss/bpm/report/ReportFacade.java 2009-05-30
17:21:27 UTC (rev 4956)
@@ -54,68 +54,78 @@
@Path("report")
public class ReportFacade
{
- private static final Log log = LogFactory.getLog(ReportFacade.class);
- private BirtService birtService;
- private boolean isInitialized;
+ private static final Log log = LogFactory.getLog(ReportFacade.class);
+ private BirtService birtService;
+ private boolean isInitialized;
- public void lazyInitialize(HttpServletRequest request)
- {
- if(!isInitialized)
- {
- JMXServerConfig jmxConfig = new JMXServerConfig();
- IntegrationConfig iConfig = new IntegrationConfig();
+ public void lazyInitialize(HttpServletRequest request)
+ throws BirtInitException
+ {
+ if(!isInitialized)
+ {
+ JMXServerConfig jmxConfig = new JMXServerConfig();
+ IntegrationConfig iConfig = new IntegrationConfig();
- File severDataDir = jmxConfig.getServerDataDir();
- String absServerDataDir = severDataDir.getAbsolutePath();
+ File severDataDir = jmxConfig.getServerDataDir();
+ String absServerDataDir = severDataDir.getAbsolutePath();
- String birtDataDir = absServerDataDir + "/birt";
- String defaultBirtHome = birtDataDir + "/ReportEngine";
- String birtOutputDir = birtDataDir + "/output";
+ String birtDataDir = absServerDataDir + "/birt";
+ String defaultBirtHome = birtDataDir + "/ReportEngine";
+ String birtOutputDir = birtDataDir + "/output";
- File birtOutput = new File(birtOutputDir);
- birtOutput.mkdirs(); // will create parent directoy as well
+ File birtOutput = new File(birtOutputDir);
+ birtOutput.mkdirs(); // will create parent directoy as well
- // check dependency on ReportEngine
- if(! new File(defaultBirtHome).exists())
- throw new IllegalStateException("The BIRT report engine doesn't seem
to be installed:" +defaultBirtHome);
+ // check dependency on ReportEngine
+ if(! new File(defaultBirtHome).exists())
+ throw new BirtInitException("The BIRT report engine doesn't seem to be
installed:" +defaultBirtHome);
- // --
+ // --
- iConfig.setBirtHome(defaultBirtHome);
- iConfig.setOutputDir( birtOutputDir );
- iConfig.setReportDir( birtDataDir );
+ iConfig.setBirtHome(defaultBirtHome);
+ iConfig.setOutputDir( birtOutputDir );
+ iConfig.setReportDir( birtDataDir );
- StringBuffer sb = new StringBuffer();
- sb.append("http://");
- sb.append(request.getServerName()).append(":");
- sb.append(request.getServerPort());
- sb.append(request.getContextPath());
- sb.append(request.getServletPath());
- sb.append("/report/view/image");
+ StringBuffer sb = new StringBuffer();
+ sb.append("http://");
+ sb.append(request.getServerName()).append(":");
+ sb.append(request.getServerPort());
+ sb.append(request.getContextPath());
+ sb.append(request.getServletPath());
+ sb.append("/report/view/image");
- iConfig.setImageBaseUrl(sb.toString());
+ iConfig.setImageBaseUrl(sb.toString());
- log.info("BIRT home: " +iConfig.getBirtHome());
- log.info("Output dir: " +iConfig.getOutputDir());
- log.info("Report dir: " +iConfig.getReportDir());
+ log.info("BIRT home: " +iConfig.getBirtHome());
+ log.info("Output dir: " +iConfig.getOutputDir());
+ log.info("Report dir: " +iConfig.getReportDir());
- this.birtService = new BirtService(iConfig);
- this.birtService.create();
-
- isInitialized = true;
+ try
+ {
+ this.birtService = new BirtService(iConfig);
+ this.birtService.create();
}
- }
+ catch (Throwable t)
+ {
+ throw new BirtInitException(t.getMessage(), t);
+ }
- @GET
- @Path("view/{fileName}")
- @Produces("text/html")
- public Response viewReportHtml(
- @PathParam("fileName")
- String fileName,
- @Context HttpServletRequest
- request
- )
- {
+ isInitialized = true;
+ }
+ }
+
+ @GET
+ @Path("view/{fileName}")
+ @Produces("text/html")
+ public Response viewReportHtml(
+ @PathParam("fileName")
+ String fileName,
+ @Context HttpServletRequest
+ request
+ )
+ {
+ try
+ {
lazyInitialize(request);
Map queryParams = convertRequestParametersToMap(request);
@@ -125,43 +135,82 @@
renderMeta.setFormat(RenderMetaData.Format.HTML);
renderMeta.setClassloader(Thread.currentThread().getContextClassLoader());
renderMeta.getParameters().putAll(queryParams);
-
+
String outputFileName = birtService.render(renderMeta);
String absoluteFile = birtService.getIntegrationConfig().getOutputDir() +
outputFileName;
log.info("Render " + absoluteFile);
File reportFile = new File(absoluteFile);
return Response.ok(reportFile).type("text/html").build();
- }
+ }
+ catch (BirtInitException e2)
+ {
+ return gracefulException(e2);
+ }
+ catch(Throwable e1)
+ {
+ return gracefulException(e1);
+ }
+ }
- @GET
- @Path("view/image/{fileName}")
- public Response getImage(
- @PathParam("fileName")
- String fileName,
- @Context HttpServletRequest
- request
- )
- {
+ @GET
+ @Path("view/image/{fileName}")
+ public Response getImage(
+ @PathParam("fileName")
+ String fileName,
+ @Context HttpServletRequest
+ request
+ )
+ {
+ try
+ {
lazyInitialize(request);
-
+
String imageDir = birtService.getIntegrationConfig().getImageDirectory();
String absName = imageDir + fileName;
File imageFile = new File(absName);
if(!imageFile.exists())
- throw new IllegalArgumentException("Image " +absName+"
doesn't exist");
+ throw new IllegalArgumentException("Image " +absName+" doesn't
exist");
return Response.ok(imageFile).build();
- }
+ }
+ catch (BirtInitException e)
+ {
+ return gracefulException(e);
+ }
+ }
- static public Map<String, String>
convertRequestParametersToMap(HttpServletRequest request){
- Enumeration<?> initParameters=request.getParameterNames();
- HashMap<String, String> parameterMap = new HashMap<String, String>();
- while (initParameters.hasMoreElements()) {
- String param = (String) initParameters.nextElement();
- String value = request.getParameter(param);
- if (param != null & value != null)
- parameterMap.put(param, value);
- }
- return parameterMap;
- }
+ private Response gracefulException(Throwable e)
+ {
+ log.error(e);
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("Unable to process report:").append("<br/>");
+ sb.append(e.getMessage());
+ return Response.ok(sb.toString()).build();
+ }
+
+ static public Map<String, String>
convertRequestParametersToMap(HttpServletRequest request){
+ Enumeration<?> initParameters=request.getParameterNames();
+ HashMap<String, String> parameterMap = new HashMap<String, String>();
+ while (initParameters.hasMoreElements()) {
+ String param = (String) initParameters.nextElement();
+ String value = request.getParameter(param);
+ if (param != null & value != null)
+ parameterMap.put(param, value);
+ }
+ return parameterMap;
+ }
+
+ public class BirtInitException extends Exception
+ {
+ public BirtInitException(String message)
+ {
+ super(message);
+ }
+
+ public BirtInitException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+ }
}
Modified: projects/report-server/trunk/report-server.iml
===================================================================
--- projects/report-server/trunk/report-server.iml 2009-05-30 17:17:47 UTC (rev 4955)
+++ projects/report-server/trunk/report-server.iml 2009-05-30 17:21:27 UTC (rev 4956)
@@ -139,7 +139,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
javax.servlet:servlet-api:jar:2.4:provided">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar!/"
/>
@@ -148,7 +148,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.eclipse.birt:modelapi:jar:2.3.2:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/birt/modelapi/2.3.2/modelapi-2.3.2.jar!/"
/>
@@ -157,7 +157,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.eclipse.birt:dataadapterapi:jar:2.3.2:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/birt/dataadapterapi/2.3.2/dataadapterapi-2.3.2.jar!/"
/>
@@ -166,7 +166,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.jboss.resteasy:resteasy-jaxrs:jar:1.0.2.GA:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/jboss/resteasy/resteasy-jaxrs/1.0.2.GA/resteasy-jaxrs-1.0.2.GA.jar!/"
/>
@@ -175,7 +175,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.eclipse.birt:chartengineapi:jar:2.3.2:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/birt/chartengineapi/2.3.2/chartengineapi-2.3.2.jar!/"
/>
@@ -184,7 +184,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.eclipse.birt:scriptapi:jar:2.3.2:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/birt/scriptapi/2.3.2/scriptapi-2.3.2.jar!/"
/>
@@ -193,7 +193,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.eclipse.birt:engineapi:jar:2.3.2:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/birt/engineapi/2.3.2/engineapi-2.3.2.jar!/"
/>
@@ -202,7 +202,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep: org.eclipse.birt:dteapi:jar:2.3.2:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/birt/dteapi/2.3.2/dteapi-2.3.2.jar!/"
/>
@@ -211,7 +211,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.eclipse.birt:coreapi:jar:2.3.2:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/birt/coreapi/2.3.2/coreapi-2.3.2.jar!/"
/>
@@ -220,7 +220,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.jboss.resteasy:jaxrs-api:jar:1.0.2.GA:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/jboss/resteasy/jaxrs-api/1.0.2.GA/jaxrs-api-1.0.2.GA.jar!/"
/>
@@ -229,7 +229,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep: org.eclipse.emf:common:jar:2.4.0:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/emf/common/2.4.0/common-2.4.0.jar!/"
/>
@@ -238,7 +238,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep:
org.eclipse.emf:ecore-xmi:jar:2.4.1:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/emf/ecore-xmi/2.4.1/ecore-xmi-2.4.1.jar!/"
/>
@@ -247,7 +247,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep: org.eclipse.emf:ecore:jar:2.4.2:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/org/eclipse/emf/ecore/2.4.2/ecore-2.4.2.jar!/"
/>
@@ -256,7 +256,7 @@
<SOURCES />
</library>
</orderEntry>
- <orderEntry type="module-library">
+ <orderEntry type="module-library" exported="">
<library name="M2 Dep: com.ibm.icu:icu4j:jar:3.8.1:compile">
<CLASSES>
<root
url="jar://$MODULE_DIR$/../../../../../../.m2/repository/com/ibm/icu/icu4j/3.8.1/icu4j-3.8.1.jar!/"
/>
Modified: projects/report-server/trunk/server/src/main/webapp/loadffw.html
===================================================================
--- projects/report-server/trunk/server/src/main/webapp/loadffw.html 2009-05-30 17:17:47
UTC (rev 4955)
+++ projects/report-server/trunk/server/src/main/webapp/loadffw.html 2009-05-30 17:21:27
UTC (rev 4956)
@@ -27,6 +27,8 @@
}
}
+ alert("0:"+document.location.hostname);
+
alert("1:"+params);
</script>
</head>
@@ -40,7 +42,7 @@
if(ffw != "")
{
//document.location.href = ffw;
- alert(ffw);
+ alert("2:"+ffw);
}
</script>
</body>