PF5 RC1 - Push Showcase chat - EventBusFactory NPE..

UI Components for JSF
priyaesh
Posts: 26
Joined: 07 Feb 2011, 03:37

22 Apr 2014, 04:44

Team

I m migrating from PF 4.0.x to PF 5 RC1 and trying to get my hands around showcase chat example. But I m getting NPE at ChatView.java line 20.

Code: Select all

    private final EventBus eventBus = EventBusFactory.getDefault().eventBus();

Code: Select all


Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.rcent.sample.ChatView]: Constructor threw exception; nested exception is java.lang.NullPointerException
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1000)
	... 118 more
Caused by: java.lang.NullPointerException
	at com.rcent.sample.ChatView.<init>(ChatView.java:20)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
	... 120 more

I am using @Named annotation instead of @ManagedBean which as you may know is quite common convention CDI. And I have this pattern all over my application. No issues in any other classes.

Also I have the dependency for atmosphere 2.1.3 runtime with PF 5 RC1 in my pom for trying out this sample. Is there any other dependency that is needed specifically for push to work ?

Please share your thoughts.

Regards
Priyaesh.
priyaesh

Primefaces 4, JSF 2.1, Spring 3.2, SpringSecurity 3, JPA 2.0, Tomcat 7

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

22 Apr 2014, 07:16

reply with all of your source code, so we can compare with the showcase chat source code.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

22 Apr 2014, 17:44

priyaesh wrote:I am using @Named annotation instead of @ManagedBean which as you may know is quite common convention CDI. And I have this pattern all over my application. No issues in any other classes.
And in your stacktrace there is all kinds of info from spring... hmmmm

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

22 Apr 2014, 18:20

smithh032772 wrote:reply with all of your source code, so we can compare with the showcase chat source code.
i want to see all of his code and compare with showcase, because there is specific/special code in showcase which could possibly cause the following:

Code: Select all

Caused by: java.lang.NullPointerException
   at com.rcent.sample.ChatView.<init>(ChatView.java:20)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

priyaesh
Posts: 26
Joined: 07 Feb 2011, 03:37

23 Apr 2014, 03:09

Okay.. Here is the source code for all the chat related files.

1. ChatView.java

Code: Select all

package com.rcent.sample;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.primefaces.context.RequestContext;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;

@Named
@ViewScoped
public class ChatView implements Serializable {
     
    //private final PushContext pushContext = PushContextFactory.getDefault().getPushContext();
 
	private final EventBus eventBus = EventBusFactory.getDefault().eventBus();
 
//    @ManagedProperty("com.rcent.sample.ChatUsers@ac5024")

	@Inject
    private ChatUsers users;
 
    private String privateMessage;
     
    private String globalMessage;
     
    private String username;
     
    private boolean loggedIn;
     
    private String privateUser;
     
    private final static String CHANNEL = "/{room}/";
 
    public ChatUsers getUsers() {
        return users;
    }
 
    public void setUsers(ChatUsers users) {
        this.users = users;
    }
     
    public String getPrivateUser() {
        return privateUser;
    }
 
    public void setPrivateUser(String privateUser) {
        this.privateUser = privateUser;
    }
 
    public String getGlobalMessage() {
        return globalMessage;
    }
 
    public void setGlobalMessage(String globalMessage) {
        this.globalMessage = globalMessage;
    }
 
    public String getPrivateMessage() {
        return privateMessage;
    }
 
    public void setPrivateMessage(String privateMessage) {
        this.privateMessage = privateMessage;
    }
     
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
     
    public boolean isLoggedIn() {
        return loggedIn;
    }
    public void setLoggedIn(boolean loggedIn) {
        this.loggedIn = loggedIn;
    }
 
    public void sendGlobal() {
        eventBus.publish(CHANNEL + "*", username + ": " + globalMessage);
         
        globalMessage = null;
    }
     
    public void sendPrivate() {
        eventBus.publish(CHANNEL + privateUser, "[PM] " + username + ": " + privateMessage);
         
        privateMessage = null;
    }
     
