Unable to get dynamic path working

UI Components for JSF
Post Reply
offroadbiker
Posts: 30
Joined: 29 Nov 2012, 09:13

25 Aug 2015, 02:59

This works:

Code: Select all

            
<p:socket channel="/redirectMonitoring">
    <p:ajax event="message" oncomplete="window.location.replace('/foo.xhtml')" />
</p:socket>

Code: Select all

@PushEndpoint("/redirectMonitoring")
@Singleton
public class RedirectMonitorResource {
    @OnMessage() public void onMessage(Boolean ignore) {}
}

Code: Select all

@Model
public class RedirectBean {
    public void redirect() {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        eventBus.publish("/redirectMonitoring", Boolean.TRUE);
    }
}
But when I try to make the path dynamic as follows:

Code: Select all

            
<p:socket onMessage="handleMessage" channel="/redirectMonitoring/{sessionId}" autoConnect="false" widgetVar='subscriber'/>
<script type="text/javascript">
    function handleMessage(message) {
        window.location.replace(message);
    }
</script>

Code: Select all

@Model
public class LoginController {
    private void onLogin(@Observes @LoggedIn User loggedInUser) {
        RequestContext.getCurrentInstance().execute(
            "PF('subscriber').connect('/redirectMonitoring/" + WebUtil.getSession().getId() + "')"
        );
    }
}

Code: Select all

@PushEndpoint("/redirectMonitoring/{sessionId}")
@Singleton
public class RedirectMonitorResource {
    @PathParam("sessionId") private String sessionId;

    @OnMessage(encoders = {JSONEncoder.class}) public String onMessage(String message) { return message; }
}

Code: Select all

@Model
public class RedirectBean {
    public void redirect(String sessionId) {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        eventBus.publish("/redirectMonitoring/" + sessionId, "/foo.xhtml");
    }
}
The web browser does not load /foo.xhtml and I get the following error in the log:

20:12:24,811 ERROR [org.atmosphere.container.JSR356Endpoint] (default I/O-5) : java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method) [rt.jar:1.8.0_05]
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43) [rt.jar:1.8.0_05]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) [rt.jar:1.8.0_05]
at sun.nio.ch.IOUtil.read(IOUtil.java:192) [rt.jar:1.8.0_05]
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:375) [rt.jar:1.8.0_05]
at org.xnio.nio.NioSocketConduit.read(NioSocketConduit.java:280) [xnio-nio-3.2.2.Final.jar:3.2.2.Final]
at org.xnio.conduits.AbstractStreamSourceConduit.read(AbstractStreamSourceConduit.java:51) [xnio-api-3.2.2.Final.jar:3.2.2.Final]
at org.xnio.ssl.JsseSslStreamSourceConduit.read(JsseSslStreamSourceConduit.java:84) [xnio-api-3.2.2.Final.jar:3.2.2.Final]
at io.undertow.conduits.IdleTimeoutConduit.read(IdleTimeoutConduit.java:144)
at org.xnio.conduits.ConduitStreamSourceChannel.read(ConduitStreamSourceChannel.java:127) [xnio-api-3.2.2.Final.jar:3.2.2.Final]
at io.undertow.server.protocol.framed.AbstractFramedChannel.receive(AbstractFramedChannel.java:244)
at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:20)
at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:15)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) [xnio-api-3.2.2.Final.jar:3.2.2.Final]
at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:632)
at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:618)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) [xnio-api-3.2.2.Final.jar:3.2.2.Final]
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) [xnio-api-3.2.2.Final.jar:3.2.2.Final]
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:87) [xnio-nio-3.2.2.Final.jar:3.2.2.Final]
at org.xnio.nio.WorkerThread.run(WorkerThread.java:539) [xnio-nio-3.2.2.Final.jar:3.2.2.Final]

P.S. I did set breakpoints to ensure that the session id in

Code: Select all

 "PF('subscriber').connect('/redirectMonitoring/" + WebUtil.getSession().getId() + "')"
matched the session id in

Code: Select all

eventBus.publish("/redirectMonitoring/" + sessionId, "/foo.xhtml");
Any suggestions/pointers/advice would be greatly appreciated! :D
primefaces-5.2
primefaces-extensions-3.2.0
atmosphere-runtime-2.3.4
Mojarra 2.2.6
wildfly-8.1.0.Final

offroadbiker
Posts: 30
Joined: 29 Nov 2012, 09:13

27 Aug 2015, 20:38

The solution was to change p:socket channel attribute as follows:

Code: Select all

<p:socket channel="/redirectMonitoring/{sessionId}" ... />
to this:

Code: Select all

<p:socket channel="/redirectMonitoring/#{session.id}" ... />
primefaces-5.2
primefaces-extensions-3.2.0
atmosphere-runtime-2.3.4
Mojarra 2.2.6
wildfly-8.1.0.Final

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 34 guests