Skip to content

Commit

Permalink
Repackage library for Maven Central release
Browse files Browse the repository at this point in the history
  • Loading branch information
ethergeus committed Jul 31, 2022
1 parent 5178874 commit 4d0e6b3
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 39 deletions.
29 changes: 23 additions & 6 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# Additionally it will publish the package to the Maven Central Repository through OSSRH
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
# https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven

name: Maven Package

Expand All @@ -12,19 +14,16 @@ jobs:
build_release:

runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK for publishing to GitHub Packages
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
server-id: github
settings-path: ${{ github.workspace }}

- name: Build with Maven
run: mvn -B package --file pom.xml
Expand All @@ -45,3 +44,21 @@ jobs:
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Set up JDK for publishing to Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Publish to Maven Central Repository
run: mvn -P release --batch-mode deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Changelog

## [1.0-2] - 2022-07-29
## [1.0-3] - 2022-07-31

Revision to initial release.

### Changes
- Fixed buffer underflow issue that occurred when sending messages longer than 125 bits
- Attach JavaDoc and sources to release JAR
- Publish to Apache Maven Central Repository

### Features
- Drop-in replacement for `java.net` `ServerSocket` and `Socket` classes, able to interact with regular java.net Socket clients and web browsers
- Drop-in replacement for `java.net` `ServerSocket` and `Socket` classes, able to interact with regular `java.net` `Socket` clients and web browsers
- Automatic HTTP Upgrade handling to WebSocket protocol upon web browser handshake
- Automatic encoding and decoding of traffic between server and web browser client after WebSocket handshaking with the help of background processes
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Minimal Java library for communication between server and web browser, designed as a drop-in replacement for the `java.net` `ServerSocket` and `Socket` classes

## Features
- Drop-in replacement for `java.net` `ServerSocket` and `Socket` classes, able to interact with regular java.net Socket clients and web browsers
- Drop-in replacement for `java.net` `ServerSocket` and `Socket` classes, able to interact with regular `java.net` `Socket` clients and web browsers
- Automatic HTTP Upgrade handling to WebSocket protocol upon web browser handshake
- Automatic encoding and decoding of traffic between server and web browser client after WebSocket handshaking with the help of background processes

Expand All @@ -17,8 +17,8 @@ Minimal Java library for communication between server and web browser, designed
Using the library to communicate with web browsers is designed to be as straight-forward as interacting normal `java.net` `Socket` clients. Below is a simple example server allowing only once consecutive client to connect at a time, to handle more than one client at a time implement a client handler class with a thread for every client.

```java
import com.antonowycz.ServerSocket; // Extension of java.net.ServerSocket
import com.antonowycz.Socket; // Extension of java.net.Socket
import com.antonowycz.websocket.ServerSocket; // Extension of java.net.ServerSocket
import com.antonowycz.websocket.Socket; // Extension of java.net.Socket
...
public class TestServer implements Runnable {
...
Expand Down Expand Up @@ -56,8 +56,8 @@ public class TestServer implements Runnable {
### Client
The code above works both when the client on the receiving end is a regular `java.net.Socket` class, or a web browser with the [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455) protocol implemented, e.g. Chrome 16+, Firefox 11+, IE 10+.

#### Java Socket
The following unit test from `src/test/java/ServerTest.class` ensures backwards compatibility between the extended `Socket` class and the `java.net.Socket` class:
#### Java websocket.Socket
The following unit test from `src/test/java/ServerTest.class` ensures backwards compatibility between the extended `websocket.Socket` class and the `java.net.Socket` class:

```java
@Test
Expand Down
136 changes: 119 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@

