0

I'm developing chat app using OmniFaces version 2.7 o:socket and it works like a charm when I deploy it to WildFly 13.0.0 Final but it won't deploy on WebLogic Server Version: 12.2.1.3.0.

Here is the stack trace I'm getting:

Caused By: java.lang.NullPointerException
        at org.omnifaces.cdi.push.Socket.registerEndpointIfNecessary(Socket.java:976)
        at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:86)
        at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:705)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:328)
        at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
        at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
        at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
        at weblogic.servlet.internal.EventsManager.executeContextListener(EventsManager.java:251)
        at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:204)
        at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:189)
        at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1921)
        at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3106)
        at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1843)
        at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:884)
        at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
        at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)

I have added socket endpoint enabled to my web.xml

    <context-param>
        <param-name>org.omnifaces.SOCKET_ENDPOINT_ENABLED</param-name>
        <param-value>true</param-value>
    </context-param>

I have created minmal example that reproduces the code. Here is the source:

Here is my bean that holds all the messages:

@Data
@Named
@ApplicationScoped
public class ChatContentBean {

    private List<ChatMessage> chatMessages;

    @Inject
    @Push
    private PushContext someChannel;

    @PostConstruct
    public void init() {
        chatMessages = new ArrayList<>();
    }

    public void clearHistory() {
        chatMessages = new ArrayList<>();
    }

    public void onPageView(@Observes ChatMessage pageView) {
        chatMessages.add(pageView);
        someChannel.send(pageView);
    }

}

My backing bean:

@Log4j
@Data
@Named
@ViewScoped
@Interceptors({ExceptionInterceptor.class})
public class ChatViewBean extends SomeOtherContentPage {

    private String chatMessage;

    @Inject
    @Push
    private PushContext someChannel;

    @Inject
    private BeanManager beanManager;

    @Inject
    private ChatContentBean chatContentBean;

    @Override
    @PostConstruct
    public void init() {
        super.init();
    }

    public void clearHistory() {
        chatContentBean.clearHistory();
    }

    public void sendMessage() {
        ChatMessage cm = new ChatMessage(chatMessage, AuthContext.getUser().displayName());
        someChannel.send(cm);
        beanManager.fireEvent(cm);

        chatMessage = null;
    }

}

And part of my xhtml:

            <o:socket channel="someChannel" onmessage="updateStatsRc"/>

            <h:panelGroup id="chat">

                <ui:repeat value="#{chatContentBean.chatMessages}" var="chatElement">
                    <p:panelGrid columns="1">
                        <h:outputText value="#{chatElement.user} #{chatElement.timestamp} #{chatElement.message}"/>
                    </p:panelGrid>
                </ui:repeat>


            </h:panelGroup>

            <p:remoteCommand name="updateStatsRc" update="chat"/>

            <h:inputText id="chat_input_text" value="#{chatViewBean.chatMessage}"/>
            <p:commandButton value="Send" update="chat_input_text" action="#{chatViewBean.sendMessage()}"/>

            <p:commandButton value="Clear chat history" action="#{chatViewBean.clearHistory()}" update="chat"/>

        </h:form>

And my ChatMessage class:

@Data
public class ChatMessage {

    private String message;
    private String timestamp;
    private String user;

    public ChatMessage(String message, String user) {
        this.message = message;
        timestamp = LocalDateTime.now().toString();
        this.user = user;
    }
}

I allso tryed to add org.omnifaces.ApplicationListener to web.xml but it doesnt change anything.

Any ideas why it won't deploy to weblogic but it works on wildfly?

Kiki
  • 2,243
  • 5
  • 30
  • 43
  • So you set a breakpoint in the omnifaces class that throws the NPE and checked what actually is null? – Kukeltje Jun 05 '20 at 17:26
  • And if you remove the xhtml file, it deploys? I'm asking since there is nothing jsf related in the stacktrace but there is a cdi related class in there. And is this the full stacktrace? – Kukeltje Jun 05 '20 at 17:40
  • It deploys only if i remove org.omnifaces.SOCKET_ENDPOINT_ENABLED from web.xml but the page crashes once I open it. And then there is an error saying i need to add this configuration. – Kiki Jun 05 '20 at 17:58
  • So it is not jsf related but cdi? – Kukeltje Jun 05 '20 at 18:01
  • Yes looks like it. I'll fix the tags – Kiki Jun 05 '20 at 18:02
  • Thanks, and post omnifaces version please. And do as requested in my first comment. Otherwise https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it is a valid 'duplicate' – Kukeltje Jun 05 '20 at 18:16
  • Its not a duplicate... since it works on one environment and not on the other. It must be a missing configuration or something. And i can't debug the class since I can't remote debug to the server. But locally on Wildfly its working. Btw i updated the question with omnifaces vesion. Its 2.7 – Kiki Jun 05 '20 at 21:11
  • OmniFaces is open source. Based on source code, a NPE on [line 976 of Socket class in OmniFaces 2.7](https://github.com/omnifaces/omnifaces/blob/2.7/src/main/java/org/omnifaces/cdi/push/Socket.java#L976) indicates that javax.websocket.ServerContainer is unexpectedly null. In other words, a bug in WebLogic. This related issue in another library suggests that this might happen when you use JDK7 instead of JDK8 on WebLogic: https://github.com/Atmosphere/atmosphere/issues/1856 Which JDK version are you using? – BalusC Jun 05 '20 at 22:48
  • On the other hand, WebLogic is payware so you should basically push and ask them to fix this. I.e. make sure you get what you paid for. – BalusC Jun 05 '20 at 22:53

0 Answers0