Skip to content

Commit aee8aa7

Browse files
author
Mathieu Carbou
committed
Merge remote branch 'remotes/upstream/master'
Conflicts: core/src/main/java/com/glines/socketio/server/SocketIOInbound.java
2 parents 1b9dda4 + 66fdd46 commit aee8aa7

File tree

9 files changed

+56
-119
lines changed

9 files changed

+56
-119
lines changed

core/src/main/java/com/glines/socketio/server/SocketIOInbound.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,32 @@
2222
*/
2323
package com.glines.socketio.server;
2424

25-
import javax.servlet.http.HttpServletRequest;
26-
2725
import com.glines.socketio.common.DisconnectReason;
2826

2927
public interface SocketIOInbound {
3028

31-
/**
32-
* Called when the connection is established. This will only ever be called once.
33-
* @param outbound The SocketOutbound associated with the connection
34-
*/
35-
void onConnect(SocketIOOutbound outbound);
36-
37-
/**
38-
* Called when the socket connection is closed. This will only ever be called once.
39-
* This method may be called instead of onConnect() if the connection handshake isn't
40-
* completed successfully.
41-
* @param reason The reason for the disconnect.
42-
* @param errorMessage Possibly non null error message associated with the reason for disconnect.
43-
*/
44-
void onDisconnect(DisconnectReason reason, String errorMessage);
29+
/**
30+
* Called when the connection is established. This will only ever be called once.
31+
*
32+
* @param outbound The SocketOutbound associated with the connection
33+
*/
34+
void onConnect(SocketIOOutbound outbound);
4535

36+
/**
37+
* Called when the socket connection is closed. This will only ever be called once.
38+
* This method may be called instead of onConnect() if the connection handshake isn't
39+
* completed successfully.
40+
*
41+
* @param reason The reason for the disconnect.
42+
* @param errorMessage Possibly non null error message associated with the reason for disconnect.
43+
*/
44+
void onDisconnect(DisconnectReason reason, String errorMessage);
4645

47-
/**
48-
* Called one per arriving message.
49-
* @param messageType
50-
* @param message
51-
* @param parseError
52-
*/
53-
void onMessage(int messageType, String message);
46+
/**
47+
* Called one per arriving message.
48+
*
49+
* @param messageType
50+
* @param message
51+
*/
52+
void onMessage(int messageType, String message);
5453
}

core/src/main/java/com/glines/socketio/server/SocketIOOutbound.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public interface SocketIOOutbound {
3838
* Initiate an orderly close of the connection. The state will be changed to CLOSING so no
3939
* new messages can be sent, but messages may still arrive until the distant end has
4040
* acknowledged the close.
41-
*
42-
* @param closeType
4341
*/
4442
void close();
4543

@@ -52,16 +50,17 @@ public interface SocketIOOutbound {
5250
* the SocketClosedException will be thrown.
5351
*
5452
* @param message The message to send
55-
* @throws com.glines.socketio.common.SocketIOException
53+
* @throws SocketIOException
5654
*/
5755
void sendMessage(String message) throws SocketIOException;
5856

5957
/**
6058
* Send a message.
6159
*
60+
* @param messageType
6261
* @param message
6362
* @throws IllegalStateException if the socket is not CONNECTED.
64-
* @throws SocketIOMessageParserException if the message type parser encode() failed.
63+
* @throws SocketIOException
6564
*/
6665
void sendMessage(int messageType, String message) throws SocketIOException;
6766
}

core/src/main/java/com/glines/socketio/server/SocketIOSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ interface SessionTask {
109109

110110
/**
111111
* Pass disconnect through to contained SocketIOInbound and update any internal state.
112-
* @param message
112+
* @param reason
113113
*/
114114
void onDisconnect(DisconnectReason reason);
115115

core/src/main/java/com/glines/socketio/server/transport/AbstractHttpTransport.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ public void handle(HttpServletRequest request,
7474

7575
Object obj = request.getAttribute(SESSION_KEY);
7676
SocketIOSession session = null;
77+
String sessionId = null;
7778
if (obj != null) {
7879
session = (SocketIOSession)obj;
7980
} else {
80-
String sessionId = extractSessionId(request);
81-
if (sessionId != null) {
81+
sessionId = extractSessionId(request);
82+
if (sessionId != null && sessionId.length() > 0) {
8283
session = sessionFactory.getSession(sessionId);
8384
}
8485
}
@@ -89,16 +90,18 @@ public void handle(HttpServletRequest request,
8990
handler.handle(request, response, session);
9091
} else {
9192
session.onShutdown();
92-
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
93+
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
9394
}
95+
} else if (sessionId != null && sessionId.length() > 0) {
96+
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
9497
} else {
9598
if ("GET".equals(request.getMethod())) {
96-
session = connect(request, response, inboundFactory, sessionFactory);
97-
if (session == null) {
98-
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
99-
}
99+
session = connect(request, response, inboundFactory, sessionFactory);
100+
if (session == null) {
101+
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
102+
}
100103
} else {
101-
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
104+
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
102105
}
103106
}
104107
}

core/src/main/java/com/glines/socketio/server/transport/WebSocketTransport.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ public void onConnect(final Outbound outbound) {
6868
this.outbound = outbound;
6969
}
7070

71-
@Override
72-
public void onFragment(boolean more, byte opcode, byte[] data, int offset, int length) {
73-
throw new UnsupportedOperationException();
74-
}
75-
7671
/*
7772
* (non-Javadoc)
7873
* @see org.eclipse.jetty.websocket.WebSocket#onDisconnect()
@@ -129,6 +124,11 @@ public void onMessage(byte frame, byte[] data, int offset, int length) {
129124
}
130125
}
131126

127+
@Override
128+
public void onFragment(boolean more, byte opcode, byte[] data, int offset, int length) {
129+
throw new UnsupportedOperationException();
130+
}
131+
132132
/*
133133
* (non-Javadoc)
134134
* @see com.glines.socketio.SocketIOInbound.SocketIOOutbound#disconnect()

core/src/main/java/com/glines/socketio/server/transport/XHRMultipartTransport.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ private class XHRMultipartSessionHelper extends XHRSessionHelper {
5757
protected void startSend(HttpServletResponse response) throws IOException {
5858
response.setContentType(contentType);
5959
response.setHeader("Connection", "keep-alive");
60-
char[] spaces = new char[244];
61-
Arrays.fill(spaces, ' ');
6260
ServletOutputStream os = response.getOutputStream();
6361
os.print(boundarySeperator);
6462
response.flushBuffer();

core/src/main/java/com/glines/socketio/server/transport/XHRTransport.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void sendMessage(SocketIOFrame frame)
119119
} catch (IOException e) {
120120
throw new SocketIOException(e);
121121
}
122-
if (!isConnectionPersistant) {
122+
if (!isConnectionPersistant && !continuation.isInitial()) {
123123
Continuation cont = continuation;
124124
continuation = null;
125125
cont.complete();
@@ -321,10 +321,14 @@ public void connect(HttpServletRequest request,
321321
is_open = true;
322322
session.onConnect(this);
323323
finishSend(response);
324-
if (isConnectionPersistant && continuation != null) {
325-
request.setAttribute(CONTINUATION_KEY, continuation);
326-
continuation.suspend(response);
327-
}
324+
if (continuation != null) {
325+
if (isConnectionPersistant) {
326+
request.setAttribute(CONTINUATION_KEY, continuation);
327+
continuation.suspend(response);
328+
} else {
329+
continuation = null;
330+
}
331+
}
328332
}
329333

330334
@Override
@@ -349,7 +353,7 @@ public void abort() {
349353
public boolean onMessages(List<String> messages) {
350354
return false;
351355
}
352-
356+
353357
@Override
354358
public boolean onMessage(String message) {
355359
return false;

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@
6464

6565
<distributionManagement>
6666
<!-- TODO: switch repositories when deploying on OSS Sonatype repos -->
67-
<!--<repository>
67+
<repository>
6868
<id>mc-release</id>
6969
<url>dav:https://mc-repo.googlecode.com/svn/maven2/releases</url>
70-
</repository>-->
70+
</repository>
7171
<!--<repository>
7272
<id>socketio-staging</id>
7373
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
7474
</repository>-->
75-
<!--<snapshotRepository>
75+
<snapshotRepository>
7676
<id>mc-snapshot</id>
7777
<url>dav:https://mc-repo.googlecode.com/svn/maven2/snapshots</url>
7878
<uniqueVersion>false</uniqueVersion>
79-
</snapshotRepository>-->
79+
</snapshotRepository>
8080
<!--<snapshotRepository>
8181
<id>socketio-snapshots</id>
8282
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>

samples/chat-gwt/src/main/resources/com/glines/socketio/sample/gwtchat/gwtchat.html

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)