Skip to content

Commit 8e6f116

Browse files
committed
Adding support for Okhttp
1 parent 30d3e55 commit 8e6f116

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>org.gitlab4j</groupId>
66
<artifactId>gitlab4j-api-cortex</artifactId>
77
<packaging>jar</packaging>
8-
<version>4.20.3</version>
8+
<version>4.20.4</version>
99
<name>GitLab4J-API - GitLab API Java Client</name>
1010
<description>GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.</description>
1111
<url>https://github.com/gitlab4j/gitlab4j-api</url>
@@ -462,6 +462,21 @@
462462
<version>2.4</version>
463463
<scope>test</scope>
464464
</dependency>
465+
<dependency>
466+
<groupId>org.jboss.resteasy</groupId>
467+
<artifactId>resteasy-client</artifactId>
468+
<version>3.15.3.Final</version>
469+
</dependency>
470+
<dependency>
471+
<groupId>net.ltgt.jaxrs</groupId>
472+
<artifactId>resteasy-client-okhttp3</artifactId>
473+
<version>1.1</version>
474+
</dependency>
475+
<dependency>
476+
<groupId>com.squareup.okhttp3</groupId>
477+
<artifactId>okhttp</artifactId>
478+
<version>4.9.3</version>
479+
</dependency>
465480
</dependencies>
466481

467482
<dependencyManagement>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.gitlab4j.api.http;
2+
3+
import net.ltgt.resteasy.client.okhttp3.OkHttpClientEngine;
4+
import okhttp3.OkHttpClient;
5+
import org.gitlab4j.api.utils.JacksonJson;
6+
import org.glassfish.jersey.client.ClientProperties;
7+
import org.glassfish.jersey.jackson.JacksonFeature;
8+
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
9+
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
10+
import org.jboss.resteasy.spi.ResteasyProviderFactory;
11+
import org.jboss.resteasy.client.jaxrs.internal.ClientConfiguration;
12+
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
13+
14+
public class OkHttpResteasyClientFactory {
15+
public static ResteasyClient getClient(OkHttpClient client) {
16+
ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
17+
instance.registerProvider(JacksonJson.class);
18+
RegisterBuiltin.register(instance);
19+
20+
ClientConfiguration clientConfig = new ClientConfiguration(instance);
21+
clientConfig.property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true);
22+
clientConfig.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true);
23+
24+
return new ResteasyClientBuilder().providerFactory(instance)
25+
.register(JacksonFeature.class)
26+
.httpEngine(new OkHttpClientEngine(client))
27+
.withConfig(clientConfig)
28+
.build();
29+
}
30+
}

0 commit comments

Comments
 (0)