forked from LianjiaTech/retrofit-spring-boot-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
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
3803fe9
commit 55c7d08
Showing
29 changed files
with
560 additions
and
240 deletions.
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
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
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
7 changes: 0 additions & 7 deletions
7
src/main/java/com/github/lianjiatech/retrofit/spring/boot/core/DefaultErrorDecoder.java
This file was deleted.
Oops, something went wrong.
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
22 changes: 0 additions & 22 deletions
22
.../java/com/github/lianjiatech/retrofit/spring/boot/core/NoValidServiceInstanceChooser.java
This file was deleted.
Oops, something went wrong.
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
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
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
55 changes: 55 additions & 0 deletions
55
src/main/java/com/github/lianjiatech/retrofit/spring/boot/degrade/BaseRetrofitDegrade.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,55 @@ | ||
package com.github.lianjiatech.retrofit.spring.boot.degrade; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.springframework.context.EnvironmentAware; | ||
import org.springframework.core.env.Environment; | ||
|
||
import com.github.lianjiatech.retrofit.spring.boot.core.RetrofitClient; | ||
import com.github.lianjiatech.retrofit.spring.boot.util.RetrofitUtils; | ||
|
||
/** | ||
* @author 陈添明 | ||
* @since 2022/5/1 9:54 下午 | ||
*/ | ||
public abstract class BaseRetrofitDegrade implements RetrofitDegrade, ResourceNameParser, EnvironmentAware { | ||
|
||
protected static final String HTTP_OUT = "HTTP_OUT"; | ||
|
||
protected static final Map<Method, String> RESOURCE_NAME_CACHE = new ConcurrentHashMap<>(128); | ||
|
||
protected Environment environment; | ||
|
||
@Override | ||
public String parseResourceName(Method method) { | ||
String resourceName = RESOURCE_NAME_CACHE.get(method); | ||
if (resourceName != null) { | ||
return resourceName; | ||
} | ||
RetrofitClient retrofitClient = method.getDeclaringClass().getAnnotation(RetrofitClient.class); | ||
String baseUrl = RetrofitUtils.convertBaseUrl(retrofitClient, retrofitClient.baseUrl(), environment); | ||
HttpMethodPath httpMethodPath = parseHttpMethodPath(method); | ||
resourceName = formatResourceName(baseUrl, httpMethodPath); | ||
RESOURCE_NAME_CACHE.put(method, resourceName); | ||
return resourceName; | ||
} | ||
|
||
protected String formatResourceName(String baseUrl, HttpMethodPath httpMethodPath) { | ||
return String.format("%s:%s:%s", HTTP_OUT, httpMethodPath.getMethod(), baseUrl + httpMethodPath.getPath()); | ||
} | ||
|
||
protected boolean isDefaultOrStatic(Method method) { | ||
if (method.isDefault()) { | ||
return true; | ||
} | ||
return Modifier.isStatic(method.getModifiers()); | ||
} | ||
|
||
@Override | ||
public void setEnvironment(Environment environment) { | ||
this.environment = environment; | ||
} | ||
} |
35 changes: 0 additions & 35 deletions
35
...n/java/com/github/lianjiatech/retrofit/spring/boot/degrade/DefaultResourceNameParser.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.