Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version bump, MRJar, and use virtual threads on Java 21+ #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/maven-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
java-version: 21
distribution: 'temurin'
architecture: x64
- name: Cache Maven packages
uses: actions/cache@v2
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM adoptopenjdk:11-jre-hotspot
FROM eclipse-temurin:21-jre-alpine

LABEL description="Basic Proxy Facade for NTLM, Kerberos, SOCKS and Proxy Auto Config file proxies"
LABEL maintainer="ecovaci"
Expand All @@ -13,9 +13,9 @@ RUN chmod +x /opt/winfoom/docker-entrypoint.sh

EXPOSE 3129 9999

RUN groupadd -r winfoom && useradd -r -g winfoom winfoom
RUN addgroup -S winfoom && adduser -S -g winfoom winfoom

RUN mkdir /data && chown winfoom:winfoom /data
RUN mkdir /data && chown winfoom:winfoom /data && chown -R winfoom:winfoom /opt/winfoom

USER winfoom

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ An example of such a facade for NTLM proxies is [CNTLM](http://cntlm.sourceforge
## Download Winfoom
### Download prepackaged
To try out Winfoom without needing to download the source and package it, check out the [releases](https://github.com/ecovaci/winfoom/releases) for a prepackaged `winfoom-*.zip`.
Winfoom is a Java application and requires a Java Runtime Environment (at least v11).
Winfoom is a Java application and requires a Java Runtime Environment (at least v17).

If it is not already installed on your system, you can download it from [AdoptOpenJDK](https://adoptopenjdk.net/) or,
on Linux systems, use your package manager.
Expand All @@ -39,7 +39,7 @@ to your system architecture, unzip it in the Winfoom directory and rename it to

### Build from source code
If you decide to build the executable *jar* file from the source code, you would need these prerequisites:
* Java JDK 11(+)
* Java JDK 21+ (winfoom requires Java 17 to run, but JDK21 or higher is required to build)
* Maven 3.x version (optional)

First download the source code from [releases](https://github.com/ecovaci/winfoom/releases) and unzip it.
Expand Down
65 changes: 51 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,31 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<version>3.2.2</version>
<relativePath/>
</parent>
<groupId>org.kpax</groupId>
<artifactId>winfoom</artifactId>
<version>4.0.3</version>
<version>5.0.0-SNAPSHOT</version>

<name>winfoom</name>
<url>https://github.com/ecovaci/winfoom</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<httpclient.version>4.5.13</httpclient.version>
<commons-configuration2.version>2.7</commons-configuration2.version>
<commons-io.version>2.11.0</commons-io.version>
<httpclient.version>4.5.14</httpclient.version>
<commons-configuration2.version>2.9.0</commons-configuration2.version>
<commons-io.version>2.15.1</commons-io.version>
<commons-beanutils.version>1.9.4</commons-beanutils.version>
<ipaddress.version>5.3.3</ipaddress.version>
<ipaddress.version>5.4.0</ipaddress.version>
<cache2k.version>2.6.1.Final</cache2k.version>
<commons-pool2.version>2.11.1</commons-pool2.version>
<graalvm-js.version>22.0.0.2</graalvm-js.version>
<mock-server.version>5.9.0</mock-server.version>
<commons-pool2.version>2.12.0</commons-pool2.version>
<graalvm-js.version>23.0.3</graalvm-js.version>
<littleproxy.version>1.1.2</littleproxy.version>
<mockserver-netty.version>5.10.0</mockserver-netty.version>
<lombok.version>1.18.20</lombok.version>
<assertj.version>3.20.2</assertj.version>
<log4j-jcl.version>2.17.2</log4j-jcl.version>
<mockserver-netty.version>5.15.0</mockserver-netty.version>
<lombok.version>1.18.30</lombok.version>
<assertj.version>3.25.1</assertj.version>
<log4j-jcl.version>2.22.1</log4j-jcl.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -185,6 +183,45 @@
<build>
<finalName>winfoom</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile-java-17</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>17</release>
</configuration>
</execution>
<execution>
<id>compile-java-21</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>21</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java21</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kpax/winfoom/api/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kpax/winfoom/config/ProxyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kpax/winfoom/config/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import java.net.Socket;
import java.net.SocketException;
import java.util.List;
Expand Down
46 changes: 8 additions & 38 deletions src/main/java/org/kpax/winfoom/proxy/ProxyExecutorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.kpax.winfoom.proxy;

import lombok.extern.slf4j.Slf4j;
import org.kpax.winfoom.proxy.concurrent.ExecutorServiceFactory;
import org.kpax.winfoom.proxy.listener.StopListener;
import org.kpax.winfoom.util.functional.SingletonSupplier;
import org.springframework.core.annotation.Order;
Expand All @@ -21,7 +22,6 @@
import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
* A wrapper for {@link ThreadPoolExecutor} that forbids {@link #shutdown()}, {@link #shutdownNow()}
Expand All @@ -32,13 +32,10 @@
@Component
public class ProxyExecutorService implements ExecutorService, StopListener {

private final SingletonSupplier<ThreadPoolExecutor> threadPoolSupplier;
private final SingletonSupplier<ExecutorService> threadPoolSupplier;

public ProxyExecutorService() {
this.threadPoolSupplier =
new SingletonSupplier<>(() -> new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS, new SynchronousQueue<>(),
new DefaultThreadFactory()));
this.threadPoolSupplier = new SingletonSupplier<>(() -> new ExecutorServiceFactory().get());
}

public void execute(Runnable task) {
Expand Down Expand Up @@ -102,42 +99,15 @@ public boolean isTerminated() {
return threadPoolSupplier.hasValue() && threadPoolSupplier.get().isTerminated();
}

@Override
public void close() {
StopListener.super.close();
}

@Override
public void onStop() {
log.debug("Reset the proxy executor service");
threadPoolSupplier.reset(ExecutorService::shutdownNow);
}

public static class DefaultThreadFactory implements ThreadFactory {
private static final AtomicInteger poolNumber = new AtomicInteger(1);
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;

public DefaultThreadFactory() {
SecurityManager securityManager = System.getSecurityManager();
group = (securityManager != null) ? securityManager.getThreadGroup() :
Thread.currentThread().getThreadGroup();
namePrefix = "pool-" +
poolNumber.getAndIncrement() +
"-thread-";
}

@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(group, runnable,
namePrefix + threadNumber.getAndIncrement(),
0);

// Make sure all threads are daemons!
if (!thread.isDaemon()) {
thread.setDaemon(true);
}

if (thread.getPriority() != Thread.NORM_PRIORITY) {
thread.setPriority(Thread.NORM_PRIORITY);
}
return thread;
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/kpax/winfoom/proxy/TunnelConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.kpax.winfoom.util.functional.ProxySingletonSupplier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import java.io.IOException;
import java.net.Socket;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2024. Eugen Covaci
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/

package org.kpax.winfoom.proxy.concurrent;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
* A {@link ThreadFactory} for thread pools.
*/
public class DefaultThreadFactory implements ThreadFactory {

private static final AtomicInteger poolNumber = new AtomicInteger(1);
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;

public DefaultThreadFactory() {
SecurityManager securityManager = System.getSecurityManager();
group = (securityManager != null) ? securityManager.getThreadGroup() : Thread.currentThread().getThreadGroup();
namePrefix = "pool-" + poolNumber.getAndIncrement() + "-thread-";
}

@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(group, runnable, namePrefix + threadNumber.getAndIncrement(), 0);
// Make sure all threads are daemons!
if (!thread.isDaemon()) {
thread.setDaemon(true);
}
if (thread.getPriority() != Thread.NORM_PRIORITY) {
thread.setPriority(Thread.NORM_PRIORITY);
}
return thread;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024. Eugen Covaci
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/

package org.kpax.winfoom.proxy.concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

/**
* A factory which creates a thread pool executor.
*/
public class ExecutorServiceFactory implements Supplier<ExecutorService> {

@Override
public ExecutorService get() {
return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS, new SynchronousQueue<>(),
new DefaultThreadFactory());
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/kpax/winfoom/view/AppFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024. Eugen Covaci
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/

package org.kpax.winfoom.proxy.concurrent;

import java.util.concurrent.*;
import java.util.function.Supplier;

/**
* A factory which creates a virtual thread executor.
*/
public class ExecutorServiceFactory implements Supplier<ExecutorService> {

public ExecutorService get() {
ThreadFactory factory = Thread.ofVirtual()
.name("virtual-thread-", 0L)
.factory();
return Executors.newThreadPerTaskExecutor(factory);
}

}