Skip to content

Commit

Permalink
use OKHttpClient.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanq committed Jan 31, 2024
1 parent 2437ca0 commit 0879bed
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cn.jiguang.app.config;

import cn.jiguang.sdk.api.*;
import cn.jiguang.sdk.api.AdminApi;
import cn.jiguang.sdk.api.DeviceApi;
import cn.jiguang.sdk.api.PushApi;
import cn.jiguang.sdk.api.ReportApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
12 changes: 12 additions & 0 deletions jiguang-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<okhttp.version>4.12.0</okhttp.version>
<lombok.version>1.18.30</lombok.version>
<feign-core.version>13.1</feign-core.version>
<feign-form.version>3.8.0</feign-form.version>
Expand Down Expand Up @@ -50,11 +51,22 @@
<artifactId>feign-slf4j</artifactId>
<version>${feign-core.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>${feign-core.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>${feign-core.version}</version>
</dependency>
<!-- okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
Expand Down
14 changes: 14 additions & 0 deletions jiguang-sdk/src/main/java/cn/jiguang/sdk/api/AdminApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.okhttp.OkHttpClient;
import feign.slf4j.Slf4jLogger;
import lombok.NonNull;

import java.net.Proxy;

public class AdminApi {

private final AdminClient adminClient;
Expand All @@ -34,6 +37,7 @@ public CertificateUploadResult uploadCertificate(@NonNull String appKey, @NonNul
public static class Builder {

private String host = "https://admin.jpush.cn";
private Proxy proxy;
private String devKey;
private String devSecret;
private Logger.Level loggerLevel = Logger.Level.BASIC;
Expand All @@ -43,6 +47,11 @@ public Builder setHost(@NonNull String host) {
return this;
}

public Builder setProxy(@NonNull Proxy proxy) {
this.proxy = proxy;
return this;
}

public Builder setDevKey(@NonNull String devKey) {
this.devKey = devKey;
return this;
Expand All @@ -59,7 +68,12 @@ public Builder setLoggerLevel(@NonNull Logger.Level loggerLevel) {
}

public AdminApi build() {
okhttp3.OkHttpClient.Builder delegateBuilder = new okhttp3.OkHttpClient().newBuilder();
if (proxy != null) {
delegateBuilder.proxy(proxy);
}
AdminClient adminClient = Feign.builder()
.client(new OkHttpClient(delegateBuilder.build()))
.requestInterceptor(new BasicAuthRequestInterceptor(devKey, devSecret))
.encoder(new ApiEncoder())
.decoder(new ApiDecoder())
Expand Down
14 changes: 14 additions & 0 deletions jiguang-sdk/src/main/java/cn/jiguang/sdk/api/DeviceApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.okhttp.OkHttpClient;
import feign.slf4j.Slf4jLogger;
import lombok.NonNull;

import java.net.Proxy;

public class DeviceApi {

private final DeviceClient deviceClient;
Expand Down Expand Up @@ -75,6 +78,7 @@ public DeviceStatusGetResult getDeviceStatus() {
public static class Builder {

private String host = "https://device.jpush.cn";
private Proxy proxy;
private String appKey;
private String masterSecret;
private Logger.Level loggerLevel = Logger.Level.BASIC;
Expand All @@ -84,6 +88,11 @@ public Builder setHost(@NonNull String host) {
return this;
}

public Builder setProxy(@NonNull Proxy proxy) {
this.proxy = proxy;
return this;
}

public Builder setAppKey(@NonNull String appKey) {
this.appKey = appKey;
return this;
Expand All @@ -100,7 +109,12 @@ public Builder setLoggerLevel(@NonNull Logger.Level loggerLevel) {
}

public DeviceApi build() {
okhttp3.OkHttpClient.Builder delegateBuilder = new okhttp3.OkHttpClient().newBuilder();
if (proxy != null) {
delegateBuilder.proxy(proxy);
}
DeviceClient deviceClient = Feign.builder()
.client(new OkHttpClient(delegateBuilder.build()))
.requestInterceptor(new BasicAuthRequestInterceptor(appKey, masterSecret))
.encoder(new ApiEncoder())
.decoder(new ApiDecoder())
Expand Down
14 changes: 14 additions & 0 deletions jiguang-sdk/src/main/java/cn/jiguang/sdk/api/PushApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.okhttp.OkHttpClient;
import feign.slf4j.Slf4jLogger;
import lombok.NonNull;

import java.net.Proxy;

public class PushApi {

private final PushClient pushClient;
Expand Down Expand Up @@ -100,6 +103,7 @@ public ImageFileUpdateResult updateImageFile(@NonNull String mediaId, @NonNull I
public static class Builder {

private String host = "https://api.jpush.cn";
private Proxy proxy;
private String appKey;
private String masterSecret;
private Logger.Level loggerLevel = Logger.Level.BASIC;
Expand All @@ -109,6 +113,11 @@ public Builder setHost(@NonNull String host) {
return this;
}

public Builder setProxy(@NonNull Proxy proxy) {
this.proxy = proxy;
return this;
}

public Builder setAppKey(@NonNull String appKey) {
this.appKey = appKey;
return this;
Expand All @@ -125,7 +134,12 @@ public Builder setLoggerLevel(@NonNull Logger.Level loggerLevel) {
}

public PushApi build() {
okhttp3.OkHttpClient.Builder delegateBuilder = new okhttp3.OkHttpClient().newBuilder();
if (proxy != null) {
delegateBuilder.proxy(proxy);
}
PushClient pushClient = Feign.builder()
.client(new OkHttpClient(delegateBuilder.build()))
.requestInterceptor(new BasicAuthRequestInterceptor(appKey, masterSecret))
.encoder(new ApiEncoder())
.decoder(new ApiDecoder())
Expand Down
13 changes: 13 additions & 0 deletions jiguang-sdk/src/main/java/cn/jiguang/sdk/api/ReportApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import feign.Feign;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import feign.okhttp.OkHttpClient;
import feign.slf4j.Slf4jLogger;
import lombok.NonNull;

import java.net.Proxy;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -42,6 +44,7 @@ public UserDetailGetResult getUserDetail(@NonNull LocalDate startDate, @NonNull
public static class Builder {

private String host = "https://report.jpush.cn";
private Proxy proxy;
private String appKey;
private String masterSecret;
private Logger.Level loggerLevel = Logger.Level.BASIC;
Expand All @@ -51,6 +54,11 @@ public Builder setHost(@NonNull String host) {
return this;
}

public Builder setProxy(@NonNull Proxy proxy) {
this.proxy = proxy;
return this;
}

public Builder setAppKey(@NonNull String appKey) {
this.appKey = appKey;
return this;
Expand All @@ -67,7 +75,12 @@ public Builder setLoggerLevel(@NonNull Logger.Level loggerLevel) {
}

public ReportApi build() {
okhttp3.OkHttpClient.Builder delegateBuilder = new okhttp3.OkHttpClient().newBuilder();
if (proxy != null) {
delegateBuilder.proxy(proxy);
}
ReportClient reportClient = Feign.builder()
.client(new OkHttpClient(delegateBuilder.build()))
.requestInterceptor(new BasicAuthRequestInterceptor(appKey, masterSecret))
.encoder(new ApiEncoder())
.decoder(new ApiDecoder())
Expand Down

0 comments on commit 0879bed

Please sign in to comment.