使用@PathParam的PrimeFaces @PushEndpoint无法正常工作

时间:2016-10-29 03:53:36

标签: java primefaces atmosphere primefaces-push

我使用PrimeFaces 6.0和Atmosphere Run Time 2.4.3。我正在关注聊天示例,并面临着未知的'什么时候推送消息有效并且不能正常工作的问题。我一直在尝试调试,以了解问题是什么,但到目前为止没有运气。

我在这里发布了配置和代码,几乎和我们有很多例子一样。

1. pom.xml

<dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>${primefaces.version}</version>
        </dependency>

<dependency>
            <groupId>org.atmosphere</groupId>
            <artifactId>atmosphere-runtime</artifactId>
            <version>2.4.3</version>
        </dependency>

2. web.xml

<servlet>
        <servlet-name>Push Servlet</servlet-name>
        <servlet-class>org.primefaces.push.PushServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

<servlet-mapping>
        <servlet-name>Push Servlet</servlet-name>
        <url-pattern>/primepush/*</url-pattern>
    </servlet-mapping>

3. Resource class

@PushEndpoint(value="/{room}/{user}")
@Singleton
public class RoomResource {

@PathParam("room")
    private String room;

    @PathParam("user")
    private String user;



@OnOpen
    public void onOpen() {
        logger.info("onOpen {} for room {} and user {}", new String[]{endpoint.toString(), this.room, this.user});

            eventBus.publish(room + "/*", "test data");
    }

We push the message as

    eventBus.publish("/room_111" + "/*", "user data");

The output is
Sometime onOpen give output as



onOpen AtmosphereResource{
         uuid=187feb09-c9da-4b5d-afe6-5c19c0b4868b,
         transport=WEBSOCKET,
         isInScope=true,
         isResumed=false,
         isCancelled=false,
         isSuspended=true,
         broadcasters=/{room}/1234,
         isClosedByClient=false,
         isClosedByApplication=false,
         action=Action{timeout=-1, type=SUSPEND}} for room **null** and **user** null

但有时我看到空间和用户确实有正确的数据。

请提供建议和帮助。

请帮助我理解@PushEndpoint(值=&#34; / {room} / {user}&#34;)是

如果我们发送&#34; / room_1 / 123&#34;或&#34; / room_2 / 345&#34; ,这意味着我们将消息推送到同一个频道吗?

我遇到频道工作不够稳定。有时,消息不会发送给订阅频道的所有人。我完全卡住了。请帮忙。

更新: 有3个案例,其中onOpen发生

  1. 纠正一个 11:29:22 INFO [http-bio-8080-exec-7]:pad.controller.TestResource.onOpen()43 - onOpen AtmosphereResource {  UUID = e6aa499b-6962-446e-a26f-f9ca1f768335,  运输=网页套接字,  isInScope = TRUE,  isResumed =假,  isCancelled =假,  isSuspended = TRUE,  广播= / {room_112} / 9999,  isClosedByClient =假,  isClosedByApplication =假,  对于房间{room_112}和用户9999

  2. ,操作=操作{timeout = -1,type = SUSPEND}}
  3. 错误案例1 11:27:54 INFO [http-bio-8080-exec-8]:pad.controller.TestResource.onOpen()43 - onOpen AtmosphereResource {  UUID = b43d6cea-CDCD-498f-b83b-7377130f5a34,  运输=网页套接字,  isInScope = TRUE,  isResumed =假,  isCancelled =假,  isSuspended = TRUE,  广播= / {room_112}; JSESSIONID = 9082465FABC76CC67477F2BC8C513D7A / 9999,  isClosedByClient =假,  isClosedByApplication =假,  action = action {timeout = -1,type = SUSPEND}} for room {room_112}; jsessionid = 9082465FABC76CC67477F2BC8C513D7A and user 9999

  4. 错误的案例2 11:29:06 INFO [http-bio-8080-exec-2]:pad.controller.TestResource.onOpen()43 - onOpen AtmosphereResource {  UUID = a34f7912-47ac-4f22-a7d5-f56a545bcea5,  运输=网页套接字,  isInScope = TRUE,  isResumed =假,  isCancelled =假,  isSuspended = TRUE,  广播= / {room_112} / 9999,  isClosedByClient =假,  isClosedByApplication =假,  action = Action {timeout = -1,type = SUSPEND}} for room null and user null

  5. 谢谢,

0 个答案:

没有答案