Skip to content

Commit 5fa66db

Browse files
authored
Merge branch 'master' into ClojureBuild
2 parents 309bdfb + 1520eaa commit 5fa66db

35 files changed

+1093
-613
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ target
1313
.classpath
1414
bin
1515

16-
/doc
16+
/doc
17+
*.xml
18+
.idea/.name

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
language: java
2-
jdk:
3-
- oraclejdk7
4-
5-
script: "./gradlew test"
1+
{
2+
"language": "java",
3+
"script": "ant all"
4+
}

README.markdown

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/ck1125/Java-WebSocket.png?branch=master)](https://travis-ci.org/ck1125/Java-WebSocket)
1+
[![Build Status](https://travis-ci.org/marci4/Java-WebSocket-Dev.svg?branch=master)](https://travis-ci.org/marci4/Java-WebSocket-Dev)
22
Java WebSockets
33
===============
44

@@ -19,28 +19,18 @@ Implemented WebSocket protocol versions are:
1919

2020

2121
##Build
22-
You can build using Ant, Maven or Leiningen but there is nothing against just putting the source path ```src/main/java ``` on your applications buildpath.
22+
You can build using Ant or Leiningen but there is nothing against just putting the source path ```src/main/java ``` on your applications buildpath.
2323

24-
###Ant
24+
### Ant
2525

2626
``` bash
2727
ant
2828
```
2929

30-
will create the javadoc of this library at ```doc/``` and build the library itself: ```dest/java_websocket.jar```
30+
will create the javadoc of this library at ```doc/``` and build the library itself: ```dist/java_websocket.jar```
3131

3232
The ant targets are: ```compile```, ```jar```, ```doc``` and ```clean```
3333

34-
###Maven
35-
36-
To use maven just add this dependency to your pom.xml:
37-
```xml
38-
<dependency>
39-
<groupId>org.java-websocket</groupId>
40-
<artifactId>Java-WebSocket</artifactId>
41-
<version>1.3.0</version>
42-
</dependency>
43-
```
4434

4535
### Leiningen
4636

@@ -89,7 +79,7 @@ connections though HTTP. After that it's up to **your** subclass to add purpose.
8979
Writing your own WebSocket Client
9080
---------------------------------
9181

92-
The `org.java_websocket.server.WebSocketClient` abstract class can connect to
82+
The `org.java_websocket.client.WebSocketClient` abstract class can connect to
9383
valid WebSocket servers. The constructor expects a valid `ws://` URI to
9484
connect to. Important events `onOpen`, `onClose`, `onMessage` and `onIOError`
9585
get fired throughout the life of the WebSocketClient, and must be implemented

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<mkdir dir="build/classes" />
77
<mkdir dir="build/examples" />
88
<javac includeantruntime="false" debug="on" srcdir="src/main/java"
9-
destdir="build/classes" target="1.5" />
9+
destdir="build/classes" target="1.6" />
1010
<javac includeantruntime="false" srcdir="src/main/example/"
1111
classpath="build/classes" destdir="build/examples" />
1212
</target>

dist/java_websocket.jar

10.8 KB
Binary file not shown.

pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<java.version>1.6</java.version>
24+
<cucumber.version>1.0.0.RC24</cucumber.version>
2425
</properties>
2526
<build>
2627
<plugins>
@@ -61,6 +62,28 @@
6162
</plugin>
6263
</plugins>
6364
</build>
65+
<dependencies>
66+
<!-- JUnit -->
67+
<dependency>
68+
<groupId>junit</groupId>
69+
<artifactId>junit</artifactId>
70+
<version>4.8.2</version>
71+
<scope>test</scope>
72+
</dependency>
73+
<!-- Cucumber -->
74+
<dependency>
75+
<groupId>info.cukes</groupId>
76+
<artifactId>cucumber-junit</artifactId>
77+
<version>1.0.0</version>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>info.cukes</groupId>
82+
<artifactId>cucumber-java</artifactId>
83+
<version>${cucumber.version}</version>
84+
<scope>test</scope>
85+
</dependency>
86+
</dependencies>
6487
<developers>
6588
<developer>
6689
<id>TooTallNate</id>

src/main/example/ChatServer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ public static void main( String[] args ) throws InterruptedException , IOExcepti
6565
if( in.equals( "exit" ) ) {
6666
s.stop();
6767
break;
68-
} else if( in.equals( "restart" ) ) {
69-
s.stop();
70-
s.start();
71-
break;
7268
}
7369
}
7470
}

src/main/example/ExampleClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.java_websocket.client.WebSocketClient;
55
import org.java_websocket.drafts.Draft;
66
import org.java_websocket.drafts.Draft_10;
7+
import org.java_websocket.drafts.Draft_17;
78
import org.java_websocket.framing.Framedata;
89
import org.java_websocket.handshake.ServerHandshake;
910

@@ -47,7 +48,7 @@ public void onError( Exception ex ) {
4748
}
4849

4950
public static void main( String[] args ) throws URISyntaxException {
50-
ExampleClient c = new ExampleClient( new URI( "ws://localhost:8887" ), new Draft_10() ); // more about drafts here: http://github.com/TooTallNate/Java-WebSocket/wiki/Drafts
51+
ExampleClient c = new ExampleClient( new URI( "ws://localhost:8887" ), new Draft_17() ); // more about drafts here: http://github.com/TooTallNate/Java-WebSocket/wiki/Drafts
5152
c.connect();
5253
}
5354

src/main/java/org/java_websocket/AbstractWrappedByteChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public int write( ByteBuffer src ) throws IOException {
4242

4343
@Override
4444
public boolean isNeedWrite() {
45-
return channel instanceof WrappedByteChannel ? ( (WrappedByteChannel) channel ).isNeedWrite() : false;
45+
return channel instanceof WrappedByteChannel && ((WrappedByteChannel) channel).isNeedWrite();
4646
}
4747

4848
@Override
@@ -54,7 +54,7 @@ public void writeMore() throws IOException {
5454

5555
@Override
5656
public boolean isNeedRead() {
57-
return channel instanceof WrappedByteChannel ? ( (WrappedByteChannel) channel ).isNeedRead() : false;
57+
return channel instanceof WrappedByteChannel && ((WrappedByteChannel) channel).isNeedRead();
5858

5959
}
6060

src/main/java/org/java_websocket/SSLSocketChannel2.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
*/
66
package org.java_websocket;
77

8+
import javax.net.ssl.SSLEngine;
9+
import javax.net.ssl.SSLEngineResult;
10+
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
11+
import javax.net.ssl.SSLEngineResult.Status;
12+
import javax.net.ssl.SSLException;
13+
import javax.net.ssl.SSLSession;
14+
import java.io.EOFException;
815
import java.io.IOException;
916
import java.net.Socket;
1017
import java.net.SocketAddress;
@@ -20,13 +27,6 @@
2027
import java.util.concurrent.ExecutorService;
2128
import java.util.concurrent.Future;
2229

23-
import javax.net.ssl.SSLEngine;
24-
import javax.net.ssl.SSLEngineResult;
25-
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
26-
import javax.net.ssl.SSLEngineResult.Status;
27-
import javax.net.ssl.SSLException;
28-
import javax.net.ssl.SSLSession;
29-
3030
/**
3131
* Implements the relevant portions of the SocketChannel interface with the SSLEngine wrapper.
3232
*/
@@ -213,6 +213,9 @@ public int write( ByteBuffer src ) throws IOException {
213213
// createBuffers( sslEngine.getSession() );
214214
//}
215215
int num = socketChannel.write( wrap( src ) );
216+
if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) {
217+
throw new EOFException("Connection is closed");
218+
}
216219
return num;
217220

218221
}
@@ -286,6 +289,9 @@ private int readRemaining( ByteBuffer dst ) throws SSLException {
286289
if( inCrypt.hasRemaining() ) {
287290
unwrap();
288291
int amount = transfereTo( inData, dst );
292+
if (readEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) {
293+
return -1;
294+
}
289295
if( amount > 0 )
290296
return amount;
291297
}
@@ -302,7 +308,6 @@ public void close() throws IOException {
302308
if( socketChannel.isOpen() )
303309
socketChannel.write( wrap( emptybuffer ) );// FIXME what if not all bytes can be written
304310
socketChannel.close();
305-
exec.shutdownNow();
306311
}
307312

308313
private boolean isHandShakeComplete() {

0 commit comments

Comments
 (0)