CDI Servlet java.lang.NullPointerException - java

People, please, help me!!! I am driving really crazy. My code have been working before today, and now it's broken...
Here is my servlet:
#Stateless
class TempSession {
void createFile( String fileName ) {
try {
FileWriter writer = new FileWriter( fileName );
writer.close();
}
catch ( IOException e ) {
e.printStackTrace();
}
}
}
#WebServlet( name = "CreteFileServlet", urlPatterns = "/createCSV" )
public class CreateCSVConfigurationServlet extends javax.servlet.http.HttpServlet {
#Inject
TempSession session;
protected void doPost( javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response ) throws javax.servlet.ServletException, IOException {}
protected void doGet( javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response ) throws javax.servlet.ServletException, IOException {
session.createFile( "d:/session.txt" );
}
}
Here is web.xml:
<servlet>
<servlet-name>CreateFileServlet</servlet-name>
<servlet-class>com.bs.amg.test.servlets.CreateCSVConfigurationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CreateFileServlet</servlet-name>
<url-pattern>/createCSV</url-pattern>
</servlet-mapping>
JSP snippet:
<form action="createCSV" method="get">
<input type="submit" value="Create configuration"/>
</form>
AnŠ² Jboss 7.0.1 log server snippet:
14:10:52,471 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "ear-1.0.ear"
14:11:10,336 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/web].[CreteFileServlet]] (http--127.0.0.1-8080-2) Servlet.service() for servlet CreteFileServlet threw exception: java.lang.NullPointerException
at com.bs.amg.test.servlets.CreateCSVConfigurationServlet.doGet(CreateCSVConfigurationServlet.java:136) [classes:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
Please, I really need your help!!!!!

You are declaring your servlet with both webservlet annotation and web.xml mapping. You should have only one declaration using the annotation as in this example.

I think that the injection is not occuring because CDI is not enabled. Make sure you have a beans.xml as stated in CDI documentation: http://docs.oracle.com/javaee/6/tutorial/doc/gjbnz.html. Here is a sample beans.xml file you can use to enable CDI:
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

Related

org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException exception in jboss AS 7.1.1

I found an error org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException exception while deploying the war file.my code is as follows.
public class ReminderService extends HttpServlet implements Runnable{
public void init() throws ServletException {
LogMsg.info("I am init()");
ReminderService rThread = new ReminderService();
refresher = new Thread(rThread);
refresher.start();
LogMsg.info("I am from appointments refresh Method.Thread is started now");
}
#Override
public void run() {
try {
LogMsg.info("I am from run Method.");
obj.somefunction();
Thread.sleep(3000);
LogMsg.info("I am from run Method.Thread woke up from sleep");
}catch (InterruptedException e) {
e.printStackTrace();
}
run();
}
}
Here i want to call the this servlet class init() by default i mean while deploying the war file but the problem is it is not triggered automatically,please let me know i am new to this.
Here the problem is in run method when i tried to call any other methods it is raising the error as mentioned as below.Please let me know the wrong thing.Thanks in advance.
This is the message i got in console
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default- host].[/ThanQDoctor].[org.jboss.tools.thanqdoctor.rest.JaxRsActivator]] (http--127.0.0.1-8080-3) Servlet.service() for servlet org.jboss.tools.thanqdoctor.rest.JaxRsActivator threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:340) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:540) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.2.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67] Caused by: java.lang.NullPointerException

Neither BindingResult nor plain target object for bean name spring mvc

