Reputation: 235
I am trying to get a simple example of a Atmosphere chat program working with Glassfish and Jersery.
So far I have a basic maven webapp archetype with the following structure:
The chat resource file is just a simple REST service using the Atmosphere annotations:
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);
}
}
The message and response classes are just simple POJO wrappers. The index.jsp, application.js, jquery.atmosphere.js and jquery.js are copied directly from the example project (found here).
My web.xml is set to the following:
<?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>
When navigating to the page, I receive the following error:
Sorry, but there's some problem with your socket or the server is down
If I navigate to the path the page is trying to access (http://localhost:8080/.../chat), I get the following message:
org.atmosphere.cpr.AtmosphereMappingException: No AtmosphereHandler found. Make sure you define it inside META-INF/atmosphere.xml or annotate using @AtmosphereHandlerService
I must be missing a file or setup configuration, but I can't seem to find where (the above message says the atmosphere.xml is missing, but this doesn't appear in the example). Any help would be appreciated.
Upvotes: 2
Views: 3849
Reputation: 235
By default the web socket protocol is not enabled in Glassfish.
You can enable it with the following command:
asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true
This is what I needed to get my connection working.
Upvotes: 3