Permalink
Browse files

some tweaks. a README

  • Loading branch information...
1 parent 9662095 commit b00c1e41c99992d5e18355698c6e61eda11dfb2c @evanchooly committed Sep 27, 2011
View
@@ -0,0 +1,10 @@
+WebSockets and Java EE
+======================
+
+This project is just a prototype/proposal for how WebSocket based applications could be standardized
+inside a Java EE container. It is by no means exhaustive nor complete. What I hope to show here is
+how I've been envisioning this working over the last two years I've spent implementing the Grizzly
+and GlassFish support. It is heavily influenced by the API I've built, of course. That said, for
+me this is a starting point not a final recommendation. I do feel that it's a better basis than
+binding any WebSocket JSR to the Servlet specification directly. For more details, please see my
+blog at http://antwerkz.com/websockets-and-java-ee/
View
@@ -5,6 +5,15 @@
<groupId>org.jsr.websockets</groupId>
<artifactId>jsr-parent</artifactId>
<version>1.0-SNAPSHOT</version>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>javax</groupId>
+ <artifactId>javaee-web-api</artifactId>
+ <version>6.0</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
<packaging>pom</packaging>
<name>jsr-parent</name>
@@ -38,13 +47,4 @@
</plugins>
</pluginManagement>
</build>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
+</project>
View
@@ -18,9 +18,7 @@
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
- <version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
-
</project>
View
@@ -23,7 +23,6 @@
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
- <version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -0,0 +1,56 @@
+package org.jsr.websockets;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class DefaultWebSocket implements WebSocket {
+ public DefaultWebSocket(ServletRequest request, ServletResponse response) {
+ }
+
+ @Override
+ public void send(String data, boolean last) {
+ }
+
+ @Override
+ public void send(byte[] data, boolean last) {
+ }
+
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public void close(int code, String reason) {
+ }
+
+ @Override
+ public boolean isConnected() {
+ return false;
+ }
+
+ @Override
+ public boolean add(WebSocketListener listener) {
+ return false;
+ }
+
+ @Override
+ public boolean remove(WebSocketListener listener) {
+ return false;
+ }
+
+ @Override
+ public void onConnect() {
+ }
+
+ @Override
+ public void onMessage(String text, boolean last) {
+ }
+
+ @Override
+ public void onMessage(byte[] data, boolean last) {
+ }
+
+ @Override
+ public void onClose(int code, String reason) {
+ }
+}
@@ -1,9 +0,0 @@
-package org.jsr.websockets;
-
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-public class DefaultWebSocketContext implements WebSocketContext {
- public DefaultWebSocketContext(ServletRequest request, ServletResponse response) {
- }
-}
@@ -0,0 +1,33 @@
+package org.jsr.websockets;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.jsr.servlet.HttpUpgradeHandler;
+
+@HttpUpgradeHandler(protocol ="websocket", urlPatterns={"/sample"})
+public class SampleWebSocketContext extends WebSocketContext {
+ @Override
+ public void customizeHandshake(ServletRequest request, ServletResponse response) {
+ super.customizeHandshake(request, response);
+ // insert cookies here
+ }
+
+ @Override
+ public WebSocket createContext(ServletRequest request, ServletResponse response) {
+ return new SampleWebSocket(request, response);
+ }
+
+ private static class SampleWebSocket extends DefaultWebSocket {
+ private String userName;
+
+ public SampleWebSocket(ServletRequest request, ServletResponse response) {
+ super(request, response);
+ userName = request.getParameter("user");
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+ }
+}
@@ -0,0 +1,25 @@
+package org.jsr.websockets;
+
+public interface WebSocket {
+ void send(String data, boolean last);
+
+ void send(byte[] data, boolean last);
+
+ void close();
+
+ void close(int code, String reason);
+
+ boolean isConnected();
+
+ boolean add(WebSocketListener listener);
+
+ boolean remove(WebSocketListener listener);
+
+ void onConnect();
+
+ void onMessage(String text, boolean last);
+
+ void onMessage(byte[] data, boolean last);
+
+ void onClose(int code, String reason);
+}
@@ -1,17 +1,37 @@
package org.jsr.websockets;
-public interface WebSocketContext extends WebSocketListener {
- void send(String data, boolean last);
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
- void send(byte[] data, boolean last);
+import org.jsr.servlet.UpgradeException;
+import org.jsr.servlet.UpgradeHandler;
- void close();
+public abstract class WebSocketContext implements UpgradeHandler, WebSocketListener {
+ @Override
+ public final void doUpgrade(ServletRequest request, ServletResponse response) throws UpgradeException {
+ // websocket handshake logic done here
+ }
- void close(int code, String reason);
+ public void customizeHandshake(ServletRequest request, ServletResponse response) {
+ }
- boolean isConnected();
+ public WebSocket createContext(ServletRequest request, ServletResponse response) {
+ return new DefaultWebSocket(request, response);
+ }
- boolean add(WebSocketListener listener);
+ @Override
+ public void onConnect(WebSocket socket) {
+ }
- boolean remove(WebSocketListener listener);
+ @Override
+ public void onMessage(WebSocket socket, String text, boolean last) {
+ }
+
+ @Override
+ public void onMessage(WebSocket socket, byte[] data, boolean last) {
+ }
+
+ @Override
+ public void onClose(WebSocket socket, int code, String reason) {
+ }
}
@@ -1,11 +1,11 @@
package org.jsr.websockets;
public interface WebSocketListener {
- void onConnect();
+ void onConnect(WebSocket socket);
- void onMessage(String text, boolean last);
+ void onMessage(WebSocket socket, String text, boolean last);
- void onMessage(byte[] data, boolean last);
+ void onMessage(WebSocket socket, byte[] data, boolean last);
- void onClose(int code, String reason);
+ void onClose(WebSocket socket, int code, String reason);
}
@@ -1,23 +0,0 @@
-package org.jsr.websockets;
-
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import org.jsr.servlet.HttpUpgradeHandler;
-import org.jsr.servlet.UpgradeException;
-import org.jsr.servlet.UpgradeHandler;
-
-@HttpUpgradeHandler (protocol ="websocket", urlPatterns={"/sample"})
-public class WebSocketUpgradeHandler implements UpgradeHandler {
- @Override
- public final void doUpgrade(ServletRequest request, ServletResponse response) throws UpgradeException {
- // websocket handshake logic done here
- }
-
- public void customizeHandshake(ServletRequest request, ServletResponse response) {
- }
-
- public WebSocketContext createContext(ServletRequest request, ServletResponse response) {
- return new DefaultWebSocketContext(request, response);
- }
-}

0 comments on commit b00c1e4

Please sign in to comment.