Showing posts with label JPivot. Show all posts
Showing posts with label JPivot. Show all posts

Wednesday, November 24, 2010

Upgrade JPivot 1.8 to Mondrian 3.3.x

Like me, if you are stuck with last (old) release of Jpivot 1.8 with embedded Mondrian version 3.0 and want to upgrade to latest Mondrian (community version) release 3.3.x then, I have a solution. JPivot sourceforge site is not uptodate with the Mondrian ROLAP engine and there are several bugs which have been fixed in latest release of Mondrian.

In my environment (Struts 1.2, JBoss 4.x, Tomcat 5.x) simply replacing the mondrian.jar with latest jar library from Mondrian Sourceforge project does not work. It fails with several ClassNotFoundException and/or NoSuchMethodError during runtime. Here is what I did and it worked fine:

  1. Download latest Mondrian distribution
  2. Expand the dowloaded jar archive
  3. Navigate to WEB-INF/classes in the expanded location
  4. Create jpivot.jar from classes inside WEB-INF/classes directory e.g. using jar command line tool as shown below. Run this command inside WEB-INF/classes directory.
  • jar cvfz jpivot.jar com/*

5. Replace the jpivot.jar inside the expanded mondrian/lib directory with the jpivot.jar created above

6. Copy all the jar files in the lib directory (including new jpivot.jar) to your deployment location. Voila, you have upgraded JPivot 1.8 to the latest mondrian (3.3) release.

Enjoy!

Friday, September 03, 2010

JPivot/Mondrian + Struts 1.x file upload issue

After we integrated JPivot (front-end for Mondrian) library in one of our Struts 1.x based web application, all file uploads working fine so far, started to fail with NullPointerException (NPE). JPivot request filter is configured to intercept all requests for action (e.g. *.do). I could not find direct discussion about this issue on Google.

After debugging for few hours myself, noticed that JPivot RequestFilter intercepts and consumes the HTTP multipart request stream through a MultipartEnabledRequest wrapper even before it reaches Struts controller. Therefore FormFile object is null in FormBean.

The simple solution that worked was to extend the JPivot RequestFilter class and override doFilter(), something like shown below and use this custom filter in place of default JPivot RequestFilter.

...
import com.tonbeller.wcf.controller.RequestFilter;

/**
* This extension modifies default behavior of JPivot controller for file uploads
* (multipart requests) . It allows Struts layer to handle such requests rather
* than processing itself.
*
* @author bjha
*/
public class MyJpivotFilter extends RequestFilter {

@Override
public final void doFilter(
ServletRequest req,
ServletResponse res,
FilterChain fc) throws IOException, ServletException {


if( isMultipartRequest( req ) ){
//let Struts handle upload
fc.doFilter(req, res);
return;
}

super.doFilter(req, res, fc);
}


static boolean isMultipartRequest(ServletRequest req) {

if (req instanceof HttpServletRequest) {

String reqMethod = ((HttpServletRequest) req).getMethod();

if ( reqMethod != null
&&
"post".equals(reqMethod.toLowerCase())) {

String content = req.getContentType();
return (
content != null
&&
content.toLowerCase().contains("multipart/form-data"));
}
}

return false;
}
}


Another option that could work would be to configure JPivot RequestFilter not to intercept requests for upload URIs via web.xml or use commons-fileupload library to handle uploads.