PrimeFaces推动AWS [英] PrimeFaces push with AWS

查看:163
本文介绍了PrimeFaces推动AWS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PrimeFaces 5.0和tomcat 7,并且我的应用程序在AWS中. 我正在尝试使用PrimeFaces推送.我已经实现了一个示例应用程序,它正在与我的本地系统一起使用.如果我将代码部署到AWS,它将失败.

I am using PrimeFaces 5.0 and tomcat 7 and my application is in AWS. I am trying to use PrimeFaces push. I have implemented a sample application and it is working with my local system. If i deploy the code to AWS it fails.

Xhtml代码

<p:socket onMessage="jsFunctionToCall" channel="/service/push"/>

Web.xml

 <filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
        <param-value>org.atmosphere.interceptor.ShiroInterceptor</param-value>
      </init-param>
  </filter>
  <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet>
        <servlet-name>Push Servlet</servlet-name>
        <servlet-class>org.primefaces.push.PushServlet</servlet-class>
        <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>

Java代码

@PushEndpoint("/service/push")
public class ServicePushResource {
    @OnMessage(encoders = {JSONEncoder.class})
    public String onMessage(String count) {
        return count;
    }
}

推送消息:

EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish("/service/push", String.valueOf("msg"));

我收到错误消息

WebSocket连接到'ws://example.com/primepush/service/push?X-Atmosphere-tracking-id = 0& X-Atmosphere-Framework = 2.2.4-javascript& X-Atmosphere-Transport = websocket& ; X-Atmosphere-TrackMessageSize = true& X-atmo-protocol = true'失败:WebSocket握手时出错:意外的响应代码:501

WebSocket connection to 'ws://example.com/primepush/service/push?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.4-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true' failed: Error during WebSocket handshake: Unexpected response code: 501

此错误之后,还有另一条错误消息

After this error there is another error message that

Websocket失败.降级为Comet并重新发送push.js.xhtml?ln = primefaces& v = 5.1:1 无法加载资源:服务器响应状态为501(未实现) http://example.com/primepush/service/push?X-Atmos …ng& X-Atmosphere-TrackMessageSize = true& X-atmo-protocol = true& __ = 1422008343786

Websocket failed. Downgrading to Comet and resending push.js.xhtml?ln=primefaces&v=5.1:1 Failed to load resource: the server responded with a status of 501 (Not Implemented) http://example.com/primepush/service/push?X-Atmos…ng&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true&_=1422008343786

在检查这两个错误消息时,我发现p:socket组件以"WebSocket"的形式传输失败,并且正在尝试使用"long-polling"(未实现)进行传输.所以我的问题是,如果不是,AWS是否支持"WebSocket"?

On inspecting both the error message, I found that the p:socket component is failing with transport as 'WebSocket' and it is trying with 'long-polling' which is not implemented. So my question is whether AWS support 'WebSocket' if not what is the workaround for that?

推荐答案

当前AWS不支持WebSocket.目前的工作是将AWS EB负载均衡器与TCP/SSL一起使用.我是通过在负载均衡器配置中将协议从HTTP更改为TCP来实现的.但这并不能单独起作用,在websocket的情况下,需要告诉beantalk直接与tomcat通信.可以使用配置文件来完成此操作,该配置文件可以按此指定的方式添加帖子.

Currently WebSocket is not supported with AWS. The work aroud is to use AWS EB loadbalancer with TCP/SSL. I did this by changing the protocol from HTTP to TCP in loadbalancer configuration. But this won't work alone, need to tell beanstalk to communicate directly to tomcat in case of websocket. This can be done using a configuration file which can be added as specified in this post.

这篇关于PrimeFaces推动AWS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