Tuesday, February 27, 2007

BIRT: Patching Annoying POST Bug in Web Viewer versions prior to 2.2

For users of the BIRT web viewer prior to 2.2, there is an annoying issue if you used an external form page to call reports. If you used a POST method instead of a GET method, the parameters are completely ignored. This issue has since been corrected in the 2.2 M4 and M5 releases of BIRT, but for you folks who still run the older version I have a fix for you.

Some time ago I was asked to look into this as an issue for a client. After digging into the source code, I found what the problem was. While technically speaking, parameters are read the same from the GET and POST methods in the BIRT web viewer, the problem comes when the web viewer makes the SOAP call to the report engine. Parameter values are not retained during a recall of the application because the URL changes, so parameters are not passed back. Below is a patch to the BIRT source tree (2.1.1 stable) that will fix the issue by making patches to the appropriate source files in the BIRT web viewer source.

What this does is create a session parameter called SoapURL, inside of the BirtSoapDispatcher class. It then builds a special URL with all the parameters for all SOAP calls to use the already existing GET handler. It then patches all the JavaScript files to use this new URL instead of the document location.

This is a very simple fix, and storing the parameters in anything more complicated would require more complex modification off the BIRT web viewer source.

To apply this patch, you will need to get the BIRT source code from either CVS or from a archive somewhere. Apply the patch as needed (I used Eclipses DIFF utility to create this patch). Now, external forms will be able to use either GET or POST methods to pass parameters to the BIRT web viewer.



Index: org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/app/AbstractBaseToc.js
===================================================================
RCS file: /cvsroot/birt/source/org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/app/AbstractBaseToc.js,v
retrieving revision 1.6
diff -u -r1.6 AbstractBaseToc.js
--- org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/app/AbstractBaseToc.js 18 Aug 2006 06:00:16 -0000 1.6
+++ org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/app/AbstractBaseToc.js 23 Dec 2006 03:39:46 -0000
@@ -259,7 +259,7 @@
*/
__neh_click_broadcast : function( query, realId )
{
- birtSoapRequest.setURL( document.location );
+ birtSoapRequest.setURL( soapURL );
if( query == '0' )
{
birtSoapRequest.addOperation( Constants.documentId, Constants.Document,
@@ -369,7 +369,7 @@
if( root.query != 1 )
{
root.query = '1';
- birtSoapRequest.setURL( document.location );
+ birtSoapRequest.setURL( soapURL );
birtSoapRequest.addOperation( Constants.documentId, Constants.Document, "GetToc", null );
return true;
}
Index: org.eclipse.birt.report.viewer/birt/webcontent/birt/pages/layout/FramesetFragment.jsp
===================================================================
RCS file: /cvsroot/birt/source/org.eclipse.birt.report.viewer/birt/webcontent/birt/pages/layout/FramesetFragment.jsp,v
retrieving revision 1.11
diff -u -r1.11 FramesetFragment.jsp
--- org.eclipse.birt.report.viewer/birt/webcontent/birt/pages/layout/FramesetFragment.jsp 25 Jul 2006 05:41:14 -0000 1.11
+++ org.eclipse.birt.report.viewer/birt/webcontent/birt/pages/layout/FramesetFragment.jsp 23 Dec 2006 03:39:47 -0000
@@ -35,6 +35,18 @@
<LINK REL="stylesheet" HREF="birt/styles/style.css" TYPE="text/css">
<link href="birt/styles/dialogbase.css" media="screen" rel="stylesheet" type="text/css"/>

+ <script type="text/javascript">
+ var soapURL =
+ <%
+ if (request.getAttribute("SoapURL") != null)
+ {
+ out.print("\"" + request.getAttribute("SoapURL").toString() + "\"");
+ }
+ else {
+ out.print("document.location");
+ } %>;
+ </script>
+
<script src="birt/ajax/utility/Debug.js" type="text/javascript"></script>
<script src="birt/ajax/lib/prototype.js" type="text/javascript"></script>

Index: org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/report/BirtReportDocument.js
===================================================================
RCS file: /cvsroot/birt/source/org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/report/BirtReportDocument.js,v
retrieving revision 1.9
diff -u -r1.9 BirtReportDocument.js
--- org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/report/BirtReportDocument.js 5 Jun 2006 09:27:23 -0000 1.9
+++ org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/report/BirtReportDocument.js 23 Dec 2006 03:39:47 -0000
@@ -69,7 +69,7 @@
}
birtSoapRequest.addOperation( Constants.documentId, Constants.Document,
"CacheParameter", null, birtParameterDialog.__parameter );
- birtSoapRequest.setURL( document.location );
+ birtSoapRequest.setURL( soapURL );
birtEventDispatcher.setFocusId( null ); // Clear out current focusid.
return true;
},
Index: org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/report/AbstractBaseReportDocument.js
===================================================================
RCS file: /cvsroot/birt/source/org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/report/AbstractBaseReportDocument.js,v
retrieving revision 1.1
diff -u -r1.1 AbstractBaseReportDocument.js
--- org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/report/AbstractBaseReportDocument.js 28 Apr 2006 05:26:32 -0000 1.1
+++ org.eclipse.birt.report.viewer/birt/webcontent/birt/ajax/ui/report/AbstractBaseReportDocument.js 23 Dec 2006 03:39:46 -0000
@@ -95,7 +95,7 @@
birtSoapRequest.addOperation( Constants.documentId, Constants.Document,
"ChangeParameter", null, birtParameterDialog.__parameter,
{ name : "svg", value : this.__has_svg_support? "true" : "false" } );
- birtSoapRequest.setURL( document.location );
+ birtSoapRequest.setURL( soapURL );
birtEventDispatcher.setFocusId( null ); // Clear out current focusid.
return true;
},
@@ -106,7 +106,7 @@
__beh_cascadingParameter : function( id, object )
{
birtSoapRequest.addOperation( Constants.documentId, Constants.Document, "GetCascadingParameter", null, object );
- birtSoapRequest.setURL( document.location );
+ birtSoapRequest.setURL( soapURL );
birtEventDispatcher.setFocusId( null ); // Clear out current focusid.
return true;
},
@@ -131,7 +131,7 @@
*/
__beh_getPage : function( id, object )
{
- birtSoapRequest.setURL( document.location );
+ birtSoapRequest.setURL( soapURL );
if ( object )
{
birtSoapRequest.addOperation( Constants.documentId, Constants.Document,
@@ -158,7 +158,7 @@
*/
__beh_export : function( id )
{
- birtSoapRequest.setURL( document.location);
+ birtSoapRequest.setURL( soapURL);
birtSoapRequest.addOperation( "Document", Constants.Document, "QueryExport", null );
return true;
}
Index: org.eclipse.birt.report.viewer/birt/WEB-INF/classes/org/eclipse/birt/report/servlet/BirtSoapMessageDispatcherServlet.java
===================================================================
RCS file: /cvsroot/birt/source/org.eclipse.birt.report.viewer/birt/WEB-INF/classes/org/eclipse/birt/report/servlet/BirtSoapMessageDispatcherServlet.java,v
retrieving revision 1.6
diff -u -r1.6 BirtSoapMessageDispatcherServlet.java
--- org.eclipse.birt.report.viewer/birt/WEB-INF/classes/org/eclipse/birt/report/servlet/BirtSoapMessageDispatcherServlet.java 25 Jul 2006 05:43:33 -0000 1.6
+++ org.eclipse.birt.report.viewer/birt/WEB-INF/classes/org/eclipse/birt/report/servlet/BirtSoapMessageDispatcherServlet.java 23 Dec 2006 03:39:46 -0000
@@ -146,6 +146,17 @@
return;
}

+ java.lang.StringBuilder builder = new java.lang.StringBuilder();
+ for (java.util.Iterator it = request.getParameterMap().keySet().iterator(); it.hasNext();)
+ {
+ String paramName = it.next().toString();
+ String paramValue = request.getParameter(paramName);
+ builder.append("&" + paramName + "=" + paramValue);
+ }
+ String soapURL = request.getRequestURL().toString() + "?" + request.getQueryString() + builder.toString();
+
+ request.setAttribute("SoapURL", soapURL);
+
IContext context = __getContext( request, response );

try

Wednesday, February 21, 2007

BIRT: Annoyance of the WEB.XML File

For those of you who have worked with any of the recent web technologies that have come into fruition in the past 10 years, such as Java and .Net, you will be familiar with a little bastard titled the WEB.XML file. Usually, when I create an application, nice little tools like Visual Studio and Eclipse take care of all the little nasty details and I rarely, if ever, have to handle anything inside of this file. That is not the case with the BIRT Example Web Viewer. I came across a really nasty and annoying issue with it.

The issue, you might wonder, is that if you use the BIRT Web Viewer that is supplied with the BIRT Runtime, which is the recommended installation method from the Eclipse/BIRT homepage, it will completely ignore any setting in the WEB.XML file completely, and instead just go on its merry little way using the default values. So, if your not happy with the location of report documents files in the BIRT Web app, and you are using the viewer supplied by the Runtime package, your SOL. Your stuck with either keeping them in the root of the application, or using the relative path in your report execution. This is a bug, and has already been reported, and verified under Tomcat 4.1, 5.5, with Java 1.4, 1.5, and 1.6, and verified with BIRTs version 2.1.1, 2.1.2, 2.2 M4, and 2.2 M5.

The good news... there is a nifty little workaround, and if your already using the Eclipse BIRT Designer, you don't need to download anything extra, just shuffle around a few files to roll your own BIRT Web Viewer, and you get all the features of the BIRT Web Viewer from the Runtime package, plus the ability to change those settings in the WEB.XML file.

These instructions are demonstrated using the BIRT 2.2 M4 All-In-One package, which has been upgraded to 2.2 M5 using the Eclipse Download Manager. I am also using Apache 5.5, and Java 5 (1.5) for my runtime environment.

  • First, locate the birt.zip file under yourr Eclipse designer, located under the BIRT/WTP Integration package. In my case, it is under: C:\birt2_2M4\eclipse\plugins\org.eclipse.birt.integration.wtp.ui_2.2.0.v20070109\runtime\birt.zip
  • Extract this package to a folder called birt under your Tomcat 5.5 webapps folder. For me, this is located at: C:\Program Files\Apache Software Foundation\apache-tomcat-5.5.20\webapps\birt
  • Now, this should end here, but, there are missing files. All of these missing files, fourtunatly, are located in the BIRT Viewer package. So, file the BIRT viewer package, and copy everything under the "birt" folder to your newly created BIRT web application folder under Tomcat. In my case, I am copying C:\birt2_2M4\eclipse\plugins\org.eclipse.birt.report.viewer_2.2.0.v20070208\birt\* to C:\Program Files\Apache Software Foundation\apache-tomcat-5.5.20\webapps\birt, overwriting any files.
  • Restart Tomcat
  • If everything worked, you should be able to run the BIRT test report. For me, this report is at http://localhost:8080/birt/frameset?__report=test.rptdesign&sample=my+parameter
  • Once this report executes correctly, test to make sure the configuration file changes will work also. Under the /WEB-INF folder, open the WEB.XML file. Look for a section with a tag called BIRT_VIEWER_WORKING_FOLDER. Under this tag, put in the value for the folder you want reports to reside under. In my case, I put in /myReports, for a section that will look like:

    BIRT_VIEWER_WORKING_FOLDER
    /myReports

  • Restart Tomcat, or reload the BIRT application
  • Re-run the test report (it should error out since the test report does not reside in the new report folder)
  • Copy the test*.rptDesign files from to the newly created report folder. Note: this folder gets created by BIRT when the application starts (that is another way you can tell if the configuration is working correctly).
  • Re-run the report. Now it should work.
That's it. A fairly easy workaround.

EclipseCon 2007

For the past few weeks, updates have been few and far between. Reason being, I have been preparing for EclipseCon 2007. So why is that such a time-sink? Well, thats because I am doing not 1, but 2 presentations for EclipseCon!

1: "Building Reports with BIRT": A day long class (thats 10 hours, roughly) with a hands on tutorial of building reports with BIRT. Live demos and exercises are expected.
2: "Dynamic BIRT Reporting": A long talk I will be presenting along with one of the BIRT PMC members, Scott Rosenbaum.

I've had to adjust some of my presentations to accommodate the styles due to some outside pressures, which is kind of a drag since the theme really seems to suit my thought process. I mean with panels that have such clever titles as "What sucks about Eclipse" (I think I might sit in on that one, I have a pretty good list of things that just piss me off about it), I really wanted to give it some personal flare. Of course, I'll still sneak in some of my trademark presentation quirks.

The great thing is, I have tons of research on issues that I came across having gotten deep into BIRT innards that others fear to even think about, so expect some heavily BIRT biased content in the future.

Overall, this should be an exciting experience, and if anyone is signed up, look forward to seeing you there.

Monday, February 12, 2007

Video Games: Scored a Wii, GC version of Zelda is backwards from Wii version, and WTF is wrong with Sony??

So I managed to score a Wii. I will say without a doubt, this is one off the most fun gaming units I have ever played, and that’s based off an initial impression of the included Wii Sports and Zelda game. These things are hard to score in my area, and I had to get one when off on a recent assignment in South Carolina.

One note, the Zelda on the Wii is like an exact mirror of the Gamecube version. Things that are on the right hand side in the Gamecube version of on the left hand side, and vise versa. It kind off threw me off.

In related news, I read this article on Penny Arcade this morning. This is funny since, as of yesterday, I say PS3’s at a local Target, a Gamestop, and a local Walmart-type grocery store no more than 3 miles from my apartment. At the grocery store, the PS3 had dust so thick, it had to have been sitting there for at least a month. These weren’t just display boxes, they were actual, on the shelf units, with big signs reading “We have PS3’s in stock”, just begging to people to buy them. I’m not sure what Sonys thinking with such bold statements, but I’d be curious to see what retailers they are calling to get their info. I’m sure if you call every Bed Bath and Beyond in your area, they too will be out of stock of PS3’s, but I’m pretty sure at least 1 Walmart, Target, or Best Buy will have some in stock.

Thursday, February 01, 2007

C: SysV IPC

I've been spending a lot of time with Java due to my recent job change and the requirements of the software we work with. So it was a refreshing break to get a chance to read this article over at Developerworks about Unix IPC mechanisms. I had written about various IPC mechanisms and concepts previously:

http://digiassn.blogspot.com/2006/07/cc-unix-ipc-shared-memory-example.html
http://digiassn.blogspot.com/2006/01/socket-programming-under-cygwin.html
http://digiassn.blogspot.com/2005/12/fork.html

I always enjoy the IBM DeveloperWorks articles for their brief tutorials and sometimes ongoing series.