I have a problem with my little project.
Here is my controler
#Controller
#RequestMapping( "/loginPage" )
public class LoginController
{
private static final String VN_LOGIN_FORM = "login/LoginForm";
private static final String VN_HOME_FORM = "redirect:../home.html";
String VN_LOGIN_FAIL_FROM = "redirect:../loginPage /login.html";
// #Autowired
private AccountService act;
private EmployeeService em;
#RequestMapping( value = "login", method = RequestMethod.GET )
public String getRegistrationForm( Model model )
{
model.addAttribute( "user", new AccountForm( ) );
return VN_LOGIN_FORM;
}
#RequestMapping( value = "", method = RequestMethod.POST )
public String postRegistrationForm( #ModelAttribute( "user" ) AccountForm form )
{
Account temp = toAccount( form );
Account found = act.getAccount( temp.getUsername( ) );
java.util.List<Employee> list = em.getNewEmployees( );
if ( found != null && found.getPassword( ).equals( temp.getPassword( ) ) )
{
return VN_HOME_FORM;
}
return VN_LOGIN_FAIL_FROM;
}
#InitBinder
public void initBinder( WebDataBinder binder )
{
binder.setAllowedFields( new String[ ] { "username", "password", "confirmPassword", "firstName", "lastName", "email",
"marketingOk", "acceptTerms" } );
}
private static Account toAccount( AccountForm form )
{
Account account = new Account( );
account.setUsername( form.getUsername( ) );
account.setPassword( form.getPassword( ) );
return account;
}
}
Here is my jps page.
<form:form action="." modelAttribute="user" method="POST"
class="login">
<form:errors path="*">
<div class="warning alert">
<spring:message code="error.global" />
</div>
</form:errors>
<div>
<label for="username">${username}</label>
<form:input name="username" id="login" path="username"
cssErrorClass="short error" value="username" />
</div>
<br>
<div>
<label for="password">${password}</label>
<form:password path="password" name="password" value="1111111111" />
</div>
<div class="login-submit">
<button type="submit" value="" class="login-button">Submit</button>
</div>
<br>
<div class="forgot-password">
<button type="submit" class="btn-reset">Forgot your
password?</button>
<button type="submit" class="btn-reset">Reset</button>
</div>
</form:form>
Here is the exception trace:
09:31:49,069 ERROR [org.springframework.web.servlet.tags.form.InputTag] (http-localhost-127.0.0.1-8080-1) Neither BindingResult nor plain target object for bean name 'user' available as request attribute: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.apache.jsp.WEB_002dINF.views.login.LoginForm_jsp._jspx_meth_form_005finput_005f0(LoginForm_jsp.java:364)
at org.apache.jsp.WEB_002dINF.views.login.LoginForm_jsp._jspService(LoginForm_jsp.java:174)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1157) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:927) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Here is info from my beans-web.xml
<mvc:view-controller path="/loginPage/login.html" view-name="login/LoginForm" />
How i access the page :
http://localhost:8080/spring-mvc/loginPage/login.html
I don't understand where's the probleme.
Looks like you have configured only <mvc:view-controller> in your beans-web.xml. In order for spring to inject user object, the controller needs to be scanned as well. Below tags are required to register the controllers and the handler mapping. If you have configured the below post your complete config in your OP.
<mvc:annotation-driven/>
<context:component-scan base-package="you controller package goes here" />
If your dispatcher servlet is set to handle *.html, then you don't need <mvc:view-controller>. Simple passing through the controller should solve your issue.

Getting java.lang.ClassNotFoundException: javax.media.jai.ParameterBlockJAI exception

