diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index aabffef4..30241467 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -11,11 +11,11 @@ jobs:
- uses: actions/checkout@v1
- - name: Set up JDK 11
+ - name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
- java-version: '11'
+ java-version: '8'
- name: Cache dependencies
uses: actions/cache@v1
@@ -26,7 +26,7 @@ jobs:
${{ runner.os }}-maven-
- name: Build, test and quality scan
- run: mvn clean install sonar:sonar -P'!standalone-client' -Pjacoco -Dsonar.organization=hakky54 -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} --no-transfer-progress
+ run: mvn clean install -P'!standalone-client' --no-transfer-progress
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.actor == 'Hakky54'
@@ -40,11 +40,11 @@ jobs:
steps:
- uses: actions/checkout@v1
- - name: Set up JDK 11
+ - name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
- java-version: '11'
+ java-version: '8'
- name: Cache dependencies
uses: actions/cache@v1
@@ -62,11 +62,11 @@ jobs:
steps:
- uses: actions/checkout@v1
- - name: Set up JDK 11
+ - name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
- java-version: '11'
+ java-version: '8'
- name: Cache dependencies
uses: actions/cache@v1
@@ -84,11 +84,11 @@ jobs:
steps:
- uses: actions/checkout@v1
- - name: Set up JDK 11
+ - name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
- java-version: '11'
+ java-version: '8'
- name: Cache dependencies
uses: actions/cache@v1
diff --git a/.gitpod.yml b/.gitpod.yml
index df261f2c..9ce91689 100644
--- a/.gitpod.yml
+++ b/.gitpod.yml
@@ -1,3 +1,3 @@
-image: adoptopenjdk/maven-openjdk11:latest
+image: adoptopenjdk/maven-openjdk8:latest
tasks:
- init: mvn install
diff --git a/README.MD b/README.MD
index 66655fbe..ecc9d34a 100644
--- a/README.MD
+++ b/README.MD
@@ -8,7 +8,7 @@
[![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-white.svg)](https://sonarcloud.io/dashboard?id=nl.altindag%3Amutual-tls-ssl)
-[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Hakky54/mutual-tls)
+[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Hakky54/mutual-tls/tree/tutorial-for-java-8)
# Mastering two way TLS 🔐 [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=If%20you%20are%20interested%20in%20securing%20your%20web%20application,%20you%20might%20want%20to%20read%20the%20tutorial%20Mastering%20two-way%20tls&url=https://github.com/Hakky54/mutual-tls&via=hakky541&hashtags=encryption,security,https,ssl,tls,certificate,developer,java,scala,kotlin,sslcontextkickstart)
@@ -57,23 +57,17 @@ Also [GitHub - SSLContext Kickstart](https://github.com/Hakky54/sslcontext-kicks
# Tutorial
## Starting the server
**Minimum requirements:**
-1. Java 11
+1. Java 8
2. Maven 3.5.0
3. Eclipse, Intellij IDEA (or any other text editor like VIM)
4. A terminal
If you want to start instantly without installing any software, click the button below to open the project in an online development environment:
-[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Hakky54/mutual-tls)
+[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Hakky54/mutual-tls/tree/tutorial-for-java-8)
This project contains a maven wrapper, so you can run this project without installing maven. The documentation for this tutorial contains next to the default mvn command also the commands for the maven wrapper.
-If you want to run this project with Java 8, you can get an older version with the git command below.
-And it is recommended to follow the instruction for that specific version, which is available at this [page](https://github.com/Hakky54/mutual-tls-ssl/tree/java-8-compatible)
-```bash
-git checkout tags/java-8-compatible
-```
-
The server depends on the other components of the project, so run `mvn install` in the root directory first.
```bash
mvn install
diff --git a/client/pom.xml b/client/pom.xml
index 835ee7dd..d90aa841 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -122,10 +122,6 @@
io.github.openfeign
feign-core
-
- com.github.mizosoft.methanol
- methanol
-
io.ktor
ktor-client-core
@@ -146,10 +142,6 @@
io.ktor
ktor-client-android
-
- io.ktor
- ktor-client-java
-
org.http4k
http4k-core
diff --git a/client/src/main/java/nl/altindag/client/ClientConfig.java b/client/src/main/java/nl/altindag/client/ClientConfig.java
index 5711b02c..88217582 100644
--- a/client/src/main/java/nl/altindag/client/ClientConfig.java
+++ b/client/src/main/java/nl/altindag/client/ClientConfig.java
@@ -3,7 +3,6 @@
import akka.actor.ActorSystem;
import akka.http.javadsl.ConnectionContext;
import akka.http.javadsl.HttpsConnectionContext;
-import com.github.mizosoft.methanol.Methanol;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.gson.GsonBuilder;
@@ -15,6 +14,7 @@
import com.twitter.finagle.http.Response;
import com.typesafe.config.ConfigFactory;
import feign.Feign;
+import io.netty.handler.ssl.SslContext;
import io.vertx.core.Vertx;
import io.vertx.core.net.KeyCertOptions;
import io.vertx.core.net.TrustOptions;
@@ -41,7 +41,9 @@
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.impl.client.HttpClients;
import org.asynchttpclient.AsyncHttpClient;
+import org.asynchttpclient.DefaultAsyncHttpClientConfig;
import org.asynchttpclient.Dsl;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
@@ -58,7 +60,6 @@
import javax.net.ssl.SSLException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.net.http.HttpClient;
import static java.util.Objects.nonNull;
import static nl.altindag.client.Constants.SERVER_URL;
@@ -128,18 +129,6 @@ public org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient apache5Htt
return client;
}
- @Bean
- public HttpClient jdkHttpClient(@Autowired(required = false) SSLFactory sslFactory) {
- if (nonNull(sslFactory)) {
- return HttpClient.newBuilder()
- .sslParameters(sslFactory.getSslParameters())
- .sslContext(sslFactory.getSslContext())
- .build();
- } else {
- return HttpClient.newHttpClient();
- }
- }
-
@Bean
public RestTemplate restTemplate(org.apache.http.impl.client.CloseableHttpClient httpClient) {
return new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
@@ -150,7 +139,7 @@ public RestTemplate restTemplate(org.apache.http.impl.client.CloseableHttpClient
public OkHttpClient okHttpClient(@Autowired(required = false) SSLFactory sslFactory) {
if (nonNull(sslFactory)) {
return new OkHttpClient.Builder()
- .sslSocketFactory(sslFactory.getSslSocketFactory(), sslFactory.getTrustManager().orElseThrow())
+ .sslSocketFactory(sslFactory.getSslSocketFactory(), sslFactory.getTrustManager().get())
.hostnameVerifier(sslFactory.getHostnameVerifier())
.build();
} else {
@@ -161,9 +150,9 @@ public OkHttpClient okHttpClient(@Autowired(required = false) SSLFactory sslFact
@Bean
@Scope("prototype")
public reactor.netty.http.client.HttpClient nettyHttpClient(@Autowired(required = false) SSLFactory sslFactory) throws SSLException {
- var httpClient = reactor.netty.http.client.HttpClient.create();
+ reactor.netty.http.client.HttpClient httpClient = reactor.netty.http.client.HttpClient.create();
if (nonNull(sslFactory)) {
- var sslContext = NettySslUtils.forClient(sslFactory).build();
+ SslContext sslContext = NettySslUtils.forClient(sslFactory).build();
httpClient = httpClient.secure(sslSpec -> sslSpec.sslContext(sslContext));
}
return httpClient;
@@ -173,7 +162,7 @@ public reactor.netty.http.client.HttpClient nettyHttpClient(@Autowired(required
@Scope("prototype")
public org.eclipse.jetty.client.HttpClient jettyHttpClient(@Autowired(required = false) SSLFactory sslFactory) {
if (nonNull(sslFactory)) {
- var sslContextFactory = JettySslUtils.forClient(sslFactory);
+ SslContextFactory sslContextFactory = JettySslUtils.forClient(sslFactory);
return new org.eclipse.jetty.client.HttpClient(sslContextFactory);
} else {
return new org.eclipse.jetty.client.HttpClient();
@@ -209,7 +198,7 @@ public Client jerseyClient(@Autowired(required = false) SSLFactory sslFactory) {
@Bean
public com.sun.jersey.api.client.Client oldJerseyClient(@Autowired(required = false) SSLFactory sslFactory) {
if (nonNull(sslFactory)) {
- var clientConfig = new DefaultClientConfig();
+ DefaultClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(sslFactory.getHostnameVerifier(), sslFactory.getSslContext()));
return com.sun.jersey.api.client.Client.create(clientConfig);
} else {
@@ -236,13 +225,13 @@ public javax.ws.rs.client.Client cxfJaxRsClient(@Autowired(required = false) SSL
@Bean
public org.apache.cxf.jaxrs.client.WebClient cxfWebClient(@Autowired(required = false) SSLFactory sslFactory) {
- var factory = new JAXRSClientFactoryBean();
+ JAXRSClientFactoryBean factory = new JAXRSClientFactoryBean();
factory.setAddress(SERVER_URL);
if (nonNull(sslFactory)) {
// One can also get conduit from WebClient.getConfig(webClient).getHttpConduit() and change it directly
factory.setBus(new CXFBusFactory().createBus());
factory.getBus().setExtension((name, address, httpConduit) -> {
- var tls = new TLSClientParameters();
+ TLSClientParameters tls = new TLSClientParameters();
tls.setSSLSocketFactory(sslFactory.getSslSocketFactory());
tls.setHostnameVerifier(sslFactory.getHostnameVerifier());
httpConduit.setTlsClientParameters(tls);
@@ -286,8 +275,8 @@ public Retrofit retrofit(OkHttpClient okHttpClient) {
@Bean
public Service finagle(@Autowired(required = false) SSLFactory sslFactory) throws URISyntaxException {
- var uri = new URI(SERVER_URL);
- var client = Http.client();
+ URI uri = new URI(SERVER_URL);
+ Http.Client client = Http.client();
if (nonNull(sslFactory)) {
client = client
.withNoHttp2()
@@ -308,7 +297,7 @@ public ActorSystem actorSystem() {
@Bean
public akka.http.javadsl.Http akkaHttpClient(@Autowired(required = false) SSLFactory sslFactory,
ActorSystem actorSystem) {
- var http = akka.http.javadsl.Http.get(actorSystem);
+ akka.http.javadsl.Http http = akka.http.javadsl.Http.get(actorSystem);
if (nonNull(sslFactory)) {
HttpsConnectionContext httpsContext = ConnectionContext.httpsClient(sslFactory.getSslContext());
http.setDefaultClientHttpsContext(httpsContext);
@@ -319,9 +308,9 @@ public akka.http.javadsl.Http akkaHttpClient(@Autowired(required = false) SSLFac
@Bean
public AsyncHttpClient asyncHttpClient(@Autowired(required = false) SSLFactory sslFactory) throws SSLException {
if (nonNull(sslFactory)) {
- var sslContext = NettySslUtils.forClient(sslFactory).build();
+ SslContext sslContext = NettySslUtils.forClient(sslFactory).build();
- var clientConfigBuilder = dispatch.Http.defaultClientBuilder()
+ DefaultAsyncHttpClientConfig.Builder clientConfigBuilder = dispatch.Http.defaultClientBuilder()
.setSslContext(sslContext);
return Dsl.asyncHttpClient(clientConfigBuilder);
@@ -340,21 +329,9 @@ public Feign.Builder feign(@Autowired(required = false) SSLFactory sslFactory) {
}
}
- @Bean
- public Methanol methanol(@Autowired(required = false) SSLFactory sslFactory) {
- if (nonNull(sslFactory)) {
- return Methanol.newBuilder()
- .sslContext(sslFactory.getSslContext())
- .sslParameters(sslFactory.getSslParameters())
- .build();
- } else {
- return Methanol.create();
- }
- }
-
@Bean
public io.vertx.ext.web.client.WebClient vertxWebClient(@Autowired(required = false) SSLFactory sslFactory) {
- var clientOptions = new WebClientOptions();
+ WebClientOptions clientOptions = new WebClientOptions();
if (nonNull(sslFactory)) {
clientOptions.setSsl(true);
diff --git a/client/src/main/java/nl/altindag/client/PropertyResolver.java b/client/src/main/java/nl/altindag/client/PropertyResolver.java
index c333cab6..35205c06 100644
--- a/client/src/main/java/nl/altindag/client/PropertyResolver.java
+++ b/client/src/main/java/nl/altindag/client/PropertyResolver.java
@@ -20,8 +20,8 @@ public class PropertyResolver {
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
- var propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
- var yaml = new YamlPropertiesFactoryBean();
+ PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
+ YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
yaml.setResources(new ClassPathResource(CLIENT_PROPERTY_FILE));
propertySourcesPlaceholderConfigurer.setProperties(Objects.requireNonNull(yaml.getObject()));
return propertySourcesPlaceholderConfigurer;
diff --git a/client/src/main/java/nl/altindag/client/SSLConfig.java b/client/src/main/java/nl/altindag/client/SSLConfig.java
index ef8e70c5..1563a819 100644
--- a/client/src/main/java/nl/altindag/client/SSLConfig.java
+++ b/client/src/main/java/nl/altindag/client/SSLConfig.java
@@ -37,7 +37,7 @@ public SSLFactory sslFactory(
if (oneWayAuthenticationEnabled) {
sslFactory = SSLFactory.builder()
.withTrustMaterial(trustStorePath, trustStorePassword)
- .withProtocols("TLSv1.3")
+ .withProtocols("TLSv1.2")
.build();
}
@@ -45,7 +45,7 @@ public SSLFactory sslFactory(
sslFactory = SSLFactory.builder()
.withIdentityMaterial(keyStorePath, keyStorePassword)
.withTrustMaterial(trustStorePath, trustStorePassword)
- .withProtocols("TLSv1.3")
+ .withProtocols("TLSv1.2")
.build();
}
diff --git a/client/src/main/java/nl/altindag/client/service/Apache5HttpAsyncClientService.java b/client/src/main/java/nl/altindag/client/service/Apache5HttpAsyncClientService.java
index c733ef59..eb3dc68e 100644
--- a/client/src/main/java/nl/altindag/client/service/Apache5HttpAsyncClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/Apache5HttpAsyncClientService.java
@@ -2,6 +2,7 @@
import nl.altindag.client.ClientType;
import nl.altindag.client.model.ClientResponse;
+import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
@@ -26,7 +27,7 @@ public Apache5HttpAsyncClientService(CloseableHttpAsyncClient httpClient) {
@Override
public ClientResponse executeRequest(String url) throws Exception {
- var request = SimpleHttpRequests.get(url);
+ SimpleHttpRequest request = SimpleHttpRequests.get(url);
request.addHeader(HEADER_KEY_CLIENT_TYPE, getClientType().getValue());
Future responseFuture = httpClient.execute(request, null);
diff --git a/client/src/main/java/nl/altindag/client/service/ApacheCXFJaxRsClientService.java b/client/src/main/java/nl/altindag/client/service/ApacheCXFJaxRsClientService.java
index 80030d05..86b5a20e 100644
--- a/client/src/main/java/nl/altindag/client/service/ApacheCXFJaxRsClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/ApacheCXFJaxRsClientService.java
@@ -7,6 +7,7 @@
import javax.ws.rs.client.Client;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import static nl.altindag.client.ClientType.APACHE_CXF_JAX_RS;
import static nl.altindag.client.Constants.HEADER_KEY_CLIENT_TYPE;
@@ -26,7 +27,7 @@ public ApacheCXFJaxRsClientService(@Qualifier("cxf") Client client) {
@Override
public ClientResponse executeRequest(String url) {
- var response = client.target(url)
+ Response response = client.target(url)
.request(MediaType.TEXT_PLAIN_TYPE)
.header(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
.get();
diff --git a/client/src/main/java/nl/altindag/client/service/ApacheCXFWebClientService.java b/client/src/main/java/nl/altindag/client/service/ApacheCXFWebClientService.java
index bb395ab1..a44094e1 100644
--- a/client/src/main/java/nl/altindag/client/service/ApacheCXFWebClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/ApacheCXFWebClientService.java
@@ -6,6 +6,7 @@
import org.springframework.stereotype.Service;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import static nl.altindag.client.ClientType.APACHE_CXF_WEB_CLIENT;
import static nl.altindag.client.Constants.HEADER_KEY_CLIENT_TYPE;
@@ -24,7 +25,7 @@ public ApacheCXFWebClientService(WebClient client) {
@Override
public ClientResponse executeRequest(String url) throws Exception {
- var response = client.to(url, false)
+ Response response = client.to(url, false)
.accept(MediaType.TEXT_PLAIN_TYPE)
.header(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
.get();
diff --git a/client/src/main/java/nl/altindag/client/service/ApacheHttpAsyncClientService.java b/client/src/main/java/nl/altindag/client/service/ApacheHttpAsyncClientService.java
index f5d630d0..9e155281 100644
--- a/client/src/main/java/nl/altindag/client/service/ApacheHttpAsyncClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/ApacheHttpAsyncClientService.java
@@ -27,13 +27,13 @@ public ApacheHttpAsyncClientService(CloseableHttpAsyncClient httpClient) {
@Override
public ClientResponse executeRequest(String url) throws Exception {
- var request = new HttpGet(url);
+ HttpGet request = new HttpGet(url);
request.addHeader(HEADER_KEY_CLIENT_TYPE, getClientType().getValue());
Future responseFuture = httpClient.execute(request, null);
HttpResponse response = responseFuture.get(TIMEOUT_AMOUNT_IN_SECONDS, TimeUnit.SECONDS);
- var responseBody = EntityUtils.toString(response.getEntity());
+ String responseBody = EntityUtils.toString(response.getEntity());
int statusCode = response.getStatusLine().getStatusCode();
return new ClientResponse(responseBody, statusCode);
}
diff --git a/client/src/main/java/nl/altindag/client/service/ApacheHttpClientService.java b/client/src/main/java/nl/altindag/client/service/ApacheHttpClientService.java
index 03ca5fe5..a9668be6 100644
--- a/client/src/main/java/nl/altindag/client/service/ApacheHttpClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/ApacheHttpClientService.java
@@ -25,11 +25,11 @@ public ApacheHttpClientService(CloseableHttpClient httpClient) {
@Override
public ClientResponse executeRequest(String url) throws IOException {
- var request = new HttpGet(url);
+ HttpGet request = new HttpGet(url);
request.addHeader(HEADER_KEY_CLIENT_TYPE, getClientType().getValue());
HttpResponse response = httpClient.execute(request);
- var responseBody = EntityUtils.toString(response.getEntity());
+ String responseBody = EntityUtils.toString(response.getEntity());
int statusCode = response.getStatusLine().getStatusCode();
return new ClientResponse(responseBody, statusCode);
}
diff --git a/client/src/main/java/nl/altindag/client/service/AsyncHttpClientService.java b/client/src/main/java/nl/altindag/client/service/AsyncHttpClientService.java
index 37aeeb4e..db30cfb3 100644
--- a/client/src/main/java/nl/altindag/client/service/AsyncHttpClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/AsyncHttpClientService.java
@@ -4,6 +4,7 @@
import nl.altindag.client.model.ClientResponse;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.RequestBuilder;
+import org.asynchttpclient.Response;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
@@ -24,11 +25,11 @@ public AsyncHttpClientService(AsyncHttpClient httpClient) {
@Override
public ClientResponse executeRequest(String url) throws Exception {
- var requestBuilder = new RequestBuilder()
+ RequestBuilder requestBuilder = new RequestBuilder()
.setUrl(url)
.setHeader(HEADER_KEY_CLIENT_TYPE, getClientType().getValue());
- var response = httpClient.executeRequest(requestBuilder)
+ Response response = httpClient.executeRequest(requestBuilder)
.toCompletableFuture()
.get(TIMEOUT_AMOUNT_IN_SECONDS, TimeUnit.SECONDS);
diff --git a/client/src/main/java/nl/altindag/client/service/FinagleHttpClientService.java b/client/src/main/java/nl/altindag/client/service/FinagleHttpClientService.java
index 5800ee2f..925c92ed 100644
--- a/client/src/main/java/nl/altindag/client/service/FinagleHttpClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/FinagleHttpClientService.java
@@ -25,7 +25,7 @@ public FinagleHttpClientService(com.twitter.finagle.Service f
@Override
public ClientResponse executeRequest(String url) throws Exception {
- var request = new RequestBuilder<>()
+ Request request = new RequestBuilder<>()
.addHeader(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
.url(url)
.buildGet(null);
diff --git a/client/src/main/java/nl/altindag/client/service/Http4kJavaHttpClientService.kt b/client/src/main/java/nl/altindag/client/service/Http4kJavaHttpClientService.kt
deleted file mode 100644
index c87d5e96..00000000
--- a/client/src/main/java/nl/altindag/client/service/Http4kJavaHttpClientService.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package nl.altindag.client.service
-
-import nl.altindag.client.ClientType
-import nl.altindag.client.ClientType.HTTP4K_JAVA_HTTP_CLIENT
-import nl.altindag.ssl.SSLFactory
-import org.http4k.client.JavaHttpClient
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.stereotype.Service
-import java.net.http.HttpClient
-
-@Service
-class Http4kJavaHttpClientService(
- @Autowired(required = false)
- sslFactory: SSLFactory?
-) : Http4kClientService(
- JavaHttpClient(
- httpClient = sslFactory?.let { factory ->
- HttpClient.newBuilder()
- .sslParameters(factory.sslParameters)
- .sslContext(factory.sslContext)
- .build()
- } ?: HttpClient.newHttpClient()
- )
-) {
-
- override fun getClientType(): ClientType = HTTP4K_JAVA_HTTP_CLIENT
-
-}
\ No newline at end of file
diff --git a/client/src/main/java/nl/altindag/client/service/Http4kOkHttpClientService.kt b/client/src/main/java/nl/altindag/client/service/Http4kOkHttpClientService.kt
index 8dd6cc42..a05e7143 100644
--- a/client/src/main/java/nl/altindag/client/service/Http4kOkHttpClientService.kt
+++ b/client/src/main/java/nl/altindag/client/service/Http4kOkHttpClientService.kt
@@ -16,7 +16,7 @@ class Http4kOkHttpClientService(
OkHttp(
client = sslFactory?.let { factory ->
OkHttpClient().newBuilder()
- .sslSocketFactory(factory.sslSocketFactory, factory.trustManager.orElseThrow())
+ .sslSocketFactory(factory.sslSocketFactory, factory.trustManager.get())
.hostnameVerifier(factory.hostnameVerifier)
.build()
} ?: OkHttpClient()
diff --git a/client/src/main/java/nl/altindag/client/service/JdkHttpClientService.java b/client/src/main/java/nl/altindag/client/service/JdkHttpClientService.java
deleted file mode 100644
index 592887f2..00000000
--- a/client/src/main/java/nl/altindag/client/service/JdkHttpClientService.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package nl.altindag.client.service;
-
-import static nl.altindag.client.ClientType.JDK_HTTP_CLIENT;
-import static nl.altindag.client.Constants.HEADER_KEY_CLIENT_TYPE;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Service;
-
-import nl.altindag.client.ClientType;
-import nl.altindag.client.model.ClientResponse;
-
-@Service
-public class JdkHttpClientService implements RequestService {
-
- private final HttpClient httpClient;
-
- public JdkHttpClientService(@Qualifier("jdkHttpClient") HttpClient httpClient) {
- this.httpClient = httpClient;
- }
-
- @Override
- public ClientResponse executeRequest(String url) throws IOException, InterruptedException {
- HttpRequest request = HttpRequest.newBuilder()
- .GET()
- .header(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
- .uri(URI.create(url))
- .build();
-
- HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
-
- return new ClientResponse(response.body(), response.statusCode());
- }
-
- @Override
- public ClientType getClientType() {
- return JDK_HTTP_CLIENT;
- }
-
-}
diff --git a/client/src/main/java/nl/altindag/client/service/JerseyClientService.java b/client/src/main/java/nl/altindag/client/service/JerseyClientService.java
index b61fed67..3da97f50 100644
--- a/client/src/main/java/nl/altindag/client/service/JerseyClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/JerseyClientService.java
@@ -6,6 +6,7 @@
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
import org.springframework.stereotype.Service;
import nl.altindag.client.ClientType;
@@ -22,7 +23,7 @@ public JerseyClientService(Client client) {
@Override
public ClientResponse executeRequest(String url) {
- var response = client.target(url)
+ Response response = client.target(url)
.request(MediaType.TEXT_PLAIN_TYPE)
.header(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
.get();
diff --git a/client/src/main/java/nl/altindag/client/service/JettyReactiveHttpClientService.java b/client/src/main/java/nl/altindag/client/service/JettyReactiveHttpClientService.java
index 0a31333d..8bb68051 100644
--- a/client/src/main/java/nl/altindag/client/service/JettyReactiveHttpClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/JettyReactiveHttpClientService.java
@@ -3,6 +3,7 @@
import nl.altindag.client.ClientType;
import nl.altindag.client.model.ClientResponse;
import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpMethod;
import org.springframework.stereotype.Service;
@@ -22,7 +23,7 @@ public JettyReactiveHttpClientService(HttpClient httpClient) {
public ClientResponse executeRequest(String url) throws Exception {
httpClient.start();
- var contentResponse = httpClient.newRequest(url)
+ ContentResponse contentResponse = httpClient.newRequest(url)
.method(HttpMethod.GET)
.header(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
.send();
diff --git a/client/src/main/java/nl/altindag/client/service/KohttpService.kt b/client/src/main/java/nl/altindag/client/service/KohttpService.kt
index d87a5c73..78138bbd 100644
--- a/client/src/main/java/nl/altindag/client/service/KohttpService.kt
+++ b/client/src/main/java/nl/altindag/client/service/KohttpService.kt
@@ -54,7 +54,7 @@ class KohttpClientConfig {
client {
sslConfig = SslConfig().apply {
sslSocketFactory = factory.sslSocketFactory
- trustManager = factory.trustManager.orElseThrow()
+ trustManager = factory.trustManager.get()
hostnameVerifier = factory.hostnameVerifier
}
}
diff --git a/client/src/main/java/nl/altindag/client/service/KtorJavaHttpClientService.kt b/client/src/main/java/nl/altindag/client/service/KtorJavaHttpClientService.kt
deleted file mode 100644
index 4e30536f..00000000
--- a/client/src/main/java/nl/altindag/client/service/KtorJavaHttpClientService.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-package nl.altindag.client.service
-
-import io.ktor.client.HttpClient
-import io.ktor.client.engine.java.Java
-import nl.altindag.client.ClientType
-import nl.altindag.client.ClientType.KTOR_JAVA_HTTP_CLIENT
-import nl.altindag.ssl.SSLFactory
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.stereotype.Service
-
-@Service
-class KtorJavaHttpClientService(
- @Autowired(required = false)
- sslFactory: SSLFactory?
-): KtorHttpClientService(
- HttpClient(Java) {
- sslFactory?.let { factory ->
- engine {
- config {
- sslContext(factory.sslContext)
- sslParameters(factory.sslParameters)
- }
- }
- }
- }
-) {
-
- override fun getClientType(): ClientType = KTOR_JAVA_HTTP_CLIENT
-
-}
diff --git a/client/src/main/java/nl/altindag/client/service/KtorOkHttpClientService.kt b/client/src/main/java/nl/altindag/client/service/KtorOkHttpClientService.kt
index cb22dea1..f23f2c32 100644
--- a/client/src/main/java/nl/altindag/client/service/KtorOkHttpClientService.kt
+++ b/client/src/main/java/nl/altindag/client/service/KtorOkHttpClientService.kt
@@ -17,7 +17,7 @@ class KtorOkHttpClientService(
sslFactory?.let { factory ->
engine {
config {
- sslSocketFactory(factory.sslSocketFactory, factory.trustManager.orElseThrow())
+ sslSocketFactory(factory.sslSocketFactory, factory.trustManager.get())
hostnameVerifier(factory.hostnameVerifier)
}
}
diff --git a/client/src/main/java/nl/altindag/client/service/MethanolService.java b/client/src/main/java/nl/altindag/client/service/MethanolService.java
deleted file mode 100644
index 1bb7f754..00000000
--- a/client/src/main/java/nl/altindag/client/service/MethanolService.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package nl.altindag.client.service;
-
-import com.github.mizosoft.methanol.Methanol;
-import com.github.mizosoft.methanol.MutableRequest;
-import nl.altindag.client.ClientType;
-import nl.altindag.client.model.ClientResponse;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Service;
-
-import java.io.IOException;
-import java.net.http.HttpResponse;
-
-import static nl.altindag.client.ClientType.METHANOL;
-import static nl.altindag.client.Constants.HEADER_KEY_CLIENT_TYPE;
-
-@Service
-public class MethanolService implements RequestService {
-
- private final Methanol httpClient;
-
- public MethanolService(@Qualifier("methanol") Methanol httpClient) {
- this.httpClient = httpClient;
- }
-
- @Override
- public ClientResponse executeRequest(String url) throws IOException, InterruptedException {
- MutableRequest request = MutableRequest.GET(url).header(HEADER_KEY_CLIENT_TYPE, getClientType().getValue());
-
- HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
-
- return new ClientResponse(response.body(), response.statusCode());
- }
-
- @Override
- public ClientType getClientType() {
- return METHANOL;
- }
-
-}
diff --git a/client/src/main/java/nl/altindag/client/service/OkHttpClientService.java b/client/src/main/java/nl/altindag/client/service/OkHttpClientService.java
index 7bf5cca7..d15a97cc 100644
--- a/client/src/main/java/nl/altindag/client/service/OkHttpClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/OkHttpClientService.java
@@ -4,6 +4,7 @@
import nl.altindag.client.model.ClientResponse;
import okhttp3.OkHttpClient;
import okhttp3.Request;
+import okhttp3.Response;
import org.springframework.stereotype.Service;
import java.io.IOException;
@@ -23,12 +24,12 @@ public OkHttpClientService(OkHttpClient okHttpClient) {
@Override
public ClientResponse executeRequest(String url) throws IOException {
- var request = new Request.Builder()
+ Request request = new Request.Builder()
.url(url)
.header(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
.build();
- var response = okHttpClient.newCall(request).execute();
+ Response response = okHttpClient.newCall(request).execute();
return new ClientResponse(Objects.requireNonNull(response.body()).string(), response.code());
}
diff --git a/client/src/main/java/nl/altindag/client/service/OldJdkHttpClientService.java b/client/src/main/java/nl/altindag/client/service/OldJdkHttpClientService.java
index ed05a6cd..1a8f40c6 100644
--- a/client/src/main/java/nl/altindag/client/service/OldJdkHttpClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/OldJdkHttpClientService.java
@@ -40,7 +40,7 @@ public ClientResponse executeRequest(String url) throws IOException {
if (url.contains(HTTP_REQUEST)) {
connection = createHttpURLConnection(url);
} else if (url.contains(HTTPS_REQUEST)) {
- var httpsURLConnection = createHttpsURLConnection(url);
+ HttpsURLConnection httpsURLConnection = createHttpsURLConnection(url);
httpsURLConnection.setHostnameVerifier(sslFactory.getHostnameVerifier());
httpsURLConnection.setSSLSocketFactory(sslFactory.getSslSocketFactory());
connection = httpsURLConnection;
@@ -53,7 +53,7 @@ public ClientResponse executeRequest(String url) throws IOException {
connection.setRequestMethod(HttpGet.METHOD_NAME);
connection.setRequestProperty(HEADER_KEY_CLIENT_TYPE, getClientType().getValue());
- var responseBody = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
+ String responseBody = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
return new ClientResponse(responseBody, connection.getResponseCode());
}
diff --git a/client/src/main/java/nl/altindag/client/service/OldJerseyClientService.java b/client/src/main/java/nl/altindag/client/service/OldJerseyClientService.java
index c8ed4abc..5ebc7ebe 100644
--- a/client/src/main/java/nl/altindag/client/service/OldJerseyClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/OldJerseyClientService.java
@@ -21,7 +21,7 @@ public OldJerseyClientService(Client client) {
@Override
public ClientResponse executeRequest(String url) {
- var clientResponse = client.resource(url)
+ com.sun.jersey.api.client.ClientResponse clientResponse = client.resource(url)
.header(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
.get(com.sun.jersey.api.client.ClientResponse.class);
diff --git a/client/src/main/java/nl/altindag/client/service/SpringRestTemplateService.java b/client/src/main/java/nl/altindag/client/service/SpringRestTemplateService.java
index bb70802e..4c82cf35 100644
--- a/client/src/main/java/nl/altindag/client/service/SpringRestTemplateService.java
+++ b/client/src/main/java/nl/altindag/client/service/SpringRestTemplateService.java
@@ -24,7 +24,7 @@ public SpringRestTemplateService(RestTemplate restTemplate) {
@Override
public ClientResponse executeRequest(String url) {
- var headers = new HttpHeaders();
+ HttpHeaders headers = new HttpHeaders();
headers.add(HEADER_KEY_CLIENT_TYPE, getClientType().getValue());
HttpEntity entity = new HttpEntity<>(null, headers);
diff --git a/client/src/main/java/nl/altindag/client/service/VertxWebClientService.java b/client/src/main/java/nl/altindag/client/service/VertxWebClientService.java
index aefbdbb0..09a7d198 100644
--- a/client/src/main/java/nl/altindag/client/service/VertxWebClientService.java
+++ b/client/src/main/java/nl/altindag/client/service/VertxWebClientService.java
@@ -25,7 +25,7 @@ public VertxWebClientService(WebClient client) {
@Override
public ClientResponse executeRequest(String url) throws Exception {
- var uri = URI.create(url);
+ URI uri = URI.create(url);
HttpResponse response = client.get(uri.getPort(), uri.getHost(), uri.getPath())
.putHeader(HEADER_KEY_CLIENT_TYPE, getClientType().getValue())
diff --git a/client/src/main/java/nl/altindag/client/stepdefs/HelloStepDefs.java b/client/src/main/java/nl/altindag/client/stepdefs/HelloStepDefs.java
index 2bd622d1..5793beeb 100644
--- a/client/src/main/java/nl/altindag/client/stepdefs/HelloStepDefs.java
+++ b/client/src/main/java/nl/altindag/client/stepdefs/HelloStepDefs.java
@@ -9,6 +9,7 @@
import nl.altindag.client.ClientType;
import nl.altindag.client.TestScenario;
import nl.altindag.client.aspect.LogExecutionTime;
+import nl.altindag.client.model.ClientResponse;
import nl.altindag.client.service.RequestService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -43,11 +44,11 @@ public void serverIsAlive() {
public void iSayHelloWithClient(String client) throws Exception {
String url = SERVER_URL + HELLO_ENDPOINT;
- var clientType = ClientType.from(client);
- var requestService = getRequestService(clientType)
+ ClientType clientType = ClientType.from(client);
+ RequestService requestService = getRequestService(clientType)
.orElseThrow(() -> new ClientException(String.format("Received a not supported [%s] client type", clientType.getValue())));
- var clientResponse = requestService.executeRequest(url);
+ ClientResponse clientResponse = requestService.executeRequest(url);
testScenario.setClientResponse(clientResponse);
}
diff --git a/client/src/test/java/nl/altindag/client/ClientConfigShould.java b/client/src/test/java/nl/altindag/client/ClientConfigShould.java
index dd2555da..67dbb97e 100644
--- a/client/src/test/java/nl/altindag/client/ClientConfigShould.java
+++ b/client/src/test/java/nl/altindag/client/ClientConfigShould.java
@@ -2,13 +2,11 @@
import akka.actor.ActorSystem;
import akka.http.javadsl.Http;
-import com.github.mizosoft.methanol.Methanol;
import com.google.api.client.http.HttpTransport;
import com.twitter.finagle.Service;
import com.twitter.finagle.http.Request;
import com.twitter.finagle.http.Response;
import feign.Feign;
-import jakarta.ws.rs.client.Client;
import kong.unirest.Unirest;
import nl.altindag.ssl.SSLFactory;
import okhttp3.OkHttpClient;
@@ -111,24 +109,6 @@ void createApache5HttpAsyncClientWithSecurity() {
verify(sslFactory, times(1)).getSslContext();
}
- @Test
- void createJdkHttpClientWithoutSecurity() {
- java.net.http.HttpClient httpClient = victim.jdkHttpClient(null);
-
- assertThat(httpClient).isNotNull();
- }
-
- @Test
- void createJdkHttpClientWithSecurity() {
- SSLFactory sslFactory = createSSLFactory(false, true);
-
- java.net.http.HttpClient httpClient = victim.jdkHttpClient(sslFactory);
-
- assertThat(httpClient).isNotNull();
- verify(sslFactory, times(1)).getSslContext();
- verify(sslFactory, times(1)).getSslParameters();
- }
-
@Test
void createRestTemplate() {
CloseableHttpClient httpClient = mock(CloseableHttpClient.class);
@@ -238,35 +218,6 @@ void createWebClientWithJetty() {
assertThat(webClient).isNotNull();
}
- @Test
- void createJerseyClientWithoutSecurity() {
- Client client = victim.jerseyClient(null);
-
- assertThat(client).isNotNull();
- assertThat(client.getClass().getPackageName())
- .as("Jersey JAX-RS implemenatsion is used")
- .startsWith("org.glassfish.jersey");
-
- client.close();
- }
-
- @Test
- void createJerseyClientWithSecurity() {
- SSLFactory sslFactory = createSSLFactory(false, true);
-
- Client client = victim.jerseyClient(sslFactory);
-
- assertThat(client).isNotNull();
- assertThat(client.getClass().getPackageName())
- .as("Jersey JAX-RS implemenatsion is used")
- .startsWith("org.glassfish.jersey");
-
- verify(sslFactory, times(1)).getSslContext();
- verify(sslFactory, times(1)).getHostnameVerifier();
-
- client.close();
- }
-
@Test
void createOldJerseyClientWithoutSecurity() {
com.sun.jersey.api.client.Client client = victim.oldJerseyClient(null);
@@ -289,21 +240,6 @@ void createOldJerseyClientWithSecurity() {
client.destroy();
}
- @Test
- void createCxfJaxRsClientWithoutSecurity() {
- javax.ws.rs.client.Client client = victim.cxfJaxRsClient(null);
-
- assertThat(client).isNotNull();
- assertThat(client.getClass().getPackageName())
- .as("CXF JAX-RS implemenatsion is used")
- .startsWith("org.apache.cxf");
-
- assertThat(client.getSslContext()).isNull();
- assertThat(client.getHostnameVerifier()).isNull();
-
- client.close();
- }
-
@Test
void createCxfJaxRsClientWithSecurity() {
SSLFactory sslFactory = createSSLFactory(false, true);
@@ -504,24 +440,6 @@ void createFeignWithSecurity() {
verify(sslFactory, times(1)).getHostnameVerifier();
}
- @Test
- void createMethanolWithoutSecurity() {
- Methanol httpClient = victim.methanol(null);
-
- assertThat(httpClient).isNotNull();
- }
-
- @Test
- void createMethanolWithSecurity() {
- SSLFactory sslFactory = createSSLFactory(true, true);
-
- Methanol httpClient = victim.methanol(sslFactory);
-
- assertThat(httpClient).isNotNull();
- verify(sslFactory, times(1)).getSslContext();
- verify(sslFactory, times(1)).getSslParameters();
- }
-
@Test
void createVertxWithoutSecurity() {
io.vertx.ext.web.client.WebClient webClient = victim.vertxWebClient(null);
diff --git a/client/src/test/java/nl/altindag/client/SSLConfigShould.java b/client/src/test/java/nl/altindag/client/SSLConfigShould.java
index b9e2570a..1328163a 100644
--- a/client/src/test/java/nl/altindag/client/SSLConfigShould.java
+++ b/client/src/test/java/nl/altindag/client/SSLConfigShould.java
@@ -22,7 +22,7 @@ void createSslFactoryWithOneWayAuthentication() {
assertThat(sslFactory.getSslContext()).isNotNull();
assertThat(sslFactory.getKeyManager()).isNotPresent();
assertThat(sslFactory.getTrustManager()).isNotNull();
- assertThat(sslFactory.getProtocols()).contains("TLSv1.3");
+ assertThat(sslFactory.getProtocols()).contains("TLSv1.2");
}
@Test
@@ -39,7 +39,7 @@ void createSslFactoryWithTwoWayAuthentication() {
assertThat(sslFactory.getSslContext()).isNotNull();
assertThat(sslFactory.getKeyManager()).isPresent();
assertThat(sslFactory.getTrustManager()).isNotNull();
- assertThat(sslFactory.getProtocols()).contains("TLSv1.3");
+ assertThat(sslFactory.getProtocols()).contains("TLSv1.2");
}
@Test
diff --git a/client/src/test/java/nl/altindag/client/service/Http4kJavaHttpClientServiceShould.kt b/client/src/test/java/nl/altindag/client/service/Http4kJavaHttpClientServiceShould.kt
deleted file mode 100644
index 4c220f60..00000000
--- a/client/src/test/java/nl/altindag/client/service/Http4kJavaHttpClientServiceShould.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package nl.altindag.client.service
-
-import com.nhaarman.mockitokotlin2.times
-import com.nhaarman.mockitokotlin2.verify
-import nl.altindag.client.ClientType.HTTP4K_JAVA_HTTP_CLIENT
-import nl.altindag.client.TestConstants
-import nl.altindag.client.util.MockServerTestHelper
-import nl.altindag.client.util.SSLFactoryTestHelper
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-
-class Http4kJavaHttpClientServiceShould {
-
- @Test
- fun executeRequest() {
- MockServerTestHelper.mockResponseForClient(HTTP4K_JAVA_HTTP_CLIENT)
-
- val client = Http4kJavaHttpClientService(null)
- val response = client.executeRequest(TestConstants.HTTP_URL)
-
- assertThat(response.responseBody).isEqualTo("Hello")
- assertThat(response.statusCode).isEqualTo(200)
- }
-
- @Test
- fun createClientWithSslMaterial() {
- val sslFactory = SSLFactoryTestHelper.createSSLFactory(false, true)
-
- Http4kJavaHttpClientService(sslFactory)
-
- verify(sslFactory, times(1)).sslContext
- verify(sslFactory, times(1)).sslParameters
- }
-
-}
\ No newline at end of file
diff --git a/client/src/test/java/nl/altindag/client/service/JdkHttpClientServiceShould.java b/client/src/test/java/nl/altindag/client/service/JdkHttpClientServiceShould.java
deleted file mode 100644
index 6cc2683c..00000000
--- a/client/src/test/java/nl/altindag/client/service/JdkHttpClientServiceShould.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package nl.altindag.client.service;
-
-import nl.altindag.client.model.ClientResponse;
-import org.assertj.core.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.util.Collections;
-
-import static nl.altindag.client.ClientType.JDK_HTTP_CLIENT;
-import static nl.altindag.client.TestConstants.GET_METHOD;
-import static nl.altindag.client.TestConstants.HEADER_KEY_CLIENT_TYPE;
-import static nl.altindag.client.TestConstants.HTTP_URL;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-class JdkHttpClientServiceShould {
-
- @InjectMocks
- private JdkHttpClientService victim;
- @Mock
- private HttpClient httpClient;
-
- @Test
- @SuppressWarnings({"unchecked", "rawtypes"})
- void executeRequest() throws Exception {
- HttpResponse httpResponse = mock(HttpResponse.class);
- when(httpClient.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(httpResponse);
- when(httpResponse.statusCode()).thenReturn(200);
- when(httpResponse.body()).thenReturn("Hello");
-
- ArgumentCaptor httpRequestArgumentCaptor = ArgumentCaptor.forClass(HttpRequest.class);
- ArgumentCaptor> bodyHandlerArgumentCaptor = ArgumentCaptor.forClass(HttpResponse.BodyHandler.class);
-
- ClientResponse clientResponse = victim.executeRequest(HTTP_URL);
-
- assertThat(clientResponse.getStatusCode()).isEqualTo(200);
- assertThat(clientResponse.getResponseBody()).isEqualTo("Hello");
-
- verify(httpClient, times(1)).send(httpRequestArgumentCaptor.capture(), bodyHandlerArgumentCaptor.capture());
- assertThat(httpRequestArgumentCaptor.getValue().uri()).hasToString(HTTP_URL);
- assertThat(httpRequestArgumentCaptor.getValue().method()).isEqualTo(GET_METHOD);
- assertThat(httpRequestArgumentCaptor.getValue().headers().map()).containsExactly(Assertions.entry(HEADER_KEY_CLIENT_TYPE, Collections.singletonList(JDK_HTTP_CLIENT.getValue())));
- assertThat(bodyHandlerArgumentCaptor.getValue()).isEqualTo(HttpResponse.BodyHandlers.ofString());
- }
-
-}
diff --git a/client/src/test/java/nl/altindag/client/service/KtorJavaHttpClientServiceShould.kt b/client/src/test/java/nl/altindag/client/service/KtorJavaHttpClientServiceShould.kt
deleted file mode 100644
index 65c4e400..00000000
--- a/client/src/test/java/nl/altindag/client/service/KtorJavaHttpClientServiceShould.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-package nl.altindag.client.service
-
-import com.nhaarman.mockitokotlin2.times
-import com.nhaarman.mockitokotlin2.verify
-import nl.altindag.client.ClientType.KTOR_JAVA_HTTP_CLIENT
-import nl.altindag.client.TestConstants.HTTP_URL
-import nl.altindag.client.TestConstants.HTTPS_URL
-import nl.altindag.client.util.MockServerTestHelper
-import nl.altindag.client.util.SSLFactoryTestHelper
-import org.assertj.core.api.Assertions.assertThat
-import org.assertj.core.api.Assertions.assertThatThrownBy
-import org.junit.jupiter.api.Test
-
-
-class KtorJavaHttpClientServiceShould {
-
- @Test
- fun executeRequest() {
- MockServerTestHelper.mockResponseForClient(KTOR_JAVA_HTTP_CLIENT)
- val client = KtorJavaHttpClientService(null)
-
- val clientResponse = client.executeRequest(HTTP_URL)
-
- assertThat(clientResponse.statusCode).isEqualTo(200)
- assertThat(clientResponse.responseBody).isEqualTo("Hello")
- }
-
- @Test
- fun createClientWithSslMaterial() {
- val sslFactory = SSLFactoryTestHelper.createSSLFactory(true, true)
-
- val client = KtorJavaHttpClientService(sslFactory)
-
- assertThatThrownBy { client.executeRequest(HTTPS_URL) }
-
- verify(sslFactory, times(1)).sslContext
- verify(sslFactory, times(1)).sslParameters
- }
-
-}
diff --git a/client/src/test/java/nl/altindag/client/service/MethanolServiceShould.java b/client/src/test/java/nl/altindag/client/service/MethanolServiceShould.java
deleted file mode 100644
index 11cb8be8..00000000
--- a/client/src/test/java/nl/altindag/client/service/MethanolServiceShould.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package nl.altindag.client.service;
-
-import com.github.mizosoft.methanol.Methanol;
-import com.github.mizosoft.methanol.MutableRequest;
-import nl.altindag.client.model.ClientResponse;
-import org.assertj.core.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.net.http.HttpResponse;
-import java.util.Collections;
-
-import static nl.altindag.client.ClientType.METHANOL;
-import static nl.altindag.client.TestConstants.GET_METHOD;
-import static nl.altindag.client.TestConstants.HEADER_KEY_CLIENT_TYPE;
-import static nl.altindag.client.TestConstants.HTTP_URL;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-class MethanolServiceShould {
-
- @InjectMocks
- private MethanolService victim;
- @Mock
- private Methanol httpClient;
-
- @Test
- @SuppressWarnings({"unchecked", "rawtypes"})
- void executeRequest() throws Exception {
- HttpResponse httpResponse = mock(HttpResponse.class);
- when(httpClient.send(any(MutableRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(httpResponse);
- when(httpResponse.statusCode()).thenReturn(200);
- when(httpResponse.body()).thenReturn("Hello");
-
- ArgumentCaptor httpRequestArgumentCaptor = ArgumentCaptor.forClass(MutableRequest.class);
- ArgumentCaptor> bodyHandlerArgumentCaptor = ArgumentCaptor.forClass(HttpResponse.BodyHandler.class);
-
- ClientResponse clientResponse = victim.executeRequest(HTTP_URL);
-
- assertThat(clientResponse.getStatusCode()).isEqualTo(200);
- assertThat(clientResponse.getResponseBody()).isEqualTo("Hello");
-
- verify(httpClient, times(1)).send(httpRequestArgumentCaptor.capture(), bodyHandlerArgumentCaptor.capture());
- assertThat(httpRequestArgumentCaptor.getValue().uri()).hasToString(HTTP_URL);
- assertThat(httpRequestArgumentCaptor.getValue().method()).isEqualTo(GET_METHOD);
- assertThat(httpRequestArgumentCaptor.getValue().headers().map()).containsExactly(Assertions.entry(HEADER_KEY_CLIENT_TYPE, Collections.singletonList(METHANOL.getValue())));
- assertThat(bodyHandlerArgumentCaptor.getValue()).isEqualTo(HttpResponse.BodyHandlers.ofString());
- }
-
-}
diff --git a/client/src/test/java/nl/altindag/client/util/AssertJCustomConditions.java b/client/src/test/java/nl/altindag/client/util/AssertJCustomConditions.java
index 7bacafc7..dc344bc3 100644
--- a/client/src/test/java/nl/altindag/client/util/AssertJCustomConditions.java
+++ b/client/src/test/java/nl/altindag/client/util/AssertJCustomConditions.java
@@ -3,6 +3,8 @@
import static nl.altindag.client.TestConstants.HTTPS_URL;
import static nl.altindag.client.TestConstants.HTTP_URL;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -13,7 +15,7 @@
public final class AssertJCustomConditions {
- private static final Set URLS = Set.of(HTTP_URL, HTTPS_URL);
+ private static final Set URLS = new HashSet<>(Arrays.asList(HTTP_URL, HTTPS_URL));
public static final Condition HTTP_OR_HTTPS_SERVER_URL = new Condition<>(URLS::contains, "Validates if url is equal to the http or https url of the server");
public static final Condition SUBSTRING_OF_HTTP_OR_HTTPS_SERVER_URL = new Condition<>(url -> URLS.stream().anyMatch(urlItem -> urlItem.contains(url)), "Validates if url contains http or https url of the server");
public static final Condition> GSON_CONVERTER_FACTORY = new Condition<>(factories -> factories.stream().anyMatch(factory -> factory instanceof GsonConverterFactory), "Validates if list contains GsonConverterFactory");
diff --git a/client/src/test/resources/features/Hello.feature b/client/src/test/resources/features/Hello.feature
index 44e36f54..d8ef0648 100644
--- a/client/src/test/resources/features/Hello.feature
+++ b/client/src/test/resources/features/Hello.feature
@@ -25,12 +25,10 @@ Feature: Securing the connection between you and the world
| Http4k Apache4 Async Http Client |
| Http4k Apache5 Http Client |
| Http4k Apache5 Async Http Client |
- | Http4k Java Http Client |
| Http4k Jetty Http Client |
| Http4k OkHttp Client |
| Http4s Blaze Client |
| Http4s Java Net Client |
- | JDK HttpClient |
| Jersey HttpClient |
| Jetty Reactive HttpClient |
| Apache CXF WebClient |
@@ -39,9 +37,7 @@ Feature: Securing the connection between you and the world
| Ktor Android HttpClient |
| Ktor Apache HttpClient |
| Ktor CIO HttpClient |
- | Ktor Java HttpClient |
| Ktor Okhttp HttpClient |
- | Methanol |
| OkHttp |
| Old JDK HttpClient |
| Old Jersey HttpClient |
diff --git a/pom.xml b/pom.xml
index 4e86ca6d..1f5adff9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,7 @@
- 11
+ 1.8
2.13
2.13.6
1.5.30
@@ -293,11 +293,6 @@
ktor-client-android
${version.ktor}
-
- io.ktor
- ktor-client-java
- ${version.ktor}
-
org.http4k
http4k-core
@@ -369,11 +364,6 @@
commons-io
${version.commons-io}
-
- com.github.mizosoft.methanol
- methanol
- ${version.methanol}
-