Skip to content

Commit

Permalink
fix(fusion): Make fusion handler optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
yizzuide committed May 9, 2020
1 parent 9c6a818 commit 2605c99
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Milkomeda/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<properties>
<java.version>1.8</java.version>
<project.release.version>3.4.0-SNAPSHOT</project.release.version>
<project.release.version>3.3.2-SNAPSHOT</project.release.version>
<spring-boot.version>2.2.4</spring-boot.version>
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<mybatis.starter.version>2.1.1</mybatis.starter.version>
Expand Down Expand Up @@ -66,7 +66,7 @@
<profile>
<id>sonatype-oss-release</id>
<properties>
<project.release.version>3.4.0</project.release.version>
<project.release.version>3.3.2</project.release.version>
</properties>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* @author yizzuide
* @since 3.3.0
* @version 3.3.2
* Create at 2020/05/05 16:23
*/
@Slf4j
Expand All @@ -34,19 +35,22 @@ public void onApplicationEvent() {
return fusionAction.value();
}, false);

fusionAspect.setConverter((tag, returnObj, error) -> {
List<HandlerMetaData> handlerMetaDataList = actionMap.get(tag);
if (CollectionUtils.isEmpty(handlerMetaDataList)) {
if (fusionAspect.getConverter() == null) {
fusionAspect.setConverter((tag, returnObj, error) -> {
List<HandlerMetaData> handlerMetaDataList = actionMap.get(tag);
if (CollectionUtils.isEmpty(handlerMetaDataList)) {
return returnObj;
}
HandlerMetaData handlerMetaData = handlerMetaDataList.get(0);
FusionMetaData<?> fusionMetaData = FusionMetaData.builder().returnData(returnObj).error(returnObj == null).msg(error).build();
try {
return handlerMetaData.getMethod().invoke(handlerMetaData.getTarget(), fusionMetaData);
} catch (Exception e) {
log.error("Fusion invoke error with msg: {}", e.getMessage(), e);
}
return returnObj;
}
HandlerMetaData handlerMetaData = handlerMetaDataList.get(0);
FusionMetaData<?> fusionMetaData = FusionMetaData.builder().returnData(returnObj).error(returnObj == null).msg(error).build();
try {
return handlerMetaData.getMethod().invoke(handlerMetaData.getTarget(), fusionMetaData);
} catch (Exception e) {
log.error("Fusion invoke error with msg: {}", e.getMessage(), e);
}
return returnObj;
});
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.aop.support.AopUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
Expand All @@ -25,7 +24,7 @@
*
* @author yizzuide
* @since 1.13.4
* @version 3.3.0
* @version 3.3.2
* Create at 2019/10/24 21:17
*/
public class AopContextHolder {
Expand Down Expand Up @@ -98,8 +97,8 @@ public static Map<String, List<HandlerMetaData>> getHandlerMetaData(
if (name.startsWith("'") || name.startsWith("@") || name.startsWith("#") || name.startsWith("T(") || name.startsWith("args[")) {
name = ELContext.getValue(target, new Object[]{}, target.getClass(), method, name, String.class);
}
if (StringUtils.isEmpty(name)) {
throw new IllegalArgumentException("Please specify the [value] of "+ executeAnnotation +" !");
if (name == null) {
throw new IllegalArgumentException("Please specify the [tag] of "+ executeAnnotation +" !");
}
metaData.setName(name);
metaData.setTarget(target);
Expand Down
2 changes: 1 addition & 1 deletion MilkomedaDemo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<milkomeda.version>3.4.0-SNAPSHOT</milkomeda.version>
<milkomeda.version>3.3.2-SNAPSHOT</milkomeda.version>
<mybatis.starter>2.1.1</mybatis.starter>
<redission.version>3.12.5</redission.version>
<zookeeper.version>3.4.14</zookeeper.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ResponseEntity<Void> push() {
}

// 修改返回值
@Fusion("api")
@Fusion
@RequestMapping("product/pull")
public Object pull() {
// 返回成功的数据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@FusionHandler
public class APIResponseDataHandler {

@FusionAction("api")
@FusionAction
public Object apiAction(FusionMetaData<Product> metaData) {
// 返回错误类型响应数据
if (metaData.isError()) {
Expand Down

0 comments on commit 2605c99

Please sign in to comment.