Make sure the 3.2 branch is usable with java5. This changes are based on
the pull request #191 with a modification to not break the API.
This commit is contained in:
parent
c12717bfed
commit
0cc8153aa6
25
pom.xml
25
pom.xml
@ -276,6 +276,31 @@
|
||||
<showWarnings>true</showWarnings>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- ensure that only methods available in java 1.5 can
|
||||
be used even when compiling with java 1.6+ -->
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>animal-sniffer-maven-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<configuration>
|
||||
<signature>
|
||||
<groupId>org.codehaus.mojo.signature</groupId>
|
||||
<artifactId>java15</artifactId>
|
||||
<version>1.0</version>
|
||||
</signature>
|
||||
<ignores>
|
||||
<ignore>sun.misc.Unsafe</ignore>
|
||||
</ignores>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
|
@ -76,7 +76,7 @@ public class AutobahnServerHandler extends SimpleChannelUpstreamHandler {
|
||||
if (this.handshaker == null) {
|
||||
wsFactory.sendUnsupportedWebSocketVersionResponse(ctx.getChannel());
|
||||
} else {
|
||||
this.handshaker.handshake(ctx.getChannel(), req);
|
||||
this.handshaker.handshake(ctx.getChannel(), req).addListener(WebSocketServerHandshaker.HANDSHAKE_LISTENER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class WebSocketServerHandler extends SimpleChannelUpstreamHandler {
|
||||
if (this.handshaker == null) {
|
||||
wsFactory.sendUnsupportedWebSocketVersionResponse(ctx.getChannel());
|
||||
} else {
|
||||
this.handshaker.handshake(ctx.getChannel(), req);
|
||||
this.handshaker.handshake(ctx.getChannel(), req).addListener(WebSocketServerHandshaker.HANDSHAKE_LISTENER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,13 +71,13 @@ public class WebSocketSslServer {
|
||||
}
|
||||
|
||||
String keyStoreFilePath = System.getProperty("keystore.file.path");
|
||||
if (keyStoreFilePath == null || keyStoreFilePath.isEmpty()) {
|
||||
if (keyStoreFilePath == null || keyStoreFilePath.length() == 0) {
|
||||
System.out.println("ERROR: System property keystore.file.path not set. Exiting now!");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String keyStoreFilePassword = System.getProperty("keystore.file.password");
|
||||
if (keyStoreFilePassword == null || keyStoreFilePassword.isEmpty()) {
|
||||
if (keyStoreFilePassword == null || keyStoreFilePassword.length() == 0) {
|
||||
System.out.println("ERROR: System property keystore.file.password not set. Exiting now!");
|
||||
System.exit(1);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class WebSocketSslServerHandler extends SimpleChannelUpstreamHandler {
|
||||
if (this.handshaker == null) {
|
||||
wsFactory.sendUnsupportedWebSocketVersionResponse(ctx.getChannel());
|
||||
} else {
|
||||
this.handshaker.handshake(ctx.getChannel(), req);
|
||||
this.handshaker.handshake(ctx.getChannel(), req).addListener(WebSocketServerHandshaker.HANDSHAKE_LISTENER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.Charset;
|
||||
@ -219,7 +220,7 @@ public class QueryStringDecoder {
|
||||
}
|
||||
decodeParams(uri.substring(pathLength + 1));
|
||||
} else {
|
||||
if (uri.isEmpty()) {
|
||||
if (uri.length() == 0) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
decodeParams(uri);
|
||||
@ -387,7 +388,11 @@ public class QueryStringDecoder {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new String(buf, 0, pos, charset);
|
||||
try {
|
||||
return new String(buf, 0, pos, charset.name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalArgumentException("unsupported encoding: " + charset.name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +112,7 @@ public class ContinuationWebSocketFrame extends WebSocketFrame {
|
||||
* text to store
|
||||
*/
|
||||
public void setText(String text) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
if (text == null || text.length() == 0) {
|
||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
||||
} else {
|
||||
setBinaryData(ChannelBuffers.copiedBuffer(text, CharsetUtil.UTF_8));
|
||||
|
@ -38,7 +38,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
* String to put in the frame
|
||||
*/
|
||||
public TextWebSocketFrame(String text) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
if (text == null || text.length() == 0) {
|
||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
||||
} else {
|
||||
setBinaryData(ChannelBuffers.copiedBuffer(text, CharsetUtil.UTF_8));
|
||||
@ -68,7 +68,7 @@ public class TextWebSocketFrame extends WebSocketFrame {
|
||||
public TextWebSocketFrame(boolean finalFragment, int rsv, String text) {
|
||||
setFinalFragment(finalFragment);
|
||||
setRsv(rsv);
|
||||
if (text == null || text.isEmpty()) {
|
||||
if (text == null || text.length() == 0) {
|
||||
setBinaryData(ChannelBuffers.EMPTY_BUFFER);
|
||||
} else {
|
||||
setBinaryData(ChannelBuffers.copiedBuffer(text, CharsetUtil.UTF_8));
|
||||
|
@ -109,7 +109,7 @@ public abstract class WebSocketClientHandshaker {
|
||||
* @param channel
|
||||
* Channel
|
||||
*/
|
||||
public abstract ChannelFuture handshake(Channel channel);
|
||||
public abstract ChannelFuture handshake(Channel channel) throws Exception;
|
||||
|
||||
/**
|
||||
* Validates and finishes the opening handshake initiated by {@link #handshake}}.
|
||||
|
@ -95,7 +95,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
* Channel into which we can write our request
|
||||
*/
|
||||
@Override
|
||||
public ChannelFuture handshake(Channel channel) {
|
||||
public ChannelFuture handshake(Channel channel) throws Exception {
|
||||
// Get path
|
||||
URI wsURL = getWebSocketUrl();
|
||||
String path = wsURL.getPath();
|
||||
@ -108,7 +108,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
||||
String key = WebSocketUtil.base64(nonce);
|
||||
|
||||
String acceptSeed = key + MAGIC_GUID;
|
||||
byte[] sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII));
|
||||
byte[] sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII.name()));
|
||||
expectedChallengeResponseString = WebSocketUtil.base64(sha1);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
@ -95,7 +95,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
* Channel into which we can write our request
|
||||
*/
|
||||
@Override
|
||||
public ChannelFuture handshake(Channel channel) {
|
||||
public ChannelFuture handshake(Channel channel) throws Exception {
|
||||
// Get path
|
||||
URI wsURL = getWebSocketUrl();
|
||||
String path = wsURL.getPath();
|
||||
@ -108,7 +108,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
||||
String key = WebSocketUtil.base64(nonce);
|
||||
|
||||
String acceptSeed = key + MAGIC_GUID;
|
||||
byte[] sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII));
|
||||
byte[] sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII.name()));
|
||||
expectedChallengeResponseString = WebSocketUtil.base64(sha1);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
@ -20,6 +20,8 @@ import java.util.Set;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ChannelFutureListener;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
|
||||
/**
|
||||
@ -33,6 +35,18 @@ public abstract class WebSocketServerHandshaker {
|
||||
|
||||
private final WebSocketVersion version;
|
||||
|
||||
/**
|
||||
* {@link ChannelFutureListener} which will call {@link Channels#fireExceptionCaught(org.jboss.netty.channel.ChannelHandlerContext, Throwable)}
|
||||
* if the {@link ChannelFuture} was not sucessful.
|
||||
*/
|
||||
public static final ChannelFutureListener HANDSHAKE_LISTENER = new ChannelFutureListener() {
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
if (!future.isSuccess()) {
|
||||
Channels.fireExceptionCaught(future.getChannel(), future.getCause());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor specifying the destination web socket location
|
||||
*
|
||||
|
@ -18,10 +18,13 @@ package org.jboss.netty.handler.codec.http.websocketx;
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Values.*;
|
||||
import static org.jboss.netty.handler.codec.http.HttpVersion.*;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ChannelFutureListener;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders.Names;
|
||||
@ -118,7 +121,12 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
||||
throw new WebSocketHandshakeException("not a WebSocket request: missing key");
|
||||
}
|
||||
String acceptSeed = key + WEBSOCKET_08_ACCEPT_GUID;
|
||||
byte[] sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII));
|
||||
byte[] sha1;
|
||||
try {
|
||||
sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII.name()));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return Channels.failedFuture(channel, e);
|
||||
}
|
||||
String accept = WebSocketUtil.base64(sha1);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
@ -18,10 +18,13 @@ package org.jboss.netty.handler.codec.http.websocketx;
|
||||
import static org.jboss.netty.handler.codec.http.HttpHeaders.Values.WEBSOCKET;
|
||||
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.jboss.netty.channel.Channel;
|
||||
import org.jboss.netty.channel.ChannelFuture;
|
||||
import org.jboss.netty.channel.ChannelFutureListener;
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.Channels;
|
||||
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
|
||||
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequest;
|
||||
@ -119,7 +122,12 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
||||
throw new WebSocketHandshakeException("not a WebSocket request: missing key");
|
||||
}
|
||||
String acceptSeed = key + WEBSOCKET_13_ACCEPT_GUID;
|
||||
byte[] sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII));
|
||||
byte[] sha1;
|
||||
try {
|
||||
sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII.name()));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return Channels.failedFuture(channel, e);
|
||||
}
|
||||
String accept = WebSocketUtil.base64(sha1);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
Loading…
Reference in New Issue
Block a user