Upgrade from Primefaces 4.0 to 5.0 push

UI Components for JSF
Post Reply
hkykid
Posts: 11
Joined: 19 Oct 2012, 14:51

13 May 2014, 15:01

I have been trying to upgrade from PF 4.0/Atmosphere 2.0.2 to PF 5.0/Atmosphere 2.1.3. I noticed in the changedoc that the PushContext is deprecated, but when I upgrade and try to use the features that utilize push on the site nothing happens. I've also noticed in the server log the message "No Annotated class using @PushEndpoint found. Push will not work.".

This message makes sense as I have not updated any of the code, but I at least thought that the way I have things set up would work for the time being. I dug through the Primefaces jar and found that in the PushServlet the PrimeAtmosphereHandler was being added like this

Code: Select all

this.framework.interceptor(new AtmosphereResourceLifecycleInterceptor()).addAtmosphereHandler("/*", new PrimeAtmosphereHandler(configureRules(sc))).initAtmosphereHandler(sc);
In the PF 5.0 jar, however, I could not find this and would explain the warning I receive. My question therefore is, is there an easy way to register this handler either in code or through the web.xml so that I can at least have push working initially?

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

14 May 2014, 19:21

Can you elaboare more? Normally old application should still work as it is.

rikup
Posts: 459
Joined: 29 Jan 2013, 14:27

14 May 2014, 21:40

Are you using EAR? If yes, where are Atmosphere JARs and PF JAR?
PrimeNG 2.0.0
Angular 2.4.5

hkykid
Posts: 11
Joined: 19 Oct 2012, 14:51

15 May 2014, 15:28

jfarcand wrote:Can you elaboare more? Normally old application should still work as it is.
I am using GlassFish3 and am deploying my website as an OSGi bundle. I've had push working from PF 3.4 and PF 4.0.
In my application I declare a p:socket on a template page that all pages share as follows:

Code: Select all

<p:socket widgetVar="messageSocket" channel="#{pushChannelConstants.messageChannel}" onMessage="messageRouterFunction" autoConnect="false"/>
I handle connecting via the socket in a separate Javascript file.

My web.xml has the following items pertaining to push:

Code: Select all

<!-- This is for the required servlet for PrimeFaces push.  -->
    <servlet>
        <servlet-name>Push Servlet</servlet-name>
        <servlet-class>org.primefaces.push.PushServlet</servlet-class>
        
        <!-- This appears to be a new option as of atmosphere 1.0.12. The property specifies
             if order of message delivered to the client is not important. Default is false. -->
        <init-param>
            <param-name>org.atmosphere.cpr.Broadcaster.supportOutOfOrderBroadcast</param-name>
            <param-value>true</param-value>
        </init-param>
        
        <init-param>
            <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
            <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
        </init-param>
        
        <init-param>
            <param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
            <param-value>org.atmosphere.client.TrackMessageSizeInterceptor</param-value>
        </init-param>
        
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>Push Servlet</servlet-name>
        <url-pattern>/primepush/*</url-pattern>
    </servlet-mapping>
And in my server side code I use the PushContext to send out messages to the channel defined above.

On my switch from PF 4.0 to PF 5.0, I swapped out the jars for PF 4.0 and Atmosphere 2.0.2 with PF 5.0 and Atmosphere 2.1.3. I have not updated the code to have a PushEndpoint. When I try to run the web bundle on loading of the bundle I see a warning that says "No Annotated class using @PushEndpoint found. Push will not work.".

When trying to perform actions on the web pages, none of the push aspects work. I do not see any of the messages being pushed to my browser when I try to debug, but I do not see any kind of server errors.

In the PushServlet class in PF 3.4 and PF 4.0, it appears that a PrimeAtmosphereHandler is registered automatically. Below is the snippet of the PF 4.0 PushServlet:

Code: Select all

public class PushServlet extends AtmosphereServlet
{
  private final Logger logger = Logger.getLogger(PushServlet.class.getName());
  public static final String RULES = "org.primefaces.push.rules";

  public void init(ServletConfig sc)
    throws ServletException
  {
    PushContext c = PushContextFactory.getDefault().getPushContext();
    if (PushContextImpl.class.isAssignableFrom(c.getClass())) {
      framework().asyncSupportListener((AsyncSupportListener)PushContextImpl.class.cast(c));
    }

    super.init(sc);

    this.framework.interceptor(new AtmosphereResourceLifecycleInterceptor()).interceptor(new HeartbeatInterceptor()).interceptor(new TrackMessageSizeInterceptor()).interceptor(new SuspendTrackerInterceptor()).addAtmosphereHandler("/*", new PrimeAtmosphereHandler(configureRules(sc))).initAtmosphereHandler(sc);
  }
In the PF 5.0 jar, I could not find any sort of registering for this handler. I suspect that is why I am not seeing any of the push messages and why I see the server error. So my question basically is, do I have to have an @PushEndpoint or is there a way that I can register the PrimeAtmosphereHandler to see if that fixes my problem? Ultimately, my confusion stems from the fact that the migration guide indicates that the PushContext is deprecated. I was assuming that Push would at least work for the time being for the upgrade and then I could work on restructuring my code to use an @PushEndpoint.

rikup
Posts: 459
Joined: 29 Jan 2013, 14:27

15 May 2014, 19:20

I had same problem with EAR because I had skinny WAR and I had PF and Atmosphere inside EAR, not inside WAR. When I moved PF and Atmosphere to WAR everything started to work. I think you might have similar issue with OSGi, but I haven't never tried deployment like yours. With EAR, the problem was that web annotation weren't executed from EAR libraries.

And IMO yes, you must have @PushEndpoint.
PrimeNG 2.0.0
Angular 2.4.5

hkykid
Posts: 11
Joined: 19 Oct 2012, 14:51

16 May 2014, 14:57

rikup wrote:I had same problem with EAR because I had skinny WAR and I had PF and Atmosphere inside EAR, not inside WAR. When I moved PF and Atmosphere to WAR everything started to work. I think you might have similar issue with OSGi, but I haven't never tried deployment like yours. With EAR, the problem was that web annotation weren't executed from EAR libraries.

And IMO yes, you must have @PushEndpoint.
rikup, thanks for your replies. I am fairly certain that atmosphere/primefaces deploys correctly. It is probably just that I don't have a push endpoint.

hkykid
Posts: 11
Joined: 19 Oct 2012, 14:51

16 May 2014, 19:49

So I tried updating to use a @PushEndpoint like so

Code: Select all

@PushEndpoint("/messages")
public class SimplePushEndpoint
{
    @OnOpen
    public void onOpen()
    {
        
    }
    
    @OnMessage(encoders = {JSONEncoder.class})
    public String onMessage(String message)
    {
        return message;
    }
}

and replaced my PushContext references with EventBus references but now I receive the following errors:

Code: Select all

[#|2014-05-16T13:38:19.323-0400|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=349;_ThreadName=http-thread-pool-8180(5);|[http-thread-pool-8180(5)] WARN org.atmosphere.websocket.DefaultWebSocketProcessor - AtmosphereResource was null|#]
followed by

Code: Select all

[#|2014-05-16T13:38:19.311-0400|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=349;_ThreadName=http-thread-pool-8180(5);|java.lang.NullPointerException
	at com.sun.grizzly.tcp.http11.InternalInputBuffer.fill(InternalInputBuffer.java:820)
	at com.sun.grizzly.tcp.http11.InternalInputBuffer$InputStreamInputBuffer.doRead(InternalInputBuffer.java:873)
	at com.sun.grizzly.tcp.http11.InternalInputBuffer.doRead(InternalInputBuffer.java:789)
	at com.sun.grizzly.tcp.Request.doRead(Request.java:501)
	at com.sun.grizzly.tcp.http11.GrizzlyInputBuffer.realReadBytes(GrizzlyInputBuffer.java:327)
	at com.sun.grizzly.util.buf.ByteChunk.substract(ByteChunk.java:436)
	at com.sun.grizzly.tcp.http11.GrizzlyInputBuffer.read(GrizzlyInputBuffer.java:349)
	at com.sun.grizzly.tcp.http11.GrizzlyInputStream.read(GrizzlyInputStream.java:236)
	at com.sun.grizzly.http.servlet.ServletInputStreamImpl.read(ServletInputStreamImpl.java:99)
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
	at java.io.InputStreamReader.read(InputStreamReader.java:184)
	at java.io.BufferedReader.read1(BufferedReader.java:203)
	at java.io.BufferedReader.read(BufferedReader.java:279)
	at java.io.Reader.read(Reader.java:140)
	at org.atmosphere.util.IOUtils.readEntirely(IOUtils.java:77)
	at org.primefaces.push.impl.PushEndpointHandlerProxy.onRequest(PushEndpointHandlerProxy.java:150)
	at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:174)
	at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:95)
	at org.atmosphere.container.GrizzlyServlet30WebSocketSupport.service(GrizzlyServlet30WebSocketSupport.java:73)
	at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1805)
	at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:432)
	at org.atmosphere.websocket.DefaultWebSocketProcessor.open(DefaultWebSocketProcessor.java:186)
	at org.atmosphere.container.GlassFishWebSocketHandler.onConnect(GlassFishWebSocketHandler.java:132)
	at com.sun.grizzly.websockets.DefaultWebSocket.onConnect(DefaultWebSocket.java:140)
	at com.sun.grizzly.websockets.WebSocketEngine.upgrade(WebSocketEngine.java:189)
	at com.sun.grizzly.websockets.WebSocketAsyncFilter.doFilter(WebSocketAsyncFilter.java:54)
	at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171)
	at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143)
	at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:102)
	at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193)
	at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175)
	at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145)
	at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:210)
	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
	at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
	at java.lang.Thread.run(Thread.java:744)
|#]
I did not alter my web.xml or any of the other files and I am using GlassFish 3. Does anyone have any ideas of what this could mean?

GregTom
Posts: 1
Joined: 17 Oct 2014, 15:22

17 Oct 2014, 15:38

Did you managed to solve the problem?

Now I am trying to migrate my application from PF 4.0 to 5.1, but push is not working. In a small test project I have made the simple counter example that is in the Primefaces showcase, but it is not working. There is no any error message in the server log. Just the push message does not reach the browser.

I tried it with Glassfish 3 , Glassfish 4 and TomEE 1.7.1 but it works nowhere.
I have @PushEndpoint class, correclty defined servlet in the web.xml, eventBus.publish() is running without error, but the message is not reaching the browser.
I tried async-supported on/off, load-on-startup 1/0.
I tried both primefaces-5.0 and primefaces-5.1.
I tried atmosphere-runtime-2.2.2.jar and atmosphere-runtime-2.2.3.jar.

But there was no any configuration that could help.

I am totally stuck. Was anybody in the same situation? Is there any idea?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests