Hi,
what exactly you see in the console, when you try to enable websockets using
./asadmin start-server" and then i tried "./asadmin set
configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true
?
Thanks.
WBR,
Alexey.
On 01/17/2012 03:35 PM, forums_at_java.net wrote:
> Hi,
>
> i want to develop an websocket application. I already developed an
> websocket
> client using weberknecht-websockets and tested it with an server
> implementation using jetty webserver and it works great!
>
> Now i want to try out glassfish. I read that glassfish 3.1.1 supports
> websockets. So i googled a lot and found a few tutorials which
> describes how
> to implement the server side for websockets for glassfish.
>
> My Server Side Implementation looks like:
>
> *WebSocketServlet:*
>
> [java]
>
> package de.gfwebsocket;
> import java.io.IOException;
> import java.io.PrintWriter;
> import java.text.SimpleDateFormat;
> import java.util.Date;
> import javax.servlet.ServletConfig;
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import com.sun.grizzly.websockets.WebSocketEngine;
> /**
> * Servlet implementation class WebSocketServlet
> */
> public class WebSocketServlet extends HttpServlet {
> private static final long serialVersionUID = 1L;
>
> public WebSocketServlet() {
> super();
> // TODO Auto-generated constructor stub
> }
>
> public void init(ServletConfig config) throws ServletException {
> // TODO Auto-generated method stub
> WebSocketEngine.getEngine().register(new
> WebSocketConnection());
> }
>
> protected void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy
> HH:mm:ss");
> PrintWriter writer = response.getWriter();
> writer.println("<html>");
> writer.println("<head><title>Hello World
> Servlet</title></head>");
> writer.println("<body>");
> writer.println("<h1>Es ist der " + format.format(new Date()) +
> " Uhr</h1>");
> writer.println("<body>");
> writer.println("</html>");
> writer.flush();
> writer.close();
> }
> protected void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> // TODO Auto-generated method stub
> }
> }
> [/java]
>
> *WebSocketConnection*
>
> [java]package de.gfwebsocket;
> import com.sun.grizzly.tcp.Request;
> import com.sun.grizzly.websockets.WebSocket;
> import com.sun.grizzly.websockets.WebSocketApplication;
> import com.sun.grizzly.websockets.WebSocketListener;
> public class WebSocketConnection extends WebSocketApplication{
> @Override
> public WebSocket createSocket(WebSocketListener... listeners) {
> // TODO Auto-generated method stub
> return new WebSocketDataProcess(listeners);
> }
> @Override
> public void onClose(WebSocket socket) {
> // TODO Auto-generated method stub
> super.onClose(socket);
> }
> @Override
> public void onConnect(WebSocket socket) {
> // TODO Auto-generated method stub
> super.onConnect(socket);
> }
> @Override
> public void onMessage(WebSocket socket, String text) {
> socket.send(text);
> //super.onMessage(socket, text);
> }
>
>
> // return true if you want to communicate over websocket otherwise
> return false
> @Override
> public boolean isApplicationRequest(Request arg0) {
> // TODO Auto-generated method stub
> return true;
> }
> }[/java]
>
> *WebSocketDataProcess*
>
> [java]
>
> package de.gfwebsocket;
> import com.sun.grizzly.websockets.BaseServerWebSocket;
> import com.sun.grizzly.websockets.WebSocketListener;
> public class WebSocketDataProcess extends BaseServerWebSocket{
>
> public WebSocketDataProcess(WebSocketListener... listeners) {
> // TODO Auto-generated constructor stub
> super(listeners);
> }
> }[/java]
>
> I exported this project as an .war-File and deployed it in GlassFish
> via web
> console. I tried to reach it by using firefox and it showed me the actual
> time as expected.
>
> But if i try my client to connect with the websocket server, it
> failed. I get
> an exception on client side: "connection failed: unknown status code
> 200".
> My Client works with WebSocket. As i said, i tested it with a jetty
> websocket
> server implementation.
>
> So i tried to enable websockets in glassfish 3.1.1. I started the
> server with
> "./asadmin start-server" and then i tried "./asadmin set
> configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true".
>
> But "set" failed and it does not work.
>
>
>
> So, can anybody help me?
>
> Thank you for your help in advance.
>
> Best regards
>
> hsch
>
>
>
>
> --
>
> [Message sent by forum member 'hsch']
>
> View Post: http://forums.java.net/node/882757
>
>