Oops Null Pointer

Java programming related

Monthly Archives: November 2011

Upgrade GWT 2.0.4 to GWT 2.4.0 with GXT 2.2.5

I just upgraded from GWT 2.0.4 to GWT to 2.4.0 and here are the jars I had to change:

Run time dependencies (WEB_INF/lib):

  • updated gwt-servlet.jar to 2.4.0 version
  • updated GXT.jar (2.2.5) had to be a version compiled for GWT 2.2 and above (previous I used the 2 version)
  • updated gwt-log-26.2 to gwt-log-3.1.6.jar
  • updated guice-2.0.jar to guice-3.0.jar
  • added guice-assistedinject-3.0.jar
  • removed gwt-java-math-1.0.9.jar (andremoved the reference from the module (gwt.xml) file
Build time dependencies:
  • updated all the GWT jars
  • updated gin-1.0.jar to gin-1.5.jar (post GWT 2.2 version)
  • added javax.inject.jar that comes with guice-3.0 (new)

Struts2 file upload max size error

A few lessons I learned from getting the Struts2 file upload feature to handle files larger that 2MB:

1. There are two settings that have to be changed to handle more than 2MB.

The first is the fileUpload interceptor’s maximumSize param and the second is the struts.multipart.maxSize. I set both in the example below in the struts.xml file (the struts.multipart.maxSize can also be set in the struts.properties or web.xml).

<!-- 104857600 - 100MB -->
<constant name="struts.multipart.maxSize" value="104857600" />
<action name="importCSVFile" method="importCSVFile" class="ImportCSVDataAction" >
  <result name="success" type="tiles">importdata</result>
  <result name="error" type="tiles">importdata</result>
  <result name="input" type="tiles">importdata</result>
  <interceptor-ref name="paramsPrepareParamsStack">
    <!-- 52428800 = 50mb -->
    <param name="fileUpload.maximumSize">52428800</param>

Notice that the above code overrides the fileUpload interceptor that is in the paramsPreparParams stack. It’s a nice shorthand way of using the interceptor name as the prefix and the param name as the suffix.

2. When either of the max size limits are exceeded you get a different error message.

  • The struts.multipart.maxSize gives a fairly clear and readable message as an action error
  • The maximumSize param gives a very ugly message as a field error
I think both are not nice enough to present to the user so I catch them both in the validate method and replace with a nicer message:
private static final String MAX_FILE_SIZE = "50MB";
public void validate()
  List<String> uploadErrors = (List<String>)getActionErrors();
  if (getFieldErrors().get("upload") != null)
  for (String err : uploadErrors)
    if (err.startsWith("File too large") || err.startsWith("the request was rejected because its size"))
      addActionError(getText(MSG_KEY_ERROR_FILE_TOO_LARGE, Arrays.asList(MAX_FILE_SIZE)));

3. Note that in the first example of the struts.xml code I have the input result set. The max size errors will return a input result, so if you don’t have this defined you get a servlet error message.