Skip to content

Commit

Permalink
Update dependencies (#105)
Browse files Browse the repository at this point in the history
* Bumped Ktor

* Removed unused import statement

* Bumped scala compiler

* Bumped kotlin compiler

* Bumped kotlin coroutines

* Bumped sslcontext kickstart

* Bumped cucumber

* Bumped failsafe and surefire

* Bumped aspectjweaver

* Revert "Bumped cucumber"

This reverts commit aceee84

* Bumped cucumber reporting

* Bumped apache commons lang

* Bumped apache commons langio

* Bumped exec maven plugin

* Added todos

* Bumped jetty-reactive-httpclient

* Bumped jersey

* Bumped apache cxf

* Revert "Bumped apache cxf"

This reverts commit dfe5c14.

* Added todo

* Bumped scala maven plugin

* Bumped google http client

* Bumped unirest

* Bumped retrofit

* Bumped finagle

* Bumped Akka

* Bumped Sttp

* Bumped requests

* Configured finagle to always use http1

* Reverted finagle

* Bumped http4s and cats

* Bumped awaitility jackson-module-scala jacoco-maven-plugin junit-jupiter assertj

* Bumped mockito byte-buddy mockito-kotlin scalatest scalatest-maven-plugin mockito-scala mockserver

* Bumped maven-compiler-plugin maven-shade-plugin

* Set minimal requirement to java 17
  • Loading branch information
Hakky54 authored May 22, 2024
1 parent 80d9a94 commit 15b0d65
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
java: [ '11', '17', '21' ]
java: [ '17', '21' ]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
fail-fast: false
matrix:
os: [ windows-latest ]
java: [ '11', '17', '21' ]
java: [ '17', '21' ]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM adoptopenjdk/maven-openjdk11:latest
FROM adoptopenjdk/maven-openjdk17:latest

RUN apt-get update
run apt-get install git -y
2 changes: 1 addition & 1 deletion EXERCISES.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ These are the following steps:

## Starting the server
**Minimum requirements:**
1. Java 11
1. Java 17
2. Maven 3.5.0
3. Eclipse, Intellij IDEA (or any other text editor like VIM)
4. A terminal
Expand Down
10 changes: 5 additions & 5 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<artifactId>fuel</artifactId>
</dependency>
<dependency>
<groupId>com.softwaremill.sttp.client</groupId>
<groupId>com.softwaremill.sttp.client4</groupId>
<artifactId>core_${version.scala}</artifactId>
</dependency>
<dependency>
Expand Down Expand Up @@ -156,19 +156,19 @@
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-apache</artifactId>
<artifactId>ktor-client-apache-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-okhttp</artifactId>
<artifactId>ktor-client-okhttp-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-android</artifactId>
<artifactId>ktor-client-android-jvm</artifactId>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-java</artifactId>
<artifactId>ktor-client-java-jvm</artifactId>
</dependency>
<dependency>
<groupId>org.http4k</groupId>
Expand Down
5 changes: 2 additions & 3 deletions client/src/main/java/nl/altindag/client/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ public Retrofit retrofit(OkHttpClient okHttpClient) {
@Bean
public Service<Request, Response> finagle(SSLFactory sslFactory) throws URISyntaxException {
var uri = new URI(Constants.getServerUrl());
var client = Http.client();
var client = Http.client().withNoHttp2();
if (uri.getScheme().equals("https")) {
client = client.withNoHttp2()
.withTransport()
client = client.withTransport()
.tls(sslFactory.getSslContext());
}
return client.newService(uri.getHost() + ":" + uri.getPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ import cats.effect.{ExitCode, IO, IOApp, Resource}
import nl.altindag.client.ClientType
import nl.altindag.client.ClientType.HTTP4S_BLAZE_CLIENT
import nl.altindag.ssl.SSLFactory
import org.http4s.blaze.client.BlazeClientBuilder
import org.http4s.client.Client
import org.http4s.client.blaze.BlazeClientBuilder
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.{Component, Service}

import scala.concurrent.ExecutionContext.Implicits.global

@Service
class Http4sBlazeClientService(@Qualifier("blazeClient") client: Resource[IO, Client[IO]]) extends Http4sService(client) {

Expand All @@ -39,7 +37,7 @@ class BlazeClientConfiguration extends IOApp {

@Bean(name = Array("blazeClient"))
def createBlazeClient(sslFactory: SSLFactory): Resource[IO, Client[IO]] = {
BlazeClientBuilder[IO](global)
BlazeClientBuilder[IO]
.withSslContext(sslFactory.getSslContext)
.resource
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package nl.altindag.client.service

import cats.effect.{Blocker, ExitCode, IO, IOApp, Resource}
import cats.effect.{ExitCode, IO, IOApp, Resource}
import nl.altindag.client.ClientType
import nl.altindag.client.ClientType.HTTP4S_JAVA_NET_CLIENT
import nl.altindag.ssl.SSLFactory
Expand All @@ -24,8 +24,6 @@ import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.{Component, Service}

import scala.concurrent.ExecutionContext.Implicits.global

@Service
class Http4sJavaNetClientService(@Qualifier("javaNetClient") client: Resource[IO, Client[IO]]) extends Http4sService(client) {

Expand All @@ -38,7 +36,7 @@ class JavaNetClientConfiguration extends IOApp {

@Bean(name = Array("javaNetClient"))
def createJavaNetClient(sslFactory: SSLFactory): Resource[IO, Client[IO]] = {
JavaNetClientBuilder[IO](Blocker.liftExecutionContext(global))
JavaNetClientBuilder[IO]
.withSslSocketFactory(sslFactory.getSslSocketFactory)
.withHostnameVerifier(sslFactory.getHostnameVerifier)
.resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package nl.altindag.client.service

import cats.effect.unsafe.implicits.global
import cats.effect.{IO, Resource}
import nl.altindag.client.Constants.HEADER_KEY_CLIENT_TYPE
import nl.altindag.client.model.ClientResponse
Expand All @@ -32,7 +33,7 @@ abstract class Http4sService(client: Resource[IO, Client[IO]]) extends RequestSe

val responseBody = client
.use(client => client.expect[String](request))
.unsafeRunSync()
.unsafeRunSync

// the client will throw a runtime exception for any other status code than 2xx
// therefore it won't even reach to this point if it gets a non 2xx status code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package nl.altindag.client.service
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.statement.HttpResponse
import io.ktor.utils.io.readUTF8Line
import io.ktor.client.statement.*
import kotlinx.coroutines.runBlocking
import nl.altindag.client.Constants.HEADER_KEY_CLIENT_TYPE
import nl.altindag.client.model.ClientResponse
Expand All @@ -32,7 +31,7 @@ abstract class KtorHttpClientService(var client: HttpClient): RequestService {
header(HEADER_KEY_CLIENT_TYPE, clientType.value)
}

ClientResponse(httpResponse.content.readUTF8Line(), httpResponse.status.value)
ClientResponse(httpResponse.bodyAsText(), httpResponse.status.value)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
*/
package nl.altindag.client.service

import java.net.URI

import javax.net.ssl.HttpsURLConnection
import nl.altindag.client.ClientType
import nl.altindag.client.ClientType._
import nl.altindag.client.Constants.HEADER_KEY_CLIENT_TYPE
import nl.altindag.client.model.ClientResponse
import nl.altindag.ssl.SSLFactory
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.{Component, Service}
import sttp.client._
import sttp.client4.httpurlconnection.HttpURLConnectionBackend
import sttp.client4.{SyncBackend, basicRequest}
import sttp.model._

import java.net.URI
import javax.net.ssl.HttpsURLConnection

@Service
class SttpHttpClientService(sttpBackend: SttpBackend[Identity, Any]) extends RequestService {
class SttpHttpClientService(sttpBackend: SyncBackend) extends RequestService {

override def executeRequest(url: String): ClientResponse = {
val request = basicRequest.get(uri = Uri(javaUri = URI.create(url)))
Expand All @@ -47,7 +48,7 @@ class SttpHttpClientService(sttpBackend: SttpBackend[Identity, Any]) extends Req
class SttpHttpClientConfiguration {

@Bean
def createSttpBackendClient(sslFactory: SSLFactory): SttpBackend[Identity, Any] = {
def createSttpBackendClient(sslFactory: SSLFactory): SyncBackend = {
HttpURLConnectionBackend(customizeConnection = {
case httpsConnection: HttpsURLConnection =>
httpsConnection.setHostnameVerifier(sslFactory.getHostnameVerifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,30 @@
package nl.altindag.client.service

import java.net.URI

import nl.altindag.client.TestConstants.{HTTPS_URL, HTTP_URL}
import nl.altindag.client.model.ClientResponse
import nl.altindag.client.util.SSLFactoryTestHelper
import org.assertj.core.api.Assertions.{assertThat, assertThatThrownBy}
import org.mockito.ArgumentCaptor
import org.mockito.scalatest.MockitoSugar
import org.scalatest.funspec.AnyFunSpec
import sttp.client.{Identity, Request, RequestT, Response, SttpBackend, basicRequest}
import sttp.client4.{GenericRequest, Identity, Response, SyncBackend, basicRequest}
import sttp.model.{Header, StatusCode, Uri}

class SttpHttpClientServiceShould extends AnyFunSpec with MockitoSugar {

describe("execute request") {
val mockedBackend = mock[SttpBackend[Identity, Any]]
val mockedBackend = mock[SyncBackend]
val mockedResponse = mock[Identity[Response[Either[String, String]]]]
val mockedBody = mock[Either[String, String]]

when(mockedBackend.send(any[RequestT[Identity, Either[String, String], Any]])).thenReturn(mockedResponse)
when(mockedBackend.send(any[GenericRequest[Any, Any]])).thenReturn(mockedResponse)
when(mockedResponse.code).thenReturn(StatusCode.Ok)
when(mockedResponse.body).thenReturn(mockedBody)
when(mockedBody.toOption).thenReturn(Option.apply("Hello"))

val requestArgumentCaptor: ArgumentCaptor[RequestT[Identity, Either[String, String], Any]] = {
ArgumentCaptor.forClass(classOf[RequestT[Identity, Either[String, String], Any]])
val requestArgumentCaptor: ArgumentCaptor[GenericRequest[Any, Any]] = {
ArgumentCaptor.forClass(classOf[GenericRequest[Any, Any]])
}

val victim = new SttpHttpClientService(mockedBackend)
Expand All @@ -54,15 +53,15 @@ class SttpHttpClientServiceShould extends AnyFunSpec with MockitoSugar {
}

describe("create Sttp backend client without ssl") {
val victim: SttpBackend[Identity, Any] = new SttpHttpClientConfiguration().createSttpBackendClient(null)
val victim: SyncBackend = new SttpHttpClientConfiguration().createSttpBackendClient(null)
assertThat(victim).isNotNull
}

describe("create Sttp backend client with ssl") {
val sslFactory = SSLFactoryTestHelper.createSSLFactory(true, true)

val request: Request[Either[String, String], Any] = basicRequest.get(uri = Uri(javaUri = URI.create(HTTPS_URL)))
val victim: SttpBackend[Identity, Any] = new SttpHttpClientConfiguration().createSttpBackendClient(sslFactory)
val request: GenericRequest[Any, Any] = basicRequest.get(uri = Uri(javaUri = URI.create(HTTPS_URL)))
val victim: SyncBackend = new SttpHttpClientConfiguration().createSttpBackendClient(sslFactory)

assertThat(victim).isNotNull
assertThatThrownBy(() => victim.send(request))
Expand All @@ -72,8 +71,8 @@ class SttpHttpClientServiceShould extends AnyFunSpec with MockitoSugar {
}

describe("create Sttp backend client without ssl when sslFactory is absent") {
val request: Request[Either[String, String], Any] = basicRequest.get(uri = Uri(javaUri = URI.create(HTTPS_URL)))
val victim: SttpBackend[Identity, Any] = new SttpHttpClientConfiguration().createSttpBackendClient(null)
val request: GenericRequest[Any, Any] = basicRequest.get(uri = Uri(javaUri = URI.create(HTTPS_URL)))
val victim: SyncBackend = new SttpHttpClientConfiguration().createSttpBackendClient(null)

assertThat(victim).isNotNull
assertThatThrownBy(() => victim.send(request))
Expand All @@ -82,8 +81,8 @@ class SttpHttpClientServiceShould extends AnyFunSpec with MockitoSugar {
describe("create Sttp backend client without ssl when url is http scheme") {
val sslFactory = SSLFactoryTestHelper.createSSLFactory(true, true)

val request: Request[Either[String, String], Any] = basicRequest.get(uri = Uri(javaUri = URI.create(HTTP_URL)))
val victim: SttpBackend[Identity, Any] = new SttpHttpClientConfiguration().createSttpBackendClient(sslFactory)
val request: GenericRequest[Any, Any] = basicRequest.get(uri = Uri(javaUri = URI.create(HTTP_URL)))
val victim: SyncBackend = new SttpHttpClientConfiguration().createSttpBackendClient(sslFactory)

assertThat(victim).isNotNull
assertThatThrownBy(() => victim.send(request))
Expand Down
Loading

0 comments on commit 15b0d65

Please sign in to comment.