我正在尝试使用Glassfish和Jersery一起使用Atmosphere聊天程序的简单example。使用java和Atmosphere的基本聊天应用程序
到目前为止,我有以下结构的基本Maven的web应用程序的原型:
聊天资源文件是只使用大气注释的简单的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丢失,但这并没有出现在这个例子中)。任何帮助,将不胜感激。
请问您可以发布您的maven pom吗?我很难编译这个:http://stackoverflow.com/questions/17331792/how-to-to-get-a-atmosphere-rest-chat-sample-to-build-in-standalone-mode – user193116