Skip to content

Commit ebd19ca

Browse files
committed
Merge tag 'v1.5.6'
2 parents 397117a + ae78d38 commit ebd19ca

File tree

9 files changed

+203
-84
lines changed

9 files changed

+203
-84
lines changed

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
# Change log
22

3+
###############################################################################
4+
## Version Release 1.5.6 (2024/02/06)
5+
6+
#### Bugs Fixed
7+
8+
* [Issue 1382](https://github.com/TooTallNate/Java-WebSocket/issues/1382) - WebSocketClient.upgradeSocketToSSL is enforcing TLS 1.2 ([PR 1387](https://github.com/TooTallNate/Java-WebSocket/pull/1387))
9+
* [PR 1387](https://github.com/TooTallNate/Java-WebSocket/pull/1387) - Retrieve default SSL socket factory
10+
11+
#### New Features
12+
13+
* [Issue 1390](https://github.com/TooTallNate/Java-WebSocket/issues/1390) - Thread created by NamedThreadFactory should be a daemon ([PR 1391](https://github.com/TooTallNate/Java-WebSocket/pull/1391))
14+
* [PR 1391](https://github.com/TooTallNate/Java-WebSocket/pull/1391) - Provide way to start the client/server as daemons
15+
16+
In this release 2 issues and 2 pull requests were closed.
17+
18+
###############################################################################
19+
20+
## Version Release 1.5.5 (2023/12/18)
21+
22+
#### Bugs Fixed
23+
24+
* [Issue 1365](https://github.com/TooTallNate/Java-WebSocket/issues/1365) - Hang on reconnectBlocking
25+
* [Issue 1364](https://github.com/TooTallNate/Java-WebSocket/issues/1364) - NPE during reconnect ([PR 1367](https://github.com/TooTallNate/Java-WebSocket/pull/1367))
26+
* [PR 1367](https://github.com/TooTallNate/Java-WebSocket/pull/1367) - Fix multiple issues related to reconnect
27+
28+
In this release 2 issues and 1 pull request were closed.
29+
30+
###############################################################################
31+
32+
## Version Release 1.5.4 (2023/07/20)
33+
34+
#### New Features
35+
36+
* [Issue 1308](https://github.com/TooTallNate/Java-WebSocket/issues/1308) - Add support for Java modules ([PR 1309](https://github.com/TooTallNate/Java-WebSocket/pull/1309))
37+
* [PR 1309](https://github.com/TooTallNate/Java-WebSocket/pull/1309) - Add support for Java modules
38+
39+
#### Refactoring
40+
41+
* [PR 1259](https://github.com/TooTallNate/Java-WebSocket/pull/1259) - Replace usages of deprecated constructor Integer(String) with Integer.parseInt
42+
43+
In this release 1 issue and 2 pull requests were closed.
44+
45+
###############################################################################
46+
347
## Version Release 1.5.3 (2022/04/09)
448

549
#### Bugs Fixed

README.markdown

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Java WebSockets
33
[![Build Status](https://travis-ci.org/marci4/Java-WebSocket-Dev.svg?branch=master)](https://travis-ci.org/marci4/Java-WebSocket-Dev)
44
[![Javadocs](https://www.javadoc.io/badge/org.java-websocket/Java-WebSocket.svg)](https://www.javadoc.io/doc/org.java-websocket/Java-WebSocket)
55
[![Maven Central](https://img.shields.io/maven-central/v/org.java-websocket/Java-WebSocket.svg)](https://mvnrepository.com/artifact/org.java-websocket/Java-WebSocket)
6-
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.java-websocket/Java-WebSocket.svg)](https://oss.sonatype.org/content/repositories/snapshots/org/java-websocket/Java-WebSocket/)
76

87
This repository contains a barebones WebSocket server and client implementation
98
written in 100% Java. The underlying classes are implemented `java.nio`, which allows for a
@@ -31,7 +30,7 @@ To use maven add this dependency to your pom.xml:
3130
<dependency>
3231
<groupId>org.java-websocket</groupId>
3332
<artifactId>Java-WebSocket</artifactId>
34-
<version>1.5.3</version>
33+
<version>1.5.6</version>
3534
</dependency>
3635
```
3736

@@ -42,11 +41,11 @@ mavenCentral()
4241
```
4342
Then you can just add the latest version to your build.
4443
```xml
45-
compile "org.java-websocket:Java-WebSocket:1.5.3"
44+
compile "org.java-websocket:Java-WebSocket:1.5.6"
4645
```
4746
Or this option if you use gradle 7.0 and above.
4847
```xml
49-
implementation 'org.java-websocket:Java-WebSocket:1.5.3'
48+
implementation 'org.java-websocket:Java-WebSocket:1.5.6'
5049
```
5150

5251
#### Logging

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repositories {
1010
}
1111

1212
group = 'org.java-websocket'
13-
version = '1.5.4-SNAPSHOT'
13+
version = '1.5.6'
1414
sourceCompatibility = 1.7
1515
targetCompatibility = 1.7
1616

@@ -35,8 +35,8 @@ publishing {
3535
}
3636

3737
dependencies {
38-
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
39-
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
38+
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.6'
39+
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.6'
4040
testImplementation group: 'junit', name: 'junit', version: '4.12'
4141
testImplementation group: 'org.json', name: 'json', version: '20180813'
4242
}

pom.xml

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<groupId>org.java-websocket</groupId>
1313
<artifactId>Java-WebSocket</artifactId>
1414
<packaging>jar</packaging>
15-
<version>1.5.4.Ascom.1-SNAPSHOT</version>
15+
<version>1.5.6.Ascom</version>
1616
<name>${project.artifactId}-${project.version}</name>
1717
<description>A barebones WebSocket client and server implementation written 100% in Java</description>
1818
<url>https://github.com/TooTallNate/Java-WebSocket</url>
@@ -34,7 +34,7 @@
3434
<maven.javadoc.plugin.version>3.5.0</maven.javadoc.plugin.version>
3535
<maven.shade.plugin.version>3.4.1</maven.shade.plugin.version>
3636
<maven.source.plugin.version>3.2.1</maven.source.plugin.version>
37-
<nexus.staging.maven.plugin.version>1.6.8</nexus.staging.maven.plugin.version>
37+
<nexus.staging.maven.plugin.version>1.6.13</nexus.staging.maven.plugin.version>
3838
<sonar.projectKey>org.java-websocket:Java-WebSocket</sonar.projectKey>
3939
<sonar.organization>marci4-github</sonar.organization>
4040
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
@@ -165,6 +165,10 @@
165165
<groupId>org.apache.maven.plugins</groupId>
166166
<artifactId>maven-javadoc-plugin</artifactId>
167167
<version>${maven.javadoc.plugin.version}</version>
168+
<configuration>
169+
<sourcepath>src/main/java</sourcepath>
170+
<additionalOptions>-Xdoclint:none</additionalOptions>
171+
</configuration>
168172
<executions>
169173
<execution>
170174
<id>attach-javadocs</id>
@@ -191,6 +195,7 @@
191195
</goals>
192196
</execution>
193197
</executions>
198+
194199
</plugin>
195200
<plugin>
196201
<groupId>org.sonatype.plugins</groupId>
@@ -259,7 +264,7 @@
259264
<extensions>true</extensions>
260265
<configuration>
261266
<serverId>ossrh</serverId>
262-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
267+
<autoReleaseAfterClose>false</autoReleaseAfterClose>
263268
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
264269
</configuration>
265270
</plugin>
@@ -270,72 +275,9 @@
270275
<plugin>
271276
<groupId>org.apache.maven.plugins</groupId>
272277
<artifactId>maven-javadoc-plugin</artifactId>
273-
</plugin>
274-
</plugins>
275-
</build>
276-
</profile>
277-
<profile>
278-
<id>full</id>
279-
<activation>
280-
<activeByDefault>false</activeByDefault>
281-
</activation>
282-
<dependencies>
283-
<dependency>
284-
<groupId>org.slf4j</groupId>
285-
<artifactId>slf4j-simple</artifactId>
286-
</dependency>
287-
</dependencies>
288-
<build>
289-
<plugins>
290-
<plugin>
291-
<groupId>biz.aQute.bnd</groupId>
292-
<artifactId>bnd-maven-plugin</artifactId>
293-
</plugin>
294-
<plugin>
295-
<groupId>org.apache.maven.plugins</groupId>
296-
<artifactId>maven-shade-plugin</artifactId>
297-
<executions>
298-
<execution>
299-
<phase>package</phase>
300-
<goals>
301-
<goal>shade</goal>
302-
</goals>
303-
<configuration>
304-
<shadedArtifactAttached>true</shadedArtifactAttached>
305-
<shadedClassifierName>with-dependencies</shadedClassifierName>
306-
<transformers>
307-
<transformer
308-
implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
309-
<resource>simplelogger.properties</resource>
310-
<file>src\main\example\simplelogger.properties</file>
311-
</transformer>
312-
</transformers>
313-
</configuration>
314-
</execution>
315-
</executions>
316-
</plugin>
317-
<plugin>
318-
<groupId>org.apache.maven.plugins</groupId>
319-
<artifactId>maven-source-plugin</artifactId>
320-
</plugin>
321-
<plugin>
322-
<groupId>org.apache.maven.plugins</groupId>
323-
<artifactId>maven-jar-plugin</artifactId>
324-
<executions>
325-
<execution>
326-
<goals>
327-
<goal>test-jar</goal>
328-
</goals>
329-
</execution>
330-
</executions>
331-
</plugin>
332-
<plugin>
333-
<groupId>org.apache.maven.plugins</groupId>
334-
<artifactId>maven-javadoc-plugin</artifactId>
335-
</plugin>
336-
<plugin>
337-
<groupId>org.apache.maven.plugins</groupId>
338-
<artifactId>maven-gpg-plugin</artifactId>
278+
<configuration>
279+
<additionalOptions>-Xdoclint:none</additionalOptions>
280+
</configuration>
339281
</plugin>
340282
</plugins>
341283
</build>

src/main/java/org/java_websocket/AbstractWebSocket.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public abstract class AbstractWebSocket extends WebSocketAdapter {
9090
*/
9191
private boolean websocketRunning = false;
9292

93+
/**
94+
* Attribute to start internal threads as daemon
95+
*
96+
* @since 1.5.6
97+
*/
98+
private boolean daemon = false;
99+
93100
/**
94101
* Attribute to sync on
95102
*/
@@ -182,7 +189,7 @@ protected void startConnectionLostTimer() {
182189
private void restartConnectionLostTimer() {
183190
cancelConnectionLostTimer();
184191
connectionLostCheckerService = Executors
185-
.newSingleThreadScheduledExecutor(new NamedThreadFactory("connectionLostChecker"));
192+
.newSingleThreadScheduledExecutor(new NamedThreadFactory("connectionLostChecker", daemon));
186193
Runnable connectionLostChecker = new Runnable() {
187194

188195
/**
@@ -308,4 +315,25 @@ public void setReuseAddr(boolean reuseAddr) {
308315
this.reuseAddr = reuseAddr;
309316
}
310317

318+
319+
/**
320+
* Getter for daemon
321+
*
322+
* @return whether internal threads are spawned in daemon mode
323+
* @since 1.5.6
324+
*/
325+
public boolean isDaemon() {
326+
return daemon;
327+
}
328+
329+
/**
330+
* Setter for daemon
331+
* <p>
332+
* Controls whether or not internal threads are spawned in daemon mode
333+
*
334+
* @since 1.5.6
335+
*/
336+
public void setDaemon(boolean daemon) {
337+
this.daemon = daemon;
338+
}
311339
}

src/main/java/org/java_websocket/client/WebSocketClient.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import java.util.concurrent.CountDownLatch;
4646
import java.util.concurrent.TimeUnit;
4747
import javax.net.SocketFactory;
48-
import javax.net.ssl.SSLContext;
4948
import javax.net.ssl.SSLException;
5049
import javax.net.ssl.SSLParameters;
5150
import javax.net.ssl.SSLSession;
@@ -343,10 +342,12 @@ private void reset() {
343342
closeBlocking();
344343
if (writeThread != null) {
345344
this.writeThread.interrupt();
345+
this.writeThread.join();
346346
this.writeThread = null;
347347
}
348348
if (connectReadThread != null) {
349349
this.connectReadThread.interrupt();
350+
this.connectReadThread.join();
350351
this.connectReadThread = null;
351352
}
352353
this.draft.reset();
@@ -372,6 +373,7 @@ public void connect() {
372373
throw new IllegalStateException("WebSocketClient objects are not reuseable");
373374
}
374375
connectReadThread = new Thread(this);
376+
connectReadThread.setDaemon(isDaemon());
375377
connectReadThread.setName("WebSocketConnectReadThread-" + connectReadThread.getId());
376378
connectReadThread.start();
377379
}
@@ -505,7 +507,16 @@ public void run() {
505507
throw e;
506508
}
507509

510+
if (writeThread != null) {
511+
writeThread.interrupt();
512+
try {
513+
writeThread.join();
514+
} catch (InterruptedException e) {
515+
/* ignore */
516+
}
517+
}
508518
writeThread = new Thread(new WebsocketWriteThread(this));
519+
writeThread.setDaemon(isDaemon());
509520
writeThread.start();
510521

511522
byte[] rawbuffer = new byte[WebSocketImpl.RCVBUF];
@@ -523,7 +534,6 @@ public void run() {
523534
onError(e);
524535
engine.closeConnection(CloseFrame.ABNORMAL_CLOSE, e.getMessage());
525536
}
526-
connectReadThread = null;
527537
}
528538

529539
private void upgradeSocketToSSL()
@@ -534,9 +544,7 @@ private void upgradeSocketToSSL()
534544
if (socketFactory instanceof SSLSocketFactory) {
535545
factory = (SSLSocketFactory) socketFactory;
536546
} else {
537-
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
538-
sslContext.init(null, null, null);
539-
factory = sslContext.getSocketFactory();
547+
factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
540548
}
541549
socket = factory.createSocket(socket, uri.getHost(), getPort(), true);
542550
}
@@ -801,7 +809,6 @@ public void run() {
801809
handleIOException(e);
802810
} finally {
803811
closeSocket();
804-
writeThread = null;
805812
}
806813
}
807814

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ public void start() {
245245
if (selectorthread != null) {
246246
throw new IllegalStateException(getClass().getName() + " can only be started once.");
247247
}
248-
new Thread(this).start();
248+
Thread t = new Thread(this);
249+
t.setDaemon(isDaemon());
250+
t.start();
249251
}
250252

251253
public void stop(int timeout) throws InterruptedException {
@@ -326,6 +328,20 @@ public int getPort() {
326328
return port;
327329
}
328330

331+
@Override
332+
public void setDaemon(boolean daemon) {
333+
// pass it to the AbstractWebSocket too, to use it on the connectionLostChecker thread factory
334+
super.setDaemon(daemon);
335+
// we need to apply this to the decoders as well since they were created during the constructor
336+
for (WebSocketWorker w : decoders) {
337+
if (w.isAlive()) {
338+
throw new IllegalStateException("Cannot call setDaemon after server is already started!");
339+
} else {
340+
w.setDaemon(daemon);
341+
}
342+
}
343+
}
344+
329345
/**
330346
* Get the list of active drafts
331347
*

src/main/java/org/java_websocket/util/NamedThreadFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,22 @@ public class NamedThreadFactory implements ThreadFactory {
3434
private final ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory();
3535
private final AtomicInteger threadNumber = new AtomicInteger(1);
3636
private final String threadPrefix;
37+
private final boolean daemon;
3738

3839
public NamedThreadFactory(String threadPrefix) {
3940
this.threadPrefix = threadPrefix;
41+
this.daemon = false;
42+
}
43+
44+
public NamedThreadFactory(String threadPrefix, boolean daemon) {
45+
this.threadPrefix = threadPrefix;
46+
this.daemon = daemon;
4047
}
4148

4249
@Override
4350
public Thread newThread(Runnable runnable) {
4451
Thread thread = defaultThreadFactory.newThread(runnable);
52+
thread.setDaemon(daemon);
4553
thread.setName(threadPrefix + "-" + threadNumber);
4654
return thread;
4755
}

0 commit comments

Comments
 (0)