-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8593897
commit 4602e6a
Showing
26 changed files
with
2,032 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...t-starter/src/main/java/com/github/lianjiatech/retrofit/plus/boot/RetrofitProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.github.lianjiatech.retrofit.plus.boot; | ||
|
||
|
||
import com.alibaba.fastjson.support.retrofit.Retrofit2ConverterFactory; | ||
import com.github.lianjiatech.retrofit.plus.core.BodyCallAdapterFactory; | ||
import com.github.lianjiatech.retrofit.plus.core.ResponseCallAdapterFactory; | ||
import com.github.lianjiatech.retrofit.plus.config.Config; | ||
import com.github.lianjiatech.retrofit.plus.config.PoolConfig; | ||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* 这个类存在的主要目的是方便 IDE 自动提示开头的配置 | ||
* | ||
* @author 陈添明 | ||
*/ | ||
@Data | ||
@ConfigurationProperties(prefix = Config.PREFIX) | ||
public class RetrofitProperties { | ||
|
||
/** | ||
* 连接池配置 | ||
*/ | ||
private Map<String, PoolConfig> pool; | ||
|
||
/** | ||
* 启用 #{@link BodyCallAdapterFactory} 调用适配器 | ||
*/ | ||
private boolean enableBodyCallAdapter = true; | ||
|
||
/** | ||
* 启用 #{@link ResponseCallAdapterFactory} 调用适配器 | ||
*/ | ||
private boolean enableResponseCallAdapter = true; | ||
|
||
/** | ||
* 启用 #{@link Retrofit2ConverterFactory} 数据转换器 | ||
*/ | ||
private boolean enableFastJsonConverter = true; | ||
|
||
/** | ||
* 启用日志打印 | ||
*/ | ||
private boolean enableLog = true; | ||
|
||
/** | ||
* 禁用Void返回类型 | ||
*/ | ||
private boolean disableVoidReturnType = false; | ||
} |
39 changes: 39 additions & 0 deletions
39
retrofit-plus/src/main/java/com/github/lianjiatech/retrofit/plus/annotation/Intercept.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.lianjiatech.retrofit.plus.annotation; | ||
|
||
import com.github.lianjiatech.retrofit.plus.interceptor.BasePathMatchInterceptor; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* 自动将注解上的参数值赋值到handleInterceptor实例上 | ||
* | ||
* @author 陈添明 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Documented | ||
@InterceptMark | ||
public @interface Intercept { | ||
/** | ||
* 拦截器匹配路径pattern | ||
* | ||
* @return 拦截器匹配路径pattern | ||
*/ | ||
String[] include() default {"/**"}; | ||
|
||
/** | ||
* 拦截器排除匹配,排除指定路径拦截 <br> | ||
* | ||
* @return 排除指定路径拦截pattern | ||
*/ | ||
String[] exclude() default {}; | ||
|
||
/** | ||
* 拦截器处理器 <br> | ||
* 优先从spring容器获取对应的Bean,如果获取不到,则使用反射创建一个!<br> | ||
* 如果以Bean的形式配置,scope必须是prototype <br> | ||
* | ||
* @return 拦截器处理器 | ||
*/ | ||
Class<? extends BasePathMatchInterceptor> handler(); | ||
} |
16 changes: 16 additions & 0 deletions
16
...fit-plus/src/main/java/com/github/lianjiatech/retrofit/plus/annotation/InterceptMark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.github.lianjiatech.retrofit.plus.annotation; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* <p>拦截标记注解<br> | ||
* 标记一个注解是拦截器 | ||
* | ||
* @author 陈添明 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.ANNOTATION_TYPE) | ||
@Documented | ||
public @interface InterceptMark { | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...it-plus/src/main/java/com/github/lianjiatech/retrofit/plus/annotation/RetrofitClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.github.lianjiatech.retrofit.plus.annotation; | ||
|
||
import com.github.lianjiatech.retrofit.plus.interceptor.LogStrategy; | ||
import org.slf4j.event.Level; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author 陈添明 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Documented | ||
public @interface RetrofitClient { | ||
|
||
/** | ||
* 基础url, 支持占位符形式配置。<br> | ||
* 例如:http://${baseUrl.test} | ||
* | ||
* @return RetrofitClient的baseUrl | ||
*/ | ||
String baseUrl(); | ||
|
||
/** | ||
* 使用的连接池名称<br> | ||
* default连接池自动加载,也可以手动配置覆盖默认default连接池属性 | ||
* | ||
* @return 使用的连接池名称 | ||
*/ | ||
String poolName() default "default"; | ||
|
||
/** | ||
* 连接超时,单位为毫秒 | ||
* | ||
* @return 连接超时时间 | ||
*/ | ||
int connectTimeoutMs() default 10_000; | ||
|
||
/** | ||
* 读取超时,单位为毫秒 | ||
* | ||
* @return 读取超时时间 | ||
*/ | ||
int readTimeoutMs() default 10_000; | ||
|
||
/** | ||
* 写入超时,单位为毫秒 | ||
* | ||
* @return 写入超时时间 | ||
*/ | ||
int writeTimeoutMs() default 10_000; | ||
|
||
/** | ||
* 日志打印级别,支持的日志级别参见{@link Level} | ||
* | ||
* @return 日志打印级别 | ||
*/ | ||
Level logLevel() default Level.INFO; | ||
|
||
/** | ||
* 日志打印策略,支持的日志打印策略参见{@link LogStrategy} | ||
* | ||
* @return 日志打印策略 | ||
*/ | ||
LogStrategy logStrategy() default LogStrategy.BASIC; | ||
} |
51 changes: 51 additions & 0 deletions
51
...ofit-plus/src/main/java/com/github/lianjiatech/retrofit/plus/annotation/RetrofitScan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.github.lianjiatech.retrofit.plus.annotation; | ||
|
||
import com.github.lianjiatech.retrofit.plus.core.RetrofitClientRegistrar; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author 陈添明 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Documented | ||
@Import(RetrofitClientRegistrar.class) | ||
public @interface RetrofitScan { | ||
|
||
/** | ||
* <p>扫描包路径</p> | ||
* 与basePackages含义相同 | ||
* | ||
* @return 扫描包路径 | ||
*/ | ||
String[] value() default {}; | ||
|
||
|
||
/** | ||
* <p>扫描包路径</p> | ||
* 与value含义相同 | ||
* | ||
* @return 扫描包路径 | ||
*/ | ||
String[] basePackages() default {}; | ||
|
||
/** | ||
* 扫描的classes | ||
* | ||
* @return 扫描的classes | ||
*/ | ||
Class<?>[] basePackageClasses() default {}; | ||
|
||
/** | ||
* <p> | ||
* 配置一个retrofitHelper的Bean实例名称 | ||
* </p> | ||
* 如果该配置存在,会使用spring容器中对应的retrofitHelper的Bean实例属性来初始化retrofit <br> | ||
* 如果该配置项为空,则使用上下文属性初始化retrofit | ||
* | ||
* @return retrofitHelper的Bean实例名称 | ||
*/ | ||
String retrofitHelperRef() default ""; | ||
} |
42 changes: 42 additions & 0 deletions
42
retrofit-plus/src/main/java/com/github/lianjiatech/retrofit/plus/config/Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.lianjiatech.retrofit.plus.config; | ||
|
||
import com.alibaba.fastjson.support.retrofit.Retrofit2ConverterFactory; | ||
import com.github.lianjiatech.retrofit.plus.core.BodyCallAdapterFactory; | ||
import com.github.lianjiatech.retrofit.plus.core.ResponseCallAdapterFactory; | ||
import lombok.Data; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author 陈添明 | ||
*/ | ||
@Data | ||
public class Config { | ||
|
||
public static final String PREFIX = "retrofit-plus"; | ||
|
||
private Map<String, PoolConfig> pool; | ||
|
||
/** | ||
* 启用 #{@link BodyCallAdapterFactory} 调用适配器 | ||
*/ | ||
private boolean enableBodyCallAdapter = true; | ||
|
||
/** | ||
* 启用 #{@link ResponseCallAdapterFactory} 调用适配器 | ||
*/ | ||
private boolean enableResponseCallAdapter = true; | ||
|
||
/** | ||
* 启用 #{@link Retrofit2ConverterFactory} 数据转换器 | ||
*/ | ||
private boolean enableFastJsonConverter = true; | ||
/** | ||
* 启用日志打印 | ||
*/ | ||
private boolean enableLog = true; | ||
/** | ||
* 禁用java.lang.Void返回类型 | ||
*/ | ||
private boolean disableVoidReturnType = false; | ||
} |
25 changes: 25 additions & 0 deletions
25
retrofit-plus/src/main/java/com/github/lianjiatech/retrofit/plus/config/PoolConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.lianjiatech.retrofit.plus.config; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* 连接池参数配置 | ||
* | ||
* @author 陈添明 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PoolConfig { | ||
/** | ||
* 最大空闲连接 | ||
*/ | ||
private int maxIdleConnections = 5; | ||
|
||
/** | ||
* 保活时间,单位为秒 | ||
*/ | ||
private long keepAliveSecond = 300; | ||
} |
Oops, something went wrong.