Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB Execution jumps to jsp page and gives Servlet.service() for servlet jsp threw exception

 
Praveen Orvakanti
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am getting an Exception when im running my application:


Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException

My Code is as follows:


EJB Code:

System.out.println("INFO: Executing ReportsEJB ");
System.out
.println("INFO:************* Executing EJB ********************** ");


Session session = HibernateUtil.getSessionFactory().openSession();
Transaction t = session.beginTransaction() ;

System.out.println("DEBUG : Session retrieved");


String sqlQuery1 = "select DATA_ID, avg(value)from Power p where LAST_UPDATED_ON between :fromDate and :toDate" +
" and type = :type GROUP BY DATA_ID ORDER BY avg(value) DESC";
String sqlQuery2 = "select DATA_ID, avg(value)from Power p where LAST_UPDATED_ON between :fromDate and :toDate" +
" and type = :type GROUP BY DATA_ID ORDER BY avg(value)";
String sqlQuery3 = "select DC_ID, avg(value)from Power p where LAST_UPDATED_ON between :fromDate and :toDate" +
" and type = :type GROUP BY DC_ID ORDER BY avg(value) DESC";
String sqlQuery4 = "select DC_ID, avg(value)from Power p where LAST_UPDATED_ON between :fromDate and :toDate " +
" and type = :type GROUP BY DC_ID ORDER BY avg(value)";

System.out.println("INFO: Report Generation");

Query q1;
Iterator itr;
if(type.equals("DATA"))
{

if(reportName.equals("MAX"))
{
System.out.println("INFO: The MAX report has to be generated Data-Wise");

System.out.println("***************** Executing Query******************");
q1 = session.createQuery(sqlQuery1);

System.out.println("INFO: Data Max Report ---> ");

q1.setParameter("type", type);
q1.setParameter("fromDate",fromTimeStamp);
q1.setParameter("toDate",toTimeStamp);
q1.setMaxResults(count);

}
else
{

q1 = session.createQuery(sqlQuery2);
q1.setParameter("type", type);
q1.setParameter("fromDate",fromTimeStamp);
q1.setParameter("toDate",toTimeStamp);
q1.setMaxResults(count);
System.out.println("INFO: Data Min Report");

}
System.out.println("INFO: Iterating thro the result set");
itr = q1.iterate();
while(itr.hasNext())
{
Object[] row = (Object[]) itr.next();
Double val = (Double) row[1];
power = (Power) itr.next();
System.out.println("INFO: The Values are :");
System.out.println("INFO: DATA --> "+ power.getData().getName() );
System.out.println("INFO: POWER --> "+ power.getValue());
totalValues.put(power.getData().getName(), val);

}
}


else if(type.equals("DC"))
{

if(reportName.equals("MAX"))
{
System.out.println("INFO: The MAX report has to be generated DC-Wise");
q1 = session.createQuery(sqlQuery3);

q1.setParameter("type", type);
q1.setParameter("fromDate",fromTimeStamp);
q1.setParameter("toDate",toTimeStamp);
q1.setMaxResults(count);
System.out.println("INFO: DC Max Report");
}
else
{

q1 = session.createQuery(sqlQuery4);
q1.setParameter("type", type);
q1.setParameter("fromDate",fromTimeStamp);
q1.setParameter("toDate",toTimeStamp);
q1.setMaxResults(count);
System.out.println("INFO: DC Min Report");
}

itr = q1.iterate();
while(itr.hasNext())
{
Object[] row = (Object[]) itr.next();
Double val = (Double) row[1];
power = (Power) itr.next();
dc= power.getDc().getDC().iterator().next();
System.out.println("INFO: The Values are :");
System.out.println("INFO: DC --> "+ dc.getName());
System.out.println("INFO: POWER --> "+ val);
totalValues.put(dc.getName(), val);

}
}


t.commit();

session.close();
//HibernateUtil.shutDown();
System.out.println("DEBUG : Cleanup completed");
return totalValues;





JSP Code:


<?xml version="1.0" encoding="UTF-8"?>
<%@
page
import="com.tt.helt.duran.hibernate.entities.*,java.util.*"
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" autoFlush="true"%>

<%

Map<String,Double> powerValues;
powerValues =(Map<String,Double>) request.getAttribute("ReportValues");

Iterator itr = powerValues.entrySet().iterator();

String name;
Double value;




%>

<tt label="TT"> <%
while(itr.hasNext())
{
Map.Entry entry = (Map.Entry)itr.next();
name = (String) entry.getKey();
value = (Double) entry.getValue();
%> <sample> <name><%=name%> </name> <power><%=value%>
</power> </sample> <%

}


%> </tt>




Noe:

Strangely the execution jumps to the jsp page when the first query(q1) is created.


Exception:


17:06:12,500 INFO [STDOUT] DEBUG : Sesion factory initialized
17:06:12,500 INFO [STDOUT] DEBUG : in getSesionFactory() method
17:06:12,500 INFO [STDOUT] DEBUG : Session retrieved
17:06:12,500 INFO [STDOUT] INFO: Report Generation
17:06:12,500 INFO [STDOUT] INFO: The MAX report has to be generated Datacenter-Wise
17:06:12,500 INFO [STDOUT] ***************** Executing Query******************
17:06:12,547 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.Report_jsp._jspService(Report_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:154)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)


What could be the issue???

Thanks in advance





 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!