JSP + Velocity + Resin........ java.lang.NullPointerException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kukukgl
    New Member
    • Jun 2007
    • 4

    #1

    JSP + Velocity + Resin........ java.lang.NullPointerException

    Hi.....

    We are using velocity1.4 to implement templating in our system. The system is running fine since deploy. Recently, there is a serious problem that causing the web panel down. We did setup multiple host in resin to point to different panel. When the error happen, only the host having the problem down but others are ok.

    Host Setting in resin.conf
    Code:
     
    <host id="api.abc.com" root-directory="/www/sw/api">
          <web-app id="/" document-directory="/www/sw/api">
            <servlet-mapping url-pattern="/servlet/*" servlet-name="invoker"/>
          </web-app>
     </host>
    From the error message in stdout.log, we found the java null pointer throw from velocity. The coding area is somewhere like below:

    Code:
    public int doEndTag() throws JspException {
    		try {
    			logger.info("Velocity File Resource Loaded:"+Velocity.FILE_RESOURCE_LOADER_PATH);
    
    			VelocityContext myVelocityContext = null;
    			Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, velpath);
    			Velocity.init();
    			if (ctx == null) {
    				myVelocityContext = new VelocityContext();
    			}
    			else {
    				myVelocityContext = ctx;
    			}
    
    			Template template = null;
    			template = Velocity.getTemplate(veltemplate, "UTF-8");
    			StringWriter myStringWriter = new StringWriter();
    
    			template.merge(myVelocityContext, myStringWriter);
    			pageContext.getOut().print(myStringWriter);
    
    			return EVAL_PAGE;
    		}
    		catch (Exception e) {
    			e.printStackTrace();
    
    			throw new JspException("Exception; TEMPLATE_CLASSPATH; exception="
    					+ e.getMessage());
    		}
    	}
    We are sure that the Velocity.FILE_R ESOURCE_LOADER_ PATH, velpath, and veltemplate are always holding correct value. But, just don't know why it throwing null pointer. Until now, we still can't find out the PATTERN to simulate the problem. The error might happen any time, after server running 3 days, 4 days.... anytime(even not peak hour) then suddenly throw error. Now, we still dont know what is the root cause.... totally not idea.....

    Please help...
Working...