Skip to content

Commit

Permalink
GenericException compatible with 2.6.x or lower version (#5800)
Browse files Browse the repository at this point in the history
fixes #4675
  • Loading branch information
chickenlj authored Feb 28, 2020
1 parent 0313381 commit 0d88487
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,46 @@

package com.alibaba.dubbo.rpc.service;

import org.apache.dubbo.common.utils.StringUtils;

@Deprecated
public class GenericException extends org.apache.dubbo.rpc.service.GenericException {
public class GenericException extends RuntimeException {

private static final long serialVersionUID = -1182299763306599962L;

private String exceptionClass;

private String exceptionMessage;

public GenericException() {
}

public GenericException(String exceptionClass, String exceptionMessage) {
super(exceptionClass, exceptionMessage);
super(exceptionMessage);
this.exceptionClass = exceptionClass;
this.exceptionMessage = exceptionMessage;
}

public GenericException(Throwable cause) {
super(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 String getExceptionMessage() {
return exceptionMessage;
}

public void setExceptionMessage(String exceptionMessage) {
this.exceptionMessage = exceptionMessage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ public void onMessage(Result appResponse, Invoker<?> invoker, Invocation inv) {
generic = (String) RpcContext.getContext().getAttachment(GENERIC_KEY);
}

if (appResponse.hasException() && !(appResponse.getException() instanceof GenericException)) {
appResponse.setException(new GenericException(appResponse.getException()));
if (appResponse.hasException()) {
Throwable appException = appResponse.getException();
if (appException instanceof GenericException) {
GenericException tmp = (GenericException) appException;
appException = new com.alibaba.dubbo.rpc.service.GenericException(tmp.getExceptionClass(), tmp.getExceptionMessage());
}
if (!(appException instanceof com.alibaba.dubbo.rpc.service.GenericException)) {
appException = new com.alibaba.dubbo.rpc.service.GenericException(appException);
}
appResponse.setException(appException);
}
if (ProtocolUtils.isJavaGenericSerialization(generic)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.service.GenericException;
import org.apache.dubbo.rpc.service.GenericService;
import org.apache.dubbo.rpc.support.ProtocolUtils;
import org.apache.dubbo.rpc.support.RpcUtils;
Expand Down Expand Up @@ -169,8 +168,8 @@ public void onMessage(Result appResponse, Invoker<?> invoker, Invocation invocat
} catch (NoSuchMethodException e) {
throw new RpcException(e.getMessage(), e);
}
} else if (appResponse.getException() instanceof GenericException) {
GenericException exception = (GenericException) appResponse.getException();
} else if (appResponse.getException() instanceof com.alibaba.dubbo.rpc.service.GenericException) {
com.alibaba.dubbo.rpc.service.GenericException exception = (com.alibaba.dubbo.rpc.service.GenericException) appResponse.getException();
try {
String className = exception.getExceptionClass();
Class<?> clazz = ReflectUtils.forName(className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.service.GenericException;
import org.apache.dubbo.rpc.service.GenericService;
import org.apache.dubbo.rpc.support.DemoService;
import org.apache.dubbo.rpc.support.Person;

import com.alibaba.dubbo.rpc.service.GenericException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand Down

0 comments on commit 0d88487

Please sign in to comment.