You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2023/06/22 11:31:36 UTC
[dubbo] branch 3.2 updated: Support get alibaba GenericService from spring context (#12585)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new 27d9ce3836 Support get alibaba GenericService from spring context (#12585)
27d9ce3836 is described below
commit 27d9ce383640359924f98a4ccb66fb6f3f3140d2
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Thu Jun 22 19:31:31 2023 +0800
Support get alibaba GenericService from spring context (#12585)
---
.../com/alibaba/dubbo/rpc/service/EchoService.java | 0
.../dubbo/rpc/service/GenericException.java | 34 ++---
.../alibaba/dubbo/rpc/service/GenericService.java | 2 +-
.../apache/dubbo/config/ReferenceConfigBase.java | 2 +-
.../apache/dubbo/rpc/service/GenericException.java | 141 ++-------------------
.../java/com/alibaba/dubbo/rpc/RpcInvocation.java | 1 +
.../java/com/alibaba/dubbo/rpc/RpcException.java | 0
.../java/org/apache/dubbo/rpc/AppResponse.java | 7 +
.../org/apache/dubbo/rpc/filter/GenericFilter.java | 4 +-
9 files changed, 30 insertions(+), 161 deletions(-)
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/service/EchoService.java b/dubbo-common/src/main/java/com/alibaba/dubbo/rpc/service/EchoService.java
similarity index 100%
rename from dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/service/EchoService.java
rename to dubbo-common/src/main/java/com/alibaba/dubbo/rpc/service/EchoService.java
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/service/GenericException.java b/dubbo-common/src/main/java/com/alibaba/dubbo/rpc/service/GenericException.java
similarity index 58%
rename from dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/service/GenericException.java
rename to dubbo-common/src/main/java/com/alibaba/dubbo/rpc/service/GenericException.java
index 1a94cebf4f..0d5ac6fed2 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/service/GenericException.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/rpc/service/GenericException.java
@@ -17,46 +17,28 @@
package com.alibaba.dubbo.rpc.service;
-import org.apache.dubbo.common.utils.StringUtils;
@Deprecated
-public class GenericException extends RuntimeException {
+public class GenericException extends org.apache.dubbo.rpc.service.GenericException {
private static final long serialVersionUID = -1182299763306599962L;
- private String exceptionClass;
-
- private String exceptionMessage;
-
public GenericException() {
}
- public GenericException(String exceptionClass, String exceptionMessage) {
+ public GenericException(String exceptionMessage) {
super(exceptionMessage);
- this.exceptionClass = exceptionClass;
- this.exceptionMessage = exceptionMessage;
- }
-
- public GenericException(Throwable cause) {
- super(StringUtils.toString(cause));
- this.exceptionClass = cause.getClass().getName();
- this.exceptionMessage = cause.getMessage();
}
- public String getExceptionClass() {
- return exceptionClass;
- }
-
- public void setExceptionClass(String exceptionClass) {
- this.exceptionClass = exceptionClass;
+ public GenericException(String exceptionClass, String exceptionMessage) {
+ super(exceptionClass, exceptionMessage);
}
- public String getExceptionMessage() {
- return exceptionMessage;
+ public GenericException(Throwable cause) {
+ super(cause);
}
- public void setExceptionMessage(String exceptionMessage) {
- this.exceptionMessage = exceptionMessage;
+ public GenericException(String message, Throwable cause, String exceptionClass, String exceptionMessage) {
+ super(message, cause, exceptionClass, exceptionMessage);
}
-
}
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/service/GenericService.java b/dubbo-common/src/main/java/com/alibaba/dubbo/rpc/service/GenericService.java
similarity index 93%
rename from dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/service/GenericService.java
rename to dubbo-common/src/main/java/com/alibaba/dubbo/rpc/service/GenericService.java
index b63b60bd3e..cc3282a7a0 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/service/GenericService.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/rpc/service/GenericService.java
@@ -22,5 +22,5 @@ public interface GenericService extends org.apache.dubbo.rpc.service.GenericServ
@Override
Object $invoke(String method, String[] parameterTypes, Object[] args)
- throws com.alibaba.dubbo.rpc.service.GenericException;
+ throws GenericException;
}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
index 4b41ea2786..e2115e5cde 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
@@ -227,7 +227,7 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {
public static Class<?> determineInterfaceClass(String generic, String interfaceName, ClassLoader classLoader) {
if (ProtocolUtils.isGeneric(generic)) {
- return GenericService.class;
+ return com.alibaba.dubbo.rpc.service.GenericService.class;
}
try {
if (StringUtils.isNotEmpty(interfaceName)) {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/service/GenericException.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/service/GenericException.java
index 23f8add206..39860701f6 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/service/GenericException.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/service/GenericException.java
@@ -16,12 +16,8 @@
*/
package org.apache.dubbo.rpc.service;
-import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.StringUtils;
-import java.beans.Transient;
-import java.io.Serializable;
-
/**
* GenericException
*
@@ -31,169 +27,50 @@ public class GenericException extends RuntimeException {
private static final long serialVersionUID = -1182299763306599962L;
- private boolean useCause;
-
private String exceptionClass;
private String exceptionMessage;
- private final GenericExceptionInfo genericExceptionInfo;
-
public GenericException() {
- this(null, null);
+ }
+
+ public GenericException(String exceptionMessage) {
+ super(exceptionMessage);
+ this.exceptionMessage = exceptionMessage;
}
public GenericException(String exceptionClass, String exceptionMessage) {
super(exceptionMessage);
- this.useCause = false;
this.exceptionClass = exceptionClass;
this.exceptionMessage = exceptionMessage;
- this.genericExceptionInfo = new GenericExceptionInfo(exceptionClass, exceptionMessage, exceptionMessage, getStackTrace());
}
public GenericException(Throwable cause) {
super(StringUtils.toString(cause));
- this.useCause = false;
this.exceptionClass = cause.getClass().getName();
this.exceptionMessage = cause.getMessage();
- this.genericExceptionInfo = new GenericExceptionInfo(this.exceptionClass, this.exceptionMessage, super.getMessage(), getStackTrace());
}
- protected GenericException(GenericExceptionInfo info) {
- super(info.getMsg(), null, true, false);
- setStackTrace(info.getStackTrace());
- this.useCause = false;
- this.exceptionClass = info.getExClass();
- this.exceptionMessage = info.getExMsg();
- this.genericExceptionInfo = info;
+ public GenericException(String message, Throwable cause, String exceptionClass, String exceptionMessage) {
+ super(message, cause);
+ this.exceptionClass = exceptionClass;
+ this.exceptionMessage = exceptionMessage;
}
- @Transient
public String getExceptionClass() {
- if(this.useCause) {
- return ((GenericException)getCause()).getExceptionClass();
- }
return exceptionClass;
}
-
public void setExceptionClass(String exceptionClass) {
- if(this.useCause) {
- ((GenericException)getCause()).setExceptionClass(exceptionClass);
- return;
- }
this.exceptionClass = exceptionClass;
}
- @Transient
public String getExceptionMessage() {
- if(this.useCause) {
- return ((GenericException)getCause()).getExceptionMessage();
- }
return exceptionMessage;
}
public void setExceptionMessage(String exceptionMessage) {
- if(this.useCause) {
- ((GenericException)getCause()).setExceptionMessage(exceptionMessage);
- return;
- }
this.exceptionMessage = exceptionMessage;
}
- @Override
- @Transient
- public StackTraceElement[] getStackTrace() {
- if(this.useCause) {
- return ((GenericException)getCause()).getStackTrace();
- }
- return super.getStackTrace();
- }
-
- @Override
- @Transient
- public String getMessage() {
- if(this.useCause) {
- return getCause().getMessage();
- }
- return JsonUtils.toJson(GenericExceptionInfo.createNoStackTrace(genericExceptionInfo));
- }
-
- public String getGenericException() {
- if(this.useCause) {
- return ((GenericException)getCause()).getGenericException();
- }
- return JsonUtils.toJson(genericExceptionInfo);
- }
-
- public void setGenericException(String json) {
- GenericExceptionInfo info = JsonUtils.toJavaObject(json, GenericExceptionInfo.class);
- if(info == null) {
- return;
- }
- this.useCause = true;
- initCause(new GenericException(info));
- }
-
- @Override
- @Transient
- public String getLocalizedMessage() {
- return getMessage();
- }
-
- /**
- * create generic exception info
- */
- public static class GenericExceptionInfo implements Serializable {
- private String exClass;
- private String exMsg;
- private String msg;
- private StackTraceElement[] stackTrace;
-
- public GenericExceptionInfo() {
- }
-
- public GenericExceptionInfo(String exceptionClass, String exceptionMessage, String message, StackTraceElement[] stackTrace) {
- this.exClass = exceptionClass;
- this.exMsg = exceptionMessage;
- this.msg = message;
- this.stackTrace = stackTrace;
- }
-
- public static GenericExceptionInfo createNoStackTrace(GenericExceptionInfo info) {
- return new GenericExceptionInfo(info.getExClass(), info.getExMsg(), info.getMsg(), null);
- }
-
- public String getMsg() {
- return msg;
- }
-
- public String getExClass() {
- return exClass;
- }
-
- public String getExMsg() {
- return exMsg;
- }
-
- public void setExClass(String exClass) {
- this.exClass = exClass;
- }
-
- public void setExMsg(String exMsg) {
- this.exMsg = exMsg;
- }
-
- public void setMsg(String msg) {
- this.msg = msg;
- }
-
- public StackTraceElement[] getStackTrace() {
- return stackTrace;
- }
-
- public void setStackTrace(StackTraceElement[] stackTrace) {
- this.stackTrace = stackTrace;
- }
- }
}
diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java
index d1cf40600d..7206210ceb 100644
--- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java
+++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+@Deprecated
public class RpcInvocation implements Invocation, Serializable {
private static final long serialVersionUID = -4355285085441097045L;
diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/RpcException.java
similarity index 100%
rename from dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java
rename to dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/RpcException.java
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
index 700d49b2f7..8a2089ed20 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AppResponse.java
@@ -85,6 +85,13 @@ public class AppResponse implements Result {
} catch (Exception e) {
// ignore
}
+ if ((exception instanceof RpcException) && !(exception instanceof com.alibaba.dubbo.rpc.RpcException)) {
+ com.alibaba.dubbo.rpc.RpcException recreated =
+ new com.alibaba.dubbo.rpc.RpcException(((RpcException) exception).getCode(),
+ exception.getMessage(), exception.getCause());
+ recreated.setStackTrace(exception.getStackTrace());
+ throw recreated;
+ }
throw exception;
}
return result;
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java
index 00f23815cd..8375298508 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java
@@ -235,7 +235,9 @@ public class GenericFilter implements Filter, Filter.Listener, ScopeModelAware {
Throwable appException = appResponse.getException();
if (appException instanceof GenericException) {
GenericException tmp = (GenericException) appException;
- appException = new com.alibaba.dubbo.rpc.service.GenericException(tmp.getExceptionClass(), tmp.getExceptionMessage());
+ appException = new com.alibaba.dubbo.rpc.service.GenericException(tmp.getMessage(), tmp.getCause(),
+ tmp.getExceptionClass(), tmp.getExceptionMessage());
+ appException.setStackTrace(tmp.getStackTrace());
}
if (!(appException instanceof com.alibaba.dubbo.rpc.service.GenericException)) {
appException = new com.alibaba.dubbo.rpc.service.GenericException(appException);