<groupId>com.antonowycz</groupId>
<artifactId>minimal-jwebsocket</artifactId>
<version>1.0-2</version>
<version>1.0-3</version>
<packaging>jar</packaging>
<name>minimal-jwebsocket</name>
<description>Minimal Java library for communication between server and web browser, designed as a drop-in replacement for the java.net websocket.ServerSocket and websocket.Socket classes</description>
<url>https://github.com/ethergeus/minimal-jwebsocket</url>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<developers>
<developer>
<id>ethergeus</id>
<name>Andrey Antonowycz</name>
<email>andrey@antonowycz.com</email>
</developer>
</developers>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down Expand Up @@ -55,29 +74,105 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>@{project.version}</tagNameFormat>
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
<remoteTagging>false</remoteTagging>
<arguments>-DskipTests=true</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<serverId>ossrh</serverId>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
<stagingProgressTimeoutMinutes>60</stagingProgressTimeoutMinutes>
</configuration>
</plugin>
</plugins>
</build>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>oss.sonatype</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>

<build>
<plugins>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-javadoc-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>generate-javadoc</id>
<phase>package</phase>
<goals>
<goal>javadoc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand All @@ -88,4 +183,11 @@
<url>https://maven.pkg.github.com/ethergeus/minimal-jwebsocket</url>
</repository>
</distributionManagement>

<scm>
<connection>scm:git:git@github.com:ethergeus/minimal-jwebsocket.git</connection>
<developerConnection>scm:git:git@github.com:ethergeus/minimal-jwebsocket.git</developerConnection>
<url>https://github.com/ethergeus/minimal-jwebsocket</url>
<tag>HEAD</tag>
</scm>
</project>
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
package websocket;

import java.io.IOException;
import java.net.SocketException;
import java.net.SocketImpl;

public class ServerSocket extends java.net.ServerSocket {
/*
* The ServerSocket class of the minimal-jwebsocket packages provides a method to interact with browser clients
* whilst being backwards compatible with the java.net ServerSocket implementation.
* The websocket.ServerSocket class of the minimal-jwebsocket packages provides a method to interact with browser clients
* whilst being backwards compatible with the java.net websocket.ServerSocket implementation.
*/
public ServerSocket(int port) throws IOException {
super(port);
}

/*
* Accept a new connection to the current ServerSocket object.
* Adapted from java.net.ServerSocket to use the local Socket class instead of java.net.Socket
* Accept a new connection to the current websocket.ServerSocket object.
* Adapted from java.net.websocket.ServerSocket to use the local websocket.Socket class instead of java.net.websocket.Socket
*/
@Override
public Socket accept() throws IOException {
if (isClosed())
throw new SocketException("Socket is closed");
throw new SocketException("websocket.Socket is closed");
if (!isBound())
throw new SocketException("Socket is not bound yet");
throw new SocketException("websocket.Socket is not bound yet");
Socket s = new Socket((SocketImpl) null);
implAccept(s);
return s;
}

/*
* Call the java.net.Socket.implAccept() method to create input and output stream, then create pre-processors for
* Call the java.net.websocket.Socket.implAccept() method to create input and output stream, then create pre-processors for
* both streams which will handle the encoding and decoding for when the connection is upgraded to type websocket.
*/
protected final void implAccept(Socket s) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package websocket;

import websocket.preprocessors.WSInputStream;
import websocket.preprocessors.WSOutputStream;

import java.io.IOException;
import java.io.OutputStream;
import java.net.SocketImpl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package websocket.preprocessors;

import websocket.Socket;

import java.io.*;
import java.nio.ByteBuffer;
import java.security.NoSuchAlgorithmException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package websocket.preprocessors;

import websocket.Socket;

import java.io.*;
import java.nio.ByteBuffer;
import java.util.NoSuchElementException;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class ServerTest {
private static final int SERVER_PORT = 8080;
private TestServer server;
private static final String WS_HTML_CLIENT = Paths.get("src", "test", "web", "src/test/web/TestWSClient.html").toUri().toString();
private static final String WS_HTML_CLIENT = Paths.get("src", "test", "web", "TestWSClient.html").toUri().toString();

@BeforeEach
public void init() {
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/TestServer.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import websocket.ServerSocket;
import websocket.Socket;

import java.io.*;
import java.util.NoSuchElementException;
import java.util.Scanner;
Expand Down

0 comments on commit 4d0e6b3

Please sign in to comment.