I am really stuck at this exception from 3 days. It was working fine but suddenly it is throwing this exception.
I am trying to upload an image for cleaning from my android device to JAVA servlet in jboss which is like this :
Class Servlet extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("You need to post an image.");
PrintWriter out = response.getWriter();
out.println("Please post an image..");
out.flush();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
long time = System.currentTimeMillis(); // check the time, for file-naming and such
System.out.println("Got a post - " + time);
try{
// get the image from the app
ObjectInputStream ois = new ObjectInputStream(request.getInputStream());
byte[] imageBytes = (byte[]) ois.readObject();
PlanarImage image = ImageUtil.getAsImage(imageBytes);
ois.close();
System.out.println("Read image from stream...");
// save a copy for inspection
ImageUtil.saveImage(image, time + "_y");
.......
And the ImageUtil.getasimage is like :
public static PlanarImage getAsImage(byte[] imageBytes){
BufferedImage bi = null;
InputStream in = null;
try {
in = new ByteArrayInputStream(imageBytes);
bi = ImageIO.read(in);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return PlanarImage.wrapRenderedImage(bi);
}
I am getting the following error on the line
PlanarImage image = ImageUtil.getAsImage(imageBytes);
Error :
[org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/VINCServer].[vinc]] (http--0.0.0.0-8080-2) Servlet.service() for servlet vinc threw exception: java.lang.ClassNotFoundException: javax.media.jai.ParameterBlockJAI from [Module "deployment.VINCServer.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at VinCapture.doPost(VinCapture.java:41) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_55]
I have also downloaded all the needed jars for the above.
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import javax.media.jai.ParameterBlockJAI;
import javax.media.jai.PlanarImage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.usaa.ar.deconvolution.Restore;
import com.usaa.ar.util.ImageUtil;
But still no luck.Please help me as I am not able to find anything on this exception.

Primefaces selectManyMenu error on selecting many

I have a interfaces uses selectManyMenu where dealer can select some criteria based on zip codes they service. They have almost 800 zip codes , if we select approx 250 it works but above that interfaces throws an error as below
<p:selectManyMenu showCheckbox="true" style="width:100px;height:200px" value="#{mergeList.lbean.selectedzips}">
<f:selectItems value="#{mergeList.zips}" var="zp" itemLabel=" #{zp.name}" itemValue="# {zp.name}" />
</p:selectManyMenu>
for servlet Faces Servlet threw exception:
java.lang.NullPointerException at
com.sun.faces.context.PartialViewContextImpl.createPartialResponseWriter(PartialViewContextImpl.java:441)
[jsf-impl-2.1.7-jbossorg-2.jar:] at
com.sun.faces.context.PartialViewContextImpl.access$300(PartialViewContextImpl.java:71)
[jsf-impl-2.1.7-jbossorg-2.jar:] at
com.sun.faces.context.PartialViewContextImpl$DelayedInitPartialResponseWriter.getWrapped(PartialViewContextImpl.java:582)
[jsf-impl-2.1.7-jbossorg-2.jar:] at
javax.faces.context.PartialResponseWriter.startDocument(PartialResponseWriter.java:115)
[jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] at
org.primefaces.context.PrimePartialResponseWriter.startDocument(PrimePartialResponseWriter.java:134)
[primefaces-4.0.jar:4.0] at
com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:199)
[jsf-impl-2.1.7-jbossorg-2.jar:] at
com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:123)
[jsf-impl-2.1.7-jbossorg-2.jar:] at
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
[jsf-impl-2.1.7-jbossorg-2.jar:] at
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
[jsf-impl-2.1.7-jbossorg-2.jar:] at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
[jsf-impl-2.1.7-jbossorg-2.jar:] at
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
[jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
[jbossweb-7.0.13.Final.jar:] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
[jbossweb-7.0.13.Final.jar:] at
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
[primefaces-4.0.jar:4.0] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
[jbossweb-7.0.13.Final.jar:] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
[jbossweb-7.0.13.Final.jar:] at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
[jbossweb-7.0.13.Final.jar:] at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
[jbossweb-7.0.13.Final.jar:] at
org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
[jboss-as-web-7.1.1.Final.jar:7.1.1.Final] at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
[jbossweb-7.0.13.Final.jar:] at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
[jbossweb-7.0.13.Final.jar:] at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[jbossweb-7.0.13.Final.jar:] at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
[jbossweb-7.0.13.Final.jar:] at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
[jbossweb-7.0.13.Final.jar:] at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
[jbossweb-7.0.13.Final.jar:] at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
[jbossweb-7.0.13.Final.jar:] at java.lang.Thread.run(Unknown Source)
[rt.jar:1.6.0_25]
Try this:
List<ObjectName> selectedZips=new ArrayList<>();
// getter & setter
<p:selectManyMenu showCheckbox="true" style="width:100px;height:200px"
value="#{mergeList.selectedzips}">
<f:selectItems value="#{mergeList.zips}" var="zp" itemLabel=" #{zp.name}"
itemValue="#{zp.name}" />
</p:selectManyMenu>

NullpointerException when I'm invoking a method

I have created an entity that selects all players from a database:
#NamedQueries({
#NamedQuery(name ="player.findAll",
query = "select p from Player p")
})
and then I have created a stateless bean and its interface that implements the method.
private EntityManager em;
...
public List<Player> findAllPlayers(){
TypedQuery <Player> query =
em.createNamedQuery("player.findAll", Player.class);
List<Player> results = query.getResultList();
return results;
}
and in interface its signature
public List<Player> findAllPlayers();
then I have created a stateless facade that works as a controller(MVC-structure).
#EJB
PlayerEAOLocal playerEAO;
...//Some more code
public List <Player> findAllPlayers(){
return playerEAO.findAllPlayers();
}
//And in interface...
public List <Player> findAllPlayers();
To make it clearer this is what I have done:
An entity
A local java bean(stateless) + Interface.
and a facade + Interface that refers to the beans.
Now I have created a servlet that the JSP will use for calling the FacadeLocal class(interface).
In my doPost method I have this implemented:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
FacadeLocal f = (FacadeLocal) facade.findAllPlayers();
request.setAttribute("facade", f);
}
and then I have the JSP file:
<form action = "GetAllPlayersServlet" method = "post">
<input type = "submit" name = "submit" value = "Show all"></input></td>
<td style = "width: 2px; "></td>
<% FacadeLocal facade = (FacadeLocal)request.getAttribute("facade"); %>
<td><input type = "text" name= "showAll" value = "<%= facade.findAllPlayers()%>">
But I get a nullPointerException
The error message
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/PlayerClientProject].[jsp]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet jsp threw exception: java.lang.NullPointerException
at org.apache.jsp.ShowAllPlayers_jsp._jspService(ShowAllPlayers_jsp.java:81)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
Alright. I am editing my question a little bit.
I have succeeded with showing all data from database in the servlet by doing:
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
List<Player> allPlayers = facade.findAllPlayers();
for (Player p1 : allPlayers) {
out.println("<h4>Founded: " + p1.getClass().getSimpleName());
out.println(" Id: " + p1.getId());
out.println(" - " + p1.getNickname());
out.println(" - " + p1.getLocation());
out.println(" - " + p1.getChampion() + "</h4>");
}
}
Now I wonder how I can pass the list to the JSP using doPost method?
You need to check facade for null:
<%
FacadeLocal facade = (FacadeLocal)request.getAttribute("facade");
if(facade == null)
{
out.print("<td><input type='text' name='showAll' value='' />");
}
else
{
out.print("<td><input type='text' name='showAll' value='"+facade.findAllPlayers()+"' />");
}
%>
If that doesn't fix it, do something similar everwhere you are using the dot operator on a variable that may be null.

Categories

Resources