Skip to content

Commit

Permalink
Replace apache http client with airlift
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Jan 11, 2024
1 parent 89c5c5e commit 455a957
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
16 changes: 10 additions & 6 deletions gateway-ha/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
<version>${dep.jakarta.mail.version}</version>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>http-client</artifactId>
</dependency>

<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-assets</artifactId>
Expand Down Expand Up @@ -115,6 +120,11 @@
<version>${dep.jakarta.annotations.version}</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand All @@ -127,12 +137,6 @@
<version>2.1.2</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${dep.apache.httpcomponents}</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.apache.http.HttpStatus;
import org.eclipse.jetty.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -151,9 +151,9 @@ private String queryCluster(ProxyBackendConfiguration backend, String path)

try (Response res = call.execute()) {
switch (res.code()) {
case HttpStatus.SC_OK:
case HttpStatus.OK_200:
return res.body().string();
case HttpStatus.SC_UNAUTHORIZED:
case HttpStatus.UNAUTHORIZED_401:
log.info("Unauthorized to fetch cluster stats");
log.debug("username: {}, targetUrl: {}, cookieStore: {}",
backendStateConfiguration.getUsername(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.HttpHeaders;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -105,7 +105,7 @@ protected void debugLogHeaders(Request proxyRequest)

protected boolean isGZipEncoding(HttpServletResponse response)
{
String contentEncoding = response.getHeader(HttpHeaders.CONTENT_ENCODING);
String contentEncoding = response.getHeader(HttpHeader.CONTENT_ENCODING.toString());
return contentEncoding != null && contentEncoding.toLowerCase().contains("gzip");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import jakarta.servlet.DispatcherType;
import jakarta.servlet.Filter;
import org.apache.http.util.TextUtils;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.proxy.ConnectHandler;
import org.eclipse.jetty.server.HttpConfiguration;
Expand All @@ -35,6 +34,8 @@
import java.util.EnumSet;
import java.util.concurrent.TimeUnit;

import static com.google.common.base.Strings.isNullOrEmpty;

public class ProxyServer
implements Closeable
{
Expand Down Expand Up @@ -78,7 +79,7 @@ private void setupContext(ProxyServerConfiguration config)
sslContextFactory.setTrustAll(true);
sslContextFactory.setSslSessionTimeout((int) TimeUnit.SECONDS.toMillis(15));

if (!TextUtils.isBlank(keystorePath)) {
if (!isNullOrEmpty(keystorePath)) {
sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
sslContextFactory.setKeyStorePassword(keystorePass);
sslContextFactory.setKeyManagerPassword(keystorePass);
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>bom</artifactId>
<version>239</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-dependencies</artifactId>
Expand Down

0 comments on commit 455a957

Please sign in to comment.