Skip to content

Commit

Permalink
Revert compile version back to JDK 11, since we still want to support…
Browse files Browse the repository at this point in the history
… LTS versions. Added missing CDI implementation
  • Loading branch information
urbim committed Jan 17, 2024
1 parent 5da4fcc commit d37232d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kumuluzee-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
java-version: ['11', '17', '18']
java-version: ['11', '17', '21']

steps:
- name: Checkout code
Expand Down
5 changes: 3 additions & 2 deletions components/cdi/weld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
<artifactId>jakarta.el-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>${weld.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.ClientRequest;
import org.glassfish.jersey.client.ClientResponse;
import org.glassfish.jersey.client.internal.LocalizationMessages;
import org.glassfish.jersey.client.innate.ClientProxy;
import org.glassfish.jersey.client.spi.AsyncConnectorCallback;
import org.glassfish.jersey.client.spi.Connector;
import org.glassfish.jersey.internal.util.collection.ByteBufferInputStream;
Expand Down Expand Up @@ -79,8 +79,10 @@
* <li>{@link ClientProperties#PROXY_USERNAME}</li>
* <li>{@link ClientProperties#PROXY_PASSWORD}</li>
* <li>{@link ClientProperties#PROXY_PASSWORD}</li>
* <li>{@link JettyClientProperties#DISABLE_COOKIES}</li>*
* <li>{@link JettyClientProperties#ENABLE_SSL_HOSTNAME_VERIFICATION}</li>
* <li>{@link JettyClientProperties#PREEMPTIVE_BASIC_AUTHENTICATION}</li>
* <li>{@link JettyClientProperties#DISABLE_COOKIES}</li>
* <li>{@link JettyClientProperties#SYNC_LISTENER_RESPONSE_MAX_SIZE}</li>
* </ul>
* <p/>
* This transport supports both synchronous and asynchronous processing of client requests.
Expand Down Expand Up @@ -156,18 +158,22 @@ public Jetty10Connector(final Client jaxrsClient, final Configuration config) {

Boolean enableHostnameVerification = (Boolean) config.getProperties()
.get(JettyClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION);
if (enableHostnameVerification != null && enableHostnameVerification) {
client.getSslContextFactory().setEndpointIdentificationAlgorithm("https");
if (enableHostnameVerification != null) {
final String verificationAlgorithm = enableHostnameVerification ? "HTTPS" : null;
client.getSslContextFactory().setEndpointIdentificationAlgorithm(verificationAlgorithm);
}
if (jaxrsClient.getHostnameVerifier() != null) {
client.getSslContextFactory().setHostnameVerifier(jaxrsClient.getHostnameVerifier());
}

final Object connectTimeout = config.getProperties().get(ClientProperties.CONNECT_TIMEOUT);
if (connectTimeout instanceof Integer cTimeout && cTimeout > 0) {
client.setConnectTimeout(cTimeout);
if (connectTimeout instanceof Integer && (Integer) connectTimeout > 0) {
client.setConnectTimeout((Integer) connectTimeout);
}
final Object threadPoolSize = config.getProperties().get(ClientProperties.ASYNC_THREADPOOL_SIZE);
if (threadPoolSize instanceof Integer tPoolSize && tPoolSize > 0) {
if (threadPoolSize instanceof Integer && (Integer) threadPoolSize > 0) {
final String name = HttpClient.class.getSimpleName() + "@" + hashCode();
final QueuedThreadPool threadPool = new QueuedThreadPool(tPoolSize);
final QueuedThreadPool threadPool = new QueuedThreadPool((Integer) threadPoolSize);
threadPool.setName(name);
client.setExecutor(threadPool);
}
Expand All @@ -176,33 +182,31 @@ public Jetty10Connector(final Client jaxrsClient, final Configuration config) {

final AuthenticationStore auth = client.getAuthenticationStore();
final Object basicAuthProvider = config.getProperty(JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION);
if (basicAuthProvider instanceof BasicAuthentication baseAuth) {
auth.addAuthentication(baseAuth);
if ((basicAuthProvider instanceof BasicAuthentication)) {
auth.addAuthentication((BasicAuthentication) basicAuthProvider);
}

final Object proxyUri = config.getProperties().get(ClientProperties.PROXY_URI);
if (proxyUri != null) {
final URI u = getProxyUri(proxyUri);
final Optional<ClientProxy> proxy = ClientProxy.proxyFromConfiguration(config);
proxy.ifPresent(clientProxy -> {
final ProxyConfiguration proxyConfig = client.getProxyConfiguration();
proxyConfig.getProxies().add(new HttpProxy(u.getHost(), u.getPort()));
final URI u = clientProxy.uri();
proxyConfig.addProxy(new HttpProxy(u.getHost(), u.getPort()));

final Object proxyUsername = config.getProperties().get(ClientProperties.PROXY_USERNAME);
if (proxyUsername != null) {
final Object proxyPassword = config.getProperties().get(ClientProperties.PROXY_PASSWORD);
if (clientProxy.userName() != null) {
auth.addAuthentication(new BasicAuthentication(u, "<<ANY_REALM>>",
String.valueOf(proxyUsername), String.valueOf(proxyPassword)));
clientProxy.userName(), clientProxy.password()));
}
}
});

if (disableCookies) {
client.setCookieStore(new HttpCookieStore.Empty());
}

final Object slResponseMaxSize = configuration.getProperties()
.get(JettyClientProperties.SYNC_LISTENER_RESPONSE_MAX_SIZE);
if (slResponseMaxSize instanceof Integer slResponseMaxSizeC
&& slResponseMaxSizeC > 0) {
this.syncListenerResponseMaxSize = Optional.of(slResponseMaxSizeC);
if (slResponseMaxSize instanceof Integer
&& (Integer) slResponseMaxSize > 0) {
this.syncListenerResponseMaxSize = Optional.of((Integer) slResponseMaxSize);
} else {
this.syncListenerResponseMaxSize = Optional.empty();
}
Expand All @@ -215,17 +219,6 @@ public Jetty10Connector(final Client jaxrsClient, final Configuration config) {
this.cookieStore = client.getCookieStore();
}

@SuppressWarnings("ChainOfInstanceofChecks")
private static URI getProxyUri(final Object proxy) {
if (proxy instanceof URI uriProxy) {
return uriProxy;
} else if (proxy instanceof String stringProxy) {
return URI.create(stringProxy);
} else {
throw new ProcessingException(LocalizationMessages.WRONG_PROXY_URI_TYPE(ClientProperties.PROXY_URI));
}
}

/**
* Get the {@link HttpClient}.
*
Expand Down Expand Up @@ -257,7 +250,7 @@ public ClientResponse apply(final ClientRequest jerseyRequest) throws Processing

try {
final ContentResponse jettyResponse;
if (!syncListenerResponseMaxSize.isPresent()) {
if (syncListenerResponseMaxSize.isEmpty()) {
jettyResponse = jettyRequest.send();
} else {
final FutureResponseListener listener
Expand Down Expand Up @@ -317,10 +310,16 @@ private Request translateRequest(final ClientRequest clientRequest) {
request.method(clientRequest.getMethod());

request.followRedirects(clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true));
final Object readTimeout = clientRequest.resolveProperty(ClientProperties.READ_TIMEOUT, -1);
if (readTimeout instanceof Integer rTimeout && rTimeout > 0) {
request.timeout(rTimeout, TimeUnit.MILLISECONDS);
final Integer readTimeout = clientRequest.resolveProperty(ClientProperties.READ_TIMEOUT, -1);
if (readTimeout != null && readTimeout > 0) {
request.timeout(readTimeout, TimeUnit.MILLISECONDS);
}

final Integer totalTimeout = clientRequest.resolveProperty(JettyClientProperties.TOTAL_TIMEOUT, -1);
if (totalTimeout != null && totalTimeout > 0) {
request.timeout(totalTimeout, TimeUnit.MILLISECONDS);
}

return request;
}

Expand Down Expand Up @@ -394,9 +393,9 @@ public Future<?> apply(final ClientRequest jerseyRequest, final AsyncConnectorCa
final CompletableFuture<ClientResponse> responseFuture =
new CompletableFuture<ClientResponse>().whenComplete(
(clientResponse, throwable) -> {
if (throwable instanceof CancellationException throwable1) {
if (throwable instanceof CancellationException) {
// take care of future cancellation
jettyRequest.abort(throwable1);
jettyRequest.abort(throwable);

}
});
Expand Down
31 changes: 18 additions & 13 deletions core/src/main/java/com/kumuluz/ee/EeApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.logging.Handler;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
* @author Tilen Faganel
Expand All @@ -65,18 +66,20 @@ public EeApplication() {
initialize();
}

@SuppressWarnings("unused")
public EeApplication(EeConfig eeConfig) {

this.eeConfig = eeConfig;

initialize();
}

public static void main(String args[]) {
public static void main(String[] args) {

EeApplication app = new EeApplication();
new EeApplication();
}

@SuppressWarnings("unused")
public KumuluzServer getServer() {
return this.server.getServer();
}
Expand Down Expand Up @@ -186,24 +189,24 @@ private void initialize() {

List<EeRuntimeComponent> eeRuntimeComponents = eeComponents.stream()
.map(e -> new EeRuntimeComponent(e.getType(), e.getName()))
.toList();
.collect(Collectors.toList());

List<EeRuntimeComponent> serverEeRuntimeComponents = new ArrayList<>(Arrays.stream(server.getProvidedEeComponents())
List<EeRuntimeComponent> serverEeRuntimeComponents = Arrays.stream(server.getProvidedEeComponents())
.map(c -> new EeRuntimeComponent(c, server.getName()))
.toList());
.collect(Collectors.toList());

serverEeRuntimeComponents.addAll(eeRuntimeComponents);

eeRuntimeInternal.setEeComponents(serverEeRuntimeComponents);

List<EeRuntimeExtension> eeRuntimeExtensions = new ArrayList<>(eeExtensions.stream()
.map(e -> new EeRuntimeExtension(e.getGroup(), e.getName())).toList());
List<EeRuntimeExtension> eeRuntimeExtensions = eeExtensions.stream()
.map(e -> new EeRuntimeExtension(e.getGroup(), e.getName())).collect(Collectors.toList());

eeRuntimeExtensions.addAll(eeConfigExtensions.stream()
.map(e -> new EeRuntimeExtension(e.getGroup(), e.getName())).toList());
.map(e -> new EeRuntimeExtension(e.getGroup(), e.getName())).collect(Collectors.toList()));

eeRuntimeExtensions.addAll(eeLogsExtensions.stream()
.map(e -> new EeRuntimeExtension(e.getGroup(), e.getName())).toList());
.map(e -> new EeRuntimeExtension(e.getGroup(), e.getName())).collect(Collectors.toList()));

eeRuntimeInternal.setEeExtensions(eeRuntimeExtensions);

Expand Down Expand Up @@ -258,15 +261,17 @@ private void initialize() {
server.getServer().initServer();

// Depending on the server type, initiate server specific functionality
if (server.getServer() instanceof ServletServer servletServer) {
if (server.getServer() instanceof ServletServer) {

ServletServer servletServer = (ServletServer) server.getServer();

List<Extension> allExtensions = new ArrayList<>();
allExtensions.addAll(eeExtensions.stream().map(ExtensionWrapper::getExtension)
.toList());
.collect(Collectors.toList()));
allExtensions.addAll(eeConfigExtensions.stream().map(ExtensionWrapper::getExtension)
.toList());
.collect(Collectors.toList()));
allExtensions.addAll(eeLogsExtensions.stream().map(ExtensionWrapper::getExtension)
.toList());
.collect(Collectors.toList()));
servletServer.initWebContext(collectScanLibraries(allExtensions));

// Create and register datasources to the underlying server
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<url>https://ee.kumuluz.com</url>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<jakarta-xml-bind-api.version>4.0.1</jakarta-xml-bind-api.version>
Expand Down

0 comments on commit d37232d

Please sign in to comment.