    public void login() {
        RequestContext requestContext = RequestContext.getCurrentInstance();
         
        if(users.getUsers().contains(username)) {
            loggedIn = false;
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Username taken", "Try with another username."));
            requestContext.update("growl");
        }
        else {
            users.addUser(username);
            requestContext.execute("PF('subscriber').connect('/" + username + "')");
            loggedIn = true;
        }
    }
     
    public void disconnect() {
        //remove user and update ui
        users.removeUser(username);
        RequestContext.getCurrentInstance().update("form:users");
         
        //push leave information
        eventBus.publish(CHANNEL + "*", username + " left the channel.");
         
        //reset state
        loggedIn = false;
        username = null;
    }
//    @PostConstruct
//    public void init(){
//    	users = new ChatUsers();
//    	users.setUsers(new ArrayList<String>());
//    }
}
2. ChatUsers.java

Code: Select all

package com.rcent.sample;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.inject.Named;

import org.springframework.context.annotation.Scope;

@Named
@ApplicationScoped
public class ChatUsers {
	 
    private List<String> users;
   
    @PostConstruct
    public void init() {
        users = new ArrayList<String>();
    }

    public List<String> getUsers() {

        return this.users;
    }

    public void setUsers(List<String> users) {
        this.users = users;
    }
   
    public void addUser(String user) {
    	System.out.println("<--------inside the AddUser---------->"+getUsers().size());
    	
        this.users.add(user);
    }
   
    public void removeUser(String user) {
        this.users.remove(user);
    }
   
    public boolean contains(String user) {
        return this.users.contains(user);
    }
}

3. ChatResource.java

Code: Select all

package com.rcent.sample;

import javax.inject.Inject;
import javax.servlet.ServletContext;

import org.primefaces.push.EventBus;
import org.primefaces.push.RemoteEndpoint;
import org.primefaces.push.annotation.OnClose;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.OnOpen;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.annotation.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@PushEndpoint("/{room}/{user}")
@Singleton
public class ChatResource {
 
    private final Logger logger = LoggerFactory.getLogger(ChatResource.class);
 
    // The Path takes the form of /{room}/{user}
    public final static int USER_PATH_SEGMENT = 2;
    public final static int ROOM_PATH_SEGMENT = 1;
 
    @Inject
    private ServletContext ctx;
 
    @OnOpen
    public void onOpen(RemoteEndpoint r, EventBus eventBus) {
        logger.info("OnOpen {}", r);
         
        String username = r.pathSegments(USER_PATH_SEGMENT);
        String room = r.pathSegments(ROOM_PATH_SEGMENT);
 
        eventBus.publish(room + "/*", new Message(String.format("%s has entered the room '%s'",  username, room), true));
    }
 
    @OnClose
    public void onClose(RemoteEndpoint r, EventBus eventBus) {
        String username = r.pathSegments(USER_PATH_SEGMENT);
        String room = r.pathSegments(ROOM_PATH_SEGMENT);
         
        ChatUsers users= (ChatUsers) ctx.getAttribute("chatUsers");
        users.removeUser(username);
         
        eventBus.publish(room + "/*", new Message(String.format("%s has left the room", username), true));
    }
 
    @OnMessage(decoders = {MessageDecoder.class}, encoders = {MessageEncoder.class})
    public Message onMessage(Message message) {
        return message;
    }
}

4. Chat.xhtml

Code: Select all


<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:r="http://java.sun.com/jsf/composite/components"
	template="rcentTemplate.xhtml">

<ui:define name="content">

<div class="entry">
	
	<h1 class="title ui-widget-header ui-corner-all">Chat</h1>


<h:form id="form">

    <p:remoteCommand name="updateList" update="users" process="@this" />
    <p:fieldset id="container" legend="PrimeChat" toggleable="true">

        <h:panelGroup rendered="#{chatView.loggedIn}">

            <h:panelGrid columns="2" columnClasses="publicColumn,usersColumn" style="width:100%">
                <p:outputPanel id="public" layout="block" styleClass="ui-corner-all ui-widget-content chatlogs"/>
              
                <p:dataList id="users" var="user" value="#{chatUsers.users}"  styleClass="usersList">
<!--                  <p:dataList id="users" var="user" value="#{chatView.users.users}"  styleClass="usersList"> -->
                    <f:facet name="header">
                        Users
                    </f:facet>

                    <p:commandButton title="Chat" icon="ui-icon-comment" oncomplete="PF('pChat').show()" update=":form:privateChatContainer">
                        <f:setPropertyActionListener value="#{user}" target="#{chatView.privateUser}" />
                    </p:commandButton>
                    #{user}
                </p:dataList>
			</h:panelGrid>

            <p:separator />

            <p:inputText value="#{chatView.globalMessage}" styleClass="messageInput" />
            <p:spacer width="5" />
            <p:commandButton value="Send" actionListener="#{chatView.sendGlobal}" oncomplete="$('.messageInput').val('').focus()" >
<!--             		<p:ajax update="container" /> -->
            </p:commandButton>
            <p:spacer width="5" />
            <p:commandButton value="Disconnect" actionListener="#{chatView.disconnect}" global="false" update="container" />
        </h:panelGroup>

        <h:panelGroup rendered="#{not chatView.loggedIn}" >
            Username: <p:inputText value="#{chatView.username}" />

            <p:spacer width="5" />
            <p:commandButton value="Login" actionListener="#{chatView.login}" update="container" 
                                icon="ui-icon-person" />
        </h:panelGroup>

    </p:fieldset>

	    <p:dialog widgetVar="pChat" header="Private Chat"  showEffect="fade" hideEffect="fade">
	        <h:panelGrid id="privateChatContainer" columns="2" columnClasses="vtop,vtop">
	            <p:outputLabel for="pChatInput" value="To: #{chatView.privateUser}" />
	            <p:inputTextarea id="pChatInput" value="#{chatView.privateMessage}" rows="5" cols="30" />
	
	            <p:spacer />
	            <p:commandButton value="Send" actionListener="#{chatView.sendPrivate}" oncomplete="PF('pChat').hide()" />
	        </h:panelGrid>
	    </p:dialog>

</h:form>

<p:socket onMessage="handleMessage" channel="/{room}" autoConnect="false" widgetVar="subscriber">
<!-- 					<p:ajax event="message" update=":form:users" /> -->
</p:socket>



<script type="text/javascript">
    function handleMessage(message) {
    console.log(message);
    var chatContent = $(PrimeFaces.escapeClientId('form:public')),
    text = (message.user) ? message.user + ':' + message.text: message.text;

    chatContent.append(text + '<br />');

    //keep scroll
    chatContent.scrollTop(chatContent.height());

    if(message.updateList) {
        updateList();
    }
}
</script>
</div>
</ui:define>
</ui:composition>
		
5. Message.java

Code: Select all

package com.rcent.sample;

public class Message {
	
	    private String text;
	    private String user;
	    private boolean updateList;
	 
	    public Message() {
	    }
	 
	    public Message(String text) {
	        this.text = text;
	    }
	     
	    public Message(String text, boolean updateList) {
	        this.text = text;
	        this.updateList = updateList;
	    }
	 
	    public Message(String user, String text, boolean updateList) {
	        this.text = text;
	        this.user = user;
	        this.updateList = updateList;
	    }
	     
	    public String getText() {
	        return text;
	    }
	 
	    public Message setText(String text) {
	        this.text = text;
	        return this;
	    }
	 
	    public String getUser() {
	        return user;
	    }
	 
	    public Message setUser(String user) {
	        this.user = user;
	        return this;
	    }
	 
	    public boolean isUpdateList() {
	        return updateList;
	    }
	 
	    public void setUpdateList(boolean updateList) {
	        this.updateList = updateList;
	    }

}

6. MessageDecoder.java

Code: Select all

package com.rcent.sample;

import org.primefaces.push.Decoder;

public final  class MessageDecoder implements Decoder<String,Message> {
	
	 public Message decode(String s) {
	        String[] userAndMessage = s.split(":");
	        if (userAndMessage.length >= 2) {
	            return new Message().setUser(userAndMessage[0]).setText(userAndMessage[1]);
	        }
	        else {
	            return new Message(s);
	        }
	    }

}

7. MessageEncoder.java

Code: Select all

package com.rcent.sample;

import org.primefaces.json.JSONObject;
import org.primefaces.push.Encoder;

public final class MessageEncoder implements Encoder<Message, String> {
	
	public String encode(Message message) {
        return new JSONObject(message).toString();
    }
}

Full Stacktrace

Code: Select all

SEVERE: Servlet.service() for servlet [facesServlet] in context with path [/RcentWeb] threw exception [Error creating bean with name 'chatView' defined in file [D:\FinalGradleTest\BaseWS\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\RcentWeb\WEB-INF\classes\com\rcent\sample\ChatView.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.rcent.sample.ChatView]: Constructor threw exception; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
	at com.rcent.sample.ChatView.<init>(ChatView.java:21)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1000)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:940)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
	at org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.java:56)
	at com.company.demo.web.faces.ConversationAwareElResolver.getValue(ConversationAwareElResolver.java:43)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
	at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
	at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:415)
	at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:74)
	at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
	at org.primefaces.component.fieldset.FieldsetRenderer.encodeContent(FieldsetRenderer.java:94)
	at org.primefaces.component.fieldset.FieldsetRenderer.encodeMarkup(FieldsetRenderer.java:76)
	at org.primefaces.component.fieldset.FieldsetRenderer.encodeEnd(FieldsetRenderer.java:47)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:877)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1826)
	at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:847)
	at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:81)
	at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
	at org.primefaces.component.outputpanel.OutputPanelRenderer.encodeMarkup(OutputPanelRenderer.java:64)
	at org.primefaces.component.outputpanel.OutputPanelRenderer.encodeEnd(OutputPanelRenderer.java:40)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:877)
	at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85)
	at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
	at org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:49)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:877)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1826)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:447)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at com.company.demo.web.filter.NoPageCacheFilter.doFilter(NoPageCacheFilter.java:41)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at com.company.demo.web.conversation.ConversationFilter.doFilter(ConversationFilter.java:79)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at com.company.demo.web.filter.LogContextFilter.doFilter(LogContextFilter.java:39)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at com.company.demo.web.filter.LocaleResolverRequestFilter.doFilterInternal(LocaleResolverRequestFilter.java:52)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.omnifaces.filter.GzipResponseFilter.doFilter(GzipResponseFilter.java:147)
	at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

So thats all I have for this sample. Also I have the updated the web.xml header to 3.0 as I have seen in another forum posting.

Appreciate your help in analysing this.

Regards
priyaesh

Primefaces 4, JSF 2.1, Spring 3.2, SpringSecurity 3, JPA 2.0, Tomcat 7

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

23 Apr 2014, 03:38

okay, this is what I wanted to see, and I already knew that you changed something about the showcase code and not using exactly the same code. you are using CDI instead of JSF managed beans. right? :)

so, looking at this code below,
ChatView.java

Code: Select all

import javax.faces.application.FacesMessage;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.primefaces.context.RequestContext;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;

@Named
@ViewScoped
public class ChatView implements Serializable {
     
    //private final PushContext pushContext = PushContextFactory.getDefault().getPushContext();
 
   private final EventBus eventBus = EventBusFactory.getDefault().eventBus();
 
//    @ManagedProperty("com.rcent.sample.ChatUsers@ac5024")

   @Inject
    private ChatUsers users;
i knew you probably commented this out

Code: Select all

//    @ManagedProperty("com.rcent.sample.ChatUsers@ac5024")
hmmm, not only did you comment out the managed property, but you are using @Inject (CDI)

Code: Select all

//    @ManagedProperty("com.rcent.sample.ChatUsers@ac5024")

   @Inject
    private ChatUsers users;
and defining your bean as @ViewScoped

Code: Select all

@Named
@ViewScoped
public class ChatView implements Serializable {
via the following 'JSF' (managed bean) package

Code: Select all

import javax.faces.bean.ViewScoped;
import javax.inject.Named;
when you should be using JSF 2.2 CDI @ViewScoped package (below), right?

Code: Select all

import javax.faces.view.ViewScoped;
also, in ChatResource.java, i see you are doing the following:

Code: Select all

ChatUsers users= (ChatUsers) ctx.getAttribute("chatUsers");
via the following

Code: Select all

    @Inject
    private ServletContext ctx;
Honestly, i don't have [any] experience with using ServletContext to reference a bean, so I cannot confirm if 'your' code is correct or not. I am sure that if you revert from CDI to JSF managed bean, then you will have a working showcase chat app. right? :)

maybe you can search stackoverflow.com for a question/answer where BalusC has advised on using ServletContext to get a CDI managed bean. do you really need ServletContext to get a reference to a CDI managed bean? maybe some of the 'expert' users (like Andy, Ronald, or Thomas) can advise on this. :)
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

priyaesh
Posts: 26
Joined: 07 Feb 2011, 03:37

23 Apr 2014, 04:49

Actually there is'nt any significant difference between showcase-labs chat example and what I am using except the following 2 occasion. Everything else is exactly the same code.

1. Changed from JSF annotation @ManagedBean to CDI @Named
2. Changed from JSF annotation @ManagedProperty("org.primefaces.examples.push.chat.ChatUsers@ac5024") to CDI @Inject

Hope you would agree.
priyaesh

Primefaces 4, JSF 2.1, Spring 3.2, SpringSecurity 3, JPA 2.0, Tomcat 7

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

23 Apr 2014, 09:09

The viewscoped vs viewscoped is a good catch Howard, but suggesting to revert back from CDI to JSF managed beans is wrong... It should work normally with CDI and it does for me (albeit not using viewscoped)

Can you check if it works with a longer scope?

And I would never mix spring scopes and cdi scopes across beans... might still be the cause of weird behaviour.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

23 Apr 2014, 12:21

FYI,

Exception provided in OP (original post)

Code: Select all

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.rcent.sample.ChatView]: Constructor threw exception; nested exception is java.lang.NullPointerException
   at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
   at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1000)
   ... 118 more

Caused by: java.lang.NullPointerException
   at com.rcent.sample.ChatView.<init>(ChatView.java:20)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
   ... 120 more
caused by ChatView.java:20 ???

later, the exception provided was

Code: Select all

SEVERE: Servlet.service() for servlet [facesServlet] in context with path [/RcentWeb] threw exception [Error creating bean with name 'chatView' defined in file [D:\FinalGradleTest\BaseWS\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\RcentWeb\WEB-INF\classes\com\rcent\sample\ChatView.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.rcent.sample.ChatView]: Constructor threw exception; nested exception is java.lang.NullPointerException] with root cause

java.lang.NullPointerException
   at com.rcent.sample.ChatView.<init>(ChatView.java:21)
which contains

Code: Select all

java.lang.NullPointerException
   at com.rcent.sample.ChatView.<init>(ChatView.java:21)
caused by ChatView.java:21 ??? interesting.

I think ChatView.java:21 is the following

Code: Select all

   private final EventBus eventBus = EventBusFactory.getDefault().eventBus();
I think this is why Ronald suggested the following:
kukeltje wrote:The viewscoped vs viewscoped is a good catch Howard, but suggesting to revert back from CDI to JSF managed beans is wrong... It should work normally with CDI and it does for me (albeit not using viewscoped)

Can you check if it works with a longer scope?

And I would never mix spring scopes and cdi scopes across beans... might still be the cause of weird behaviour.
In my app, the following line of code is in my CDI @ApplicationScoped bean

Code: Select all

   private final EventBus eventBus = EventBusFactory.getDefault().eventBus();
since my resource is similar to the following (which contains @Singleton)

Code: Select all

@PushEndpoint("/{room}/{user}")
@Singleton
public class ChatResource {
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

jfarcand
Posts: 19
Joined: 02 Feb 2010, 20:23

23 Apr 2014, 15:06

@priyaesh Please file an issue, I will make sure it works properly with Spring in 5.0 FCS

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests