[jboss-user] [JBoss Portal] - Re: NPE using JSTL format

PeterJ do-not-reply at jboss.com
Sat Aug 12 21:46:42 EDT 2006


Not being one to give up easily, I came up with a workaround patch to the portal.  Edit the file .\portlet\src\main\org\jboss\portal\portlet\impl\jsr168\PortletRequestDispatcherImpl.java adding the import:

import java.util.Enumeration;

and add the following code within the execute method (new code is in blue, other code is existing code)

HttpServletRequest wrappedReq = new HttpServletRequestWrapper(req)
  | {
  |   /**
  |    * Override the behavior from tomcat, see above.
  |    *
  |    * @return the null value per the spec
  |    */
  |   public StringBuffer getRequestURL()
  |   {
  |     // Per the spec
  |     Exception e = new Exception("called getRequestURL");
  |     e.printStackTrace();
  |     return null;
  |   }
  | 
  |   public Enumeration getHeaders(String hdr) {
  |      Enumeration result = null;
  |       if ("accept-language".equals(hdr)) {
  |         result = new Enumeration() {
  |           int i = 0;
  |           public boolean hasMoreElements() {return i == 0;}
  |           public Object nextElement() {i++; return "";}
  |         };
  |       }
  |       return result;
  |   }
  | 
  | };

Why does this work?  Well, the JSTL code first looks to see if there is at least one accept-language header entry.  It never looks at what the entry is, just if there is one.  If there is, then it calls request.getLocales() and uses that information to do the localization.  This patch is sufficient to fool the JSTL code into getting the locale, which, fortunately, still exists.

My initial thought was that this is a kludge.  However, it does have some advantages.  First, all headers except accept-language still return null, as is done now.  Second, while accept-language now returns an enumeration its contents are useless, forcing the portlet to use getProperty, as recommended in section 11.1.4 of the spec.

Any desire to add this patch to the 2.4 source base?  I could open a Jira and apply the patch.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3964810#3964810

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3964810



More information about the jboss-user mailing list