我正在尝试运行Primefaces Nofity与websphere 8.5下面是文件和错误的详细信息,只是坚持做任何事情,因为没有错误在ide控制台只是浏览器控制台错误和p:套接字根本没有触发
下面的代码适用于tomcat但不适用于web-sphere
A)web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Notify</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<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.annotation.packages</param-name>
<param-value>org.primefaces.push.annotation</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.broadcasterClass</param-name>
<param-value>org.atmosphere.cpr.DefaultBroadcaster</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.packages</param-name>
<param-value>com.notify.sample</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.sessionSupport</param-name>
<param-value>true</param-value>
</init-param>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
</web-app>
B)faces-config.xml为
<?xml version="1.0" encoding="utf-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
C)NotifyResource.java
package com.notify.sample;
import javax.faces.application.FacesMessage;
import org.primefaces.push.EventBus;
import org.primefaces.push.RemoteEndpoint;
import org.primefaces.push.annotation.OnClose;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.OnOpen;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;
@PushEndpoint("/notify")
public class NotifyResource {
@OnOpen
public void onOpen( RemoteEndpoint r, EventBus e ) {
}
@OnClose
public void onClose( RemoteEndpoint r, EventBus e ) {
}
@OnMessage(encoders = {JSONEncoder.class})
public FacesMessage onMessage(FacesMessage message) {
return message;
}
}
D)NotifyView.java
package com.notify.sample;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.apache.commons.lang.StringEscapeUtils;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;
@ManagedBean
@RequestScoped
public class NotifyView {
private final static String CHANNEL = "/notify";
/** The Constant LOGGER. */
private String summary;
private String detail;
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public void send() {
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
}
}
E)notify.xhrml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:csxc="http://java.sun.com/jsf/composite/csxcomponent"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script type="text/javascript">
function handleMessage(facesmessage) {
facesmessage.severity = 'info';
PF('growl').show([facesmessage]);
}
</script>
</h:head>
<h:body>
<center>
<p:panel header="Notify Form" style="width: 350;">
<p:growl widgetVar="growl" showDetail="true" />
<h:form>
<h:panelGrid columns="2">
<p:outputLabel for="summary" value="Summary: " />
<p:inputText id="summary" value="#{notifyView.summary}" required="true" />
<p:outputLabel for="detail" value="Detail: " />
<p:inputText id="detail" value="#{notifyView.detail}" required="true" />
</h:panelGrid>
<p:commandButton value="Send" actionListener="#{notifyView.send}" />
</h:form>
<p:socket onMessage="handleMessage" channel="/notify" />
</p:panel>
</center>
</h:body>
</html>
F)web-inf / lib
G)index.jsp
<jsp:forward page="notify.jsf"></jsp:forward>
浏览器控制台错误
Tue May 17 2016 22:11:52 GMT+0530 (India Standard Time) Atmosphere: unload event push.js.jsf:1:39484
GET
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 5ms]
Firefox can't establish a connection to the server at ws://localhost:9080/app_notify/primepush/notify?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.9-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true. push.js.jsf:1:12442
Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). push.js.jsf:1:39484
Websocket closed, wasClean: false push.js.jsf:1:39484
Websocket failed. Downgrading to Comet and resending push.js.jsf:1:39484
GET
XHR
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
GET
XHR
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 1ms]
GET
XHR
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
GET
XHR
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
GET
XHR
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
GET
XHR
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
答案 0 :(得分:0)
所以我们可以标记为已回答,我认为问题的症结在于(正确地,在我看来)氛围依赖于底层服务器来支持websockets。
该应用程序适用于WebSphere Liberty,它支持WebSockets。
它不适用于WebSphere传统v8.5,后者没有。
如果使用WebSphere的传统配置文件很重要,那么WebSphere traditional支持测试版中提供的WebSockets。