2012-10-22 49 views
2

我正在嘗試使用Glassfish和Jersery一起使用Atmosphere聊天程序的簡單example使用java和Atmosphere的基本聊天應用程序

到目前爲止,我有以下結構的基本Maven的web應用程序的原型:

project setup

聊天資源文件是隻使用大氣註釋的簡單的REST服務:

package core; 

import javax.ws.rs.GET; 
import javax.ws.rs.POST; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 

import org.atmosphere.annotation.Broadcast; 
import org.atmosphere.annotation.Suspend; 

@Path("/") 
public class ChatResource { 

    @Suspend(contentType = "application/json") 
    @GET 
    public String suspend() { 
     return ""; 
    } 

    @Broadcast(writeEntity = false) 
    @POST 
    @Produces("application/json") 
    public Response broadcast(Message message) { 
     return new Response(message.author, message.message); 
    } 
} 

的消息和響應類只是簡單的POJO包裝。 index.jsp,application.js,jquery.atmosphere.js和jquery.js直接從示例項目中複製(找到here)。

我的web.xml文件中設置如下:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

    <display-name>Archetype Created Web Application</display-name> 
    <servlet> 
     <description>AtmosphereServlet</description> 
     <servlet-name>AtmosphereServlet</servlet-name> 
     <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class> 
     <load-on-startup>0</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>AtmosphereServlet</servlet-name> 
     <url-pattern>/chat/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

當瀏覽網頁,我收到以下錯誤:

Sorry, but there's some problem with your socket or the server is down

如果我瀏覽到該路徑的網頁正試圖訪問(http://localhost:8080/.../chat),我得到以下信息:

org.atmosphere.cpr.AtmosphereMappingException: No AtmosphereHandler found. Make sure you define it inside META-INF/atmosphere.xml or annotate using @AtmosphereHandlerService

我必須缺少一個文件Ø r設置配置,但我似乎無法找到在哪裏(上面的消息說atmosphere.xml丟失,但這並沒有出現在這個例子中)。任何幫助,將不勝感激。

回答

3

默認情況下,Glassfish中未啓用Web套接字協議。

你可以用下面的命令啓用它:

asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true 

這是我需要讓我的連接工作。

+0

請問您可以發佈您的maven pom嗎?我很難編譯這個:http://stackoverflow.com/questions/17331792/how-to-to-get-a-atmosphere-rest-chat-sample-to-build-in-standalone-mode – user193116