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 3d02e9c789 serialization RpcException bug pr rebase (#12357)
3d02e9c789 is described below
commit 3d02e9c7892e8ab2becd906777ac8f698a1ebebe
Author: wxbty <[email protected]>
AuthorDate: Sat Jun 3 14:52:52 2023 +0800
serialization RpcException bug pr rebase (#12357)
* rebase seri error
* fix style
* wrapper seriation exception by IOException
* fix ci
* use exception
* Multiple encode/decode conversion exceptions
* use wrapper to handle seri exp
* add licence
* move seriExp path
* revert demo
* use static proxy
* fix ci
* fix ci
* Update
dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DefaultSerializationExceptionWrapper.java
Co-authored-by: Albumen Kevin <[email protected]>
* simplefy throwable type
* judge IOException
---------
Co-authored-by: xuziyang <[email protected]>
Co-authored-by: x-shadow-man <[email protected]>
Co-authored-by: Albumen Kevin <[email protected]>
---
.../apache/dubbo/remoting/exchange/Response.java | 5 +
.../remoting/exchange/codec/ExchangeCodec.java | 1 +
.../remoting/exchange/support/DefaultFuture.java | 5 +-
.../remoting/codec/DeprecatedExchangeCodec.java | 6 +-
.../dubbo/remoting/codec/ExchangeCodecTest.java | 2 +-
.../remoting/transport/netty4/NettyChannel.java | 12 +-
.../apache/dubbo/rpc/protocol/AbstractInvoker.java | 6 +-
.../dubbo/rpc/protocol/dubbo/DubboInvoker.java | 9 +-
.../DefaultSerializationExceptionWrapper.java | 363 +++++++++++++++++++++
.../common/serialize/SerializationException.java | 35 ++
...org.apache.dubbo.common.serialize.Serialization | 1 +
.../fastjson2/FastJson2SerializationTest.java | 34 +-
.../hessian2/Hessian2SerializationTest.java | 16 +-
13 files changed, 461 insertions(+), 34 deletions(-)
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Response.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Response.java
index 923ace1f93..1a4c15eb13 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Response.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Response.java
@@ -28,6 +28,11 @@ public class Response {
*/
public static final byte OK = 20;
+ /**
+ * serialization error
+ */
+ public static final byte SERIALIZATION_ERROR = 25;
+
/**
* client side timeout.
*/
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/codec/ExchangeCodec.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/codec/ExchangeCodec.java
index 1aa2d8ad7e..717f894cc7 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/codec/ExchangeCodec.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/codec/ExchangeCodec.java
@@ -360,6 +360,7 @@ public class ExchangeCodec extends TelnetCodec {
logger.warn(TRANSPORT_EXCEED_PAYLOAD_LIMIT, "", "",
t.getMessage(), t);
try {
r.setErrorMessage(t.getMessage());
+ r.setStatus(Response.SERIALIZATION_ERROR);
channel.send(r);
return;
} catch (RemotingException e) {
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
index c35739a88e..3e38371d1e 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
@@ -26,6 +26,7 @@ import org.apache.dubbo.common.timer.TimerTask;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.RemotingException;
+import org.apache.dubbo.common.serialize.SerializationException;
import org.apache.dubbo.remoting.TimeoutException;
import org.apache.dubbo.remoting.exchange.Request;
import org.apache.dubbo.remoting.exchange.Response;
@@ -215,7 +216,9 @@ public class DefaultFuture extends
CompletableFuture<Object> {
this.complete(res.getResult());
} else if (res.getStatus() == Response.CLIENT_TIMEOUT ||
res.getStatus() == Response.SERVER_TIMEOUT) {
this.completeExceptionally(new TimeoutException(res.getStatus() ==
Response.SERVER_TIMEOUT, channel, res.getErrorMessage()));
- } else {
+ } else if(res.getStatus() == Response.SERIALIZATION_ERROR){
+ this.completeExceptionally(new
SerializationException(res.getErrorMessage()));
+ }else {
this.completeExceptionally(new RemotingException(channel,
res.getErrorMessage()));
}
}
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/DeprecatedExchangeCodec.java
b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/DeprecatedExchangeCodec.java
index 9a8910708b..c747ea6eff 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/DeprecatedExchangeCodec.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/DeprecatedExchangeCodec.java
@@ -282,7 +282,11 @@ final class DeprecatedExchangeCodec extends
DeprecatedTelnetCodec implements Cod
logger.warn(TRANSPORT_FAILED_RESPONSE, "", "", "Fail to
encode response: " + res + ", send bad_response info instead, cause: " +
t.getMessage(), t);
Response r = new Response(res.getId(), res.getVersion());
- r.setStatus(Response.BAD_RESPONSE);
+ if (t instanceof IOException) {
+ r.setStatus(Response.SERIALIZATION_ERROR);
+ } else {
+ r.setStatus(Response.BAD_RESPONSE);
+ }
r.setErrorMessage("Failed to send response: " + res + ",
cause: " + StringUtils.toString(t));
channel.send(r);
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java
b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java
index 09e1f6a341..ee5ea1134e 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java
@@ -512,7 +512,7 @@ class ExchangeCodecTest extends TelnetCodecTest {
codec.encode(channel, encodeBuffer, response);
Assertions.assertTrue(channel.getReceivedMessage() instanceof
Response);
Response receiveMessage = (Response) channel.getReceivedMessage();
- Assertions.assertEquals(Response.BAD_RESPONSE,
receiveMessage.getStatus());
+ Assertions.assertEquals(Response.SERIALIZATION_ERROR,
receiveMessage.getStatus());
Assertions.assertTrue(receiveMessage.getErrorMessage().contains("Data
length too large: "));
}
}
diff --git
a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java
b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java
index b87c166a86..2ca031cdf4 100644
---
a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java
+++
b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyChannel.java
@@ -17,7 +17,10 @@
package org.apache.dubbo.remoting.transport.netty4;
import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
+import io.netty.handler.codec.EncoderException;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
@@ -33,9 +36,6 @@ import org.apache.dubbo.remoting.exchange.Response;
import org.apache.dubbo.remoting.transport.AbstractChannel;
import org.apache.dubbo.remoting.transport.codec.CodecAdapter;
import org.apache.dubbo.remoting.utils.PayloadDropper;
-
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
import org.apache.dubbo.rpc.model.FrameworkModel;
import java.net.InetSocketAddress;
@@ -344,7 +344,11 @@ final class NettyChannel extends AbstractChannel {
*/
private static Response buildErrorResponse(Request request, Throwable t) {
Response response = new Response(request.getId(),
request.getVersion());
- response.setStatus(Response.BAD_REQUEST);
+ if(t instanceof EncoderException){
+ response.setStatus(Response.SERIALIZATION_ERROR);
+ }else{
+ response.setStatus(Response.BAD_REQUEST);
+ }
response.setErrorMessage(StringUtils.toString(t));
return response;
}
diff --git
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
index 342f29e9ed..b875f4eb62 100644
---
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
+++
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractInvoker.java
@@ -28,6 +28,7 @@ import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.remoting.RemotingException;
+import org.apache.dubbo.common.serialize.SerializationException;
import org.apache.dubbo.remoting.TimeoutException;
import org.apache.dubbo.remoting.utils.UrlUtils;
import org.apache.dubbo.rpc.AsyncRpcResult;
@@ -112,7 +113,7 @@ public abstract class AbstractInvoker<T> implements
Invoker<T> {
}
this.type = type;
this.url = url;
-
+
this.attachment = attachment == null
? null
: Collections.unmodifiableMap(attachment);
@@ -293,6 +294,9 @@ public abstract class AbstractInvoker<T> implements
Invoker<T> {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "Invoke
remote method timeout. method: " + invocation.getMethodName() + ", provider: "
+ getUrl() + ", cause: " + e.getMessage(), e);
} else if (rootCause instanceof RemotingException) {
throw new RpcException(RpcException.NETWORK_EXCEPTION, "Failed
to invoke remote method: " + invocation.getMethodName() + ", provider: " +
getUrl() + ", cause: " + e.getMessage(), e);
+ } else if (rootCause instanceof SerializationException) {
+ throw new RpcException(RpcException.SERIALIZATION_EXCEPTION,
"Invoke remote method failed cause by serialization error. remote method: " +
+ invocation.getMethodName() + ", provider: " + getUrl() +
", cause: " + e.getMessage(), e);
} else {
throw new RpcException(RpcException.UNKNOWN_EXCEPTION, "Fail
to invoke remote method: " + invocation.getMethodName() + ", provider: " +
getUrl() + ", cause: " + e.getMessage(), e);
}
diff --git
a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
index 239f88d32d..613ee79d58 100644
---
a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
+++
b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
@@ -22,6 +22,7 @@ import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.utils.AtomicPositiveInteger;
import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.remoting.RemotingException;
+import org.apache.dubbo.common.serialize.SerializationException;
import org.apache.dubbo.remoting.TimeoutException;
import org.apache.dubbo.remoting.exchange.ExchangeClient;
import org.apache.dubbo.remoting.exchange.Request;
@@ -37,6 +38,7 @@ import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.protocol.AbstractInvoker;
import org.apache.dubbo.rpc.support.RpcUtils;
+import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@@ -135,7 +137,12 @@ public class DubboInvoker<T> extends AbstractInvoker<T> {
} catch (TimeoutException e) {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "Invoke
remote method timeout. method: " + invocation.getMethodName() + ", provider: "
+ getUrl() + ", cause: " + e.getMessage(), e);
} catch (RemotingException e) {
- throw new RpcException(RpcException.NETWORK_EXCEPTION, "Failed to
invoke remote method: " + invocation.getMethodName() + ", provider: " +
getUrl() + ", cause: " + e.getMessage(), e);
+ String remoteExpMsg = "Failed to invoke remote method: " +
invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " +
e.getMessage();
+ if (e.getCause() instanceof IOException && e.getCause().getCause()
instanceof SerializationException) {
+ throw new RpcException(RpcException.SERIALIZATION_EXCEPTION,
remoteExpMsg, e);
+ } else {
+ throw new RpcException(RpcException.NETWORK_EXCEPTION,
remoteExpMsg, e);
+ }
}
}
diff --git
a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DefaultSerializationExceptionWrapper.java
b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DefaultSerializationExceptionWrapper.java
new file mode 100644
index 0000000000..6d7f4fabe8
--- /dev/null
+++
b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DefaultSerializationExceptionWrapper.java
@@ -0,0 +1,363 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.common.serialize;
+
+import org.apache.dubbo.common.URL;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+public class DefaultSerializationExceptionWrapper implements Serialization {
+
+ private final Serialization serialization;
+
+ public DefaultSerializationExceptionWrapper(Serialization serialization) {
+ if (serialization == null) {
+ throw new IllegalArgumentException("serialization == null");
+ }
+ this.serialization = serialization;
+ }
+
+ @Override
+ public byte getContentTypeId() {
+ return serialization.getContentTypeId();
+ }
+
+ @Override
+ public String getContentType() {
+ return serialization.getContentType();
+ }
+
+ @Override
+ public ObjectOutput serialize(URL url, OutputStream output) throws
IOException {
+ ObjectOutput objectOutput = serialization.serialize(url, output);
+ return new ProxyObjectOutput(objectOutput);
+ }
+
+ @Override
+ public ObjectInput deserialize(URL url, InputStream input) throws
IOException {
+ ObjectInput objectInput = serialization.deserialize(url, input);
+ return new ProxyObjectInput(objectInput);
+ }
+
+ static class ProxyObjectInput implements ObjectInput {
+
+ private final ObjectInput target;
+
+ public ProxyObjectInput(ObjectInput target) {
+ this.target = target;
+ }
+
+ @Override
+ public boolean readBool() throws IOException {
+ try {
+ return target.readBool();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public byte readByte() throws IOException {
+ try {
+ return target.readByte();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+
+ }
+ }
+
+ @Override
+ public short readShort() throws IOException {
+ try {
+ return target.readShort();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+
+ }
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ try {
+ return target.readInt();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+
+ }
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ try {
+ return target.readLong();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+
+ }
+ }
+
+ @Override
+ public float readFloat() throws IOException {
+ try {
+ return target.readFloat();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public double readDouble() throws IOException {
+ try {
+ return target.readDouble();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public String readUTF() throws IOException {
+ try {
+ return target.readUTF();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public byte[] readBytes() throws IOException {
+ try {
+ return target.readBytes();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public Object readObject() throws IOException, ClassNotFoundException {
+ try {
+ return target.readObject();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public <T> T readObject(Class<T> cls) throws IOException,
ClassNotFoundException {
+ try {
+ return target.readObject(cls);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public <T> T readObject(Class<T> cls, Type type) throws IOException,
ClassNotFoundException {
+ try {
+ return target.readObject(cls, type);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public Throwable readThrowable() throws IOException {
+ try {
+ return target.readThrowable();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public String readEvent() throws IOException {
+ try {
+ return target.readEvent();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public Map<String, Object> readAttachments() throws IOException,
ClassNotFoundException {
+ try {
+ return target.readAttachments();
+ } catch (Exception e) {
+ if (e instanceof ClassNotFoundException) {
+ throw e;
+ }
+ throw handleToIOException(e);
+ }
+ }
+ }
+
+ static class ProxyObjectOutput implements ObjectOutput {
+
+ private final ObjectOutput target;
+
+ public ProxyObjectOutput(ObjectOutput target) {
+ this.target = target;
+ }
+
+ @Override
+ public void writeBool(boolean v) throws IOException {
+ try {
+ target.writeBool(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeByte(byte v) throws IOException {
+ try {
+ target.writeByte(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeShort(short v) throws IOException {
+ try {
+ target.writeShort(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeInt(int v) throws IOException {
+ try {
+ target.writeInt(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeLong(long v) throws IOException {
+ try {
+ target.writeLong(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeFloat(float v) throws IOException {
+ try {
+ target.writeFloat(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeDouble(double v) throws IOException {
+ try {
+ target.writeDouble(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeUTF(String v) throws IOException {
+ try {
+ target.writeUTF(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeBytes(byte[] v) throws IOException {
+ try {
+ target.writeBytes(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeBytes(byte[] v, int off, int len) throws IOException {
+ try {
+ target.writeBytes(v);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void flushBuffer() throws IOException {
+ try {
+ target.flushBuffer();
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeObject(Object obj) throws IOException {
+ try {
+ target.writeObject(obj);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeThrowable(Throwable obj) throws IOException {
+ try {
+ target.writeThrowable(obj);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeEvent(String data) throws IOException {
+ try {
+ target.writeEvent(data);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+
+ @Override
+ public void writeAttachments(Map<String, Object> attachments) throws
IOException {
+ try {
+ target.writeAttachments(attachments);
+ } catch (Exception e) {
+ throw handleToIOException(e);
+ }
+ }
+ }
+
+ private static IOException handleToIOException(Exception e) {
+ if (!(e instanceof IOException)) {
+ return new IOException(new SerializationException(e));
+ }
+ return (IOException) e;
+ }
+
+}
diff --git
a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/SerializationException.java
b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/SerializationException.java
new file mode 100644
index 0000000000..ed0c445562
--- /dev/null
+++
b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/SerializationException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.common.serialize;
+
+/**
+ * Serialized runtime exceptions, internal flow,
+ * will be converted into general exceptions and added to serialization tags
when returning to rpc
+ */
+public class SerializationException extends Exception {
+
+ private static final long serialVersionUID = -3160452149606778709L;
+
+ public SerializationException(String msg) {
+ super(msg);
+ }
+
+ public SerializationException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git
a/dubbo-serialization/dubbo-serialization-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization
b/dubbo-serialization/dubbo-serialization-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization
new file mode 100644
index 0000000000..69cf80ab99
--- /dev/null
+++
b/dubbo-serialization/dubbo-serialization-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization
@@ -0,0 +1 @@
+wrapper=org.apache.dubbo.common.serialize.DefaultSerializationExceptionWrapper
diff --git
a/dubbo-serialization/dubbo-serialization-fastjson2/src/test/java/org/apache/dubbo/common/serialize/fastjson2/FastJson2SerializationTest.java
b/dubbo-serialization/dubbo-serialization-fastjson2/src/test/java/org/apache/dubbo/common/serialize/fastjson2/FastJson2SerializationTest.java
index 447e3396aa..4a9dc6eb0a 100644
---
a/dubbo-serialization/dubbo-serialization-fastjson2/src/test/java/org/apache/dubbo/common/serialize/fastjson2/FastJson2SerializationTest.java
+++
b/dubbo-serialization/dubbo-serialization-fastjson2/src/test/java/org/apache/dubbo/common/serialize/fastjson2/FastJson2SerializationTest.java
@@ -82,7 +82,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readUTF);
+ Assertions.assertThrows(IOException.class, objectInput::readUTF);
}
// write pojo, read failed
@@ -108,7 +108,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readUTF);
+ Assertions.assertThrows(IOException.class, objectInput::readUTF);
}
// write list, read failed
@@ -156,7 +156,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readEvent);
+ Assertions.assertThrows(IOException.class, objectInput::readEvent);
}
// write pojo, read failed
@@ -182,7 +182,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readEvent);
+ Assertions.assertThrows(IOException.class, objectInput::readEvent);
}
// write list, read failed
@@ -230,7 +230,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readByte);
+ Assertions.assertThrows(IOException.class, objectInput::readByte);
}
// write pojo, read failed
@@ -243,7 +243,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readByte);
+ Assertions.assertThrows(IOException.class, objectInput::readByte);
}
// write map, read failed
@@ -256,7 +256,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readByte);
+ Assertions.assertThrows(IOException.class, objectInput::readByte);
}
// write list, read failed
@@ -269,7 +269,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readByte);
+ Assertions.assertThrows(IOException.class, objectInput::readByte);
}
frameworkModel.destroy();
@@ -381,7 +381,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(List.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(List.class));
}
// write pojo, read list failed
@@ -395,7 +395,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(LinkedList.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(LinkedList.class));
}
// write pojo, read string failed
@@ -423,7 +423,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(TrustedNotSerializable.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(TrustedNotSerializable.class));
}
// write pojo, read same field failed
@@ -437,7 +437,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(TrustedPojo2.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(TrustedPojo2.class));
}
// write pojo, read map failed
@@ -451,7 +451,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(Map.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(Map.class));
}
// write list, read pojo failed
@@ -468,7 +468,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(TrustedPojo.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(TrustedPojo.class));
}
// write list, read map failed
@@ -485,7 +485,7 @@ public class FastJson2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(Map.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(Map.class));
}
frameworkModel.destroy();
@@ -542,7 +542,7 @@ public class FastJson2SerializationTest {
frameworkModel.getBeanFactory().getBean(SerializeSecurityManager.class).setCheckStatus(SerializeCheckStatus.STRICT);
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readObject);
+ Assertions.assertThrows(IOException.class,
objectInput::readObject);
frameworkModel.destroy();
}
}
@@ -576,7 +576,7 @@ public class FastJson2SerializationTest {
frameworkModel.getBeanFactory().getBean(SerializeSecurityManager.class).setCheckStatus(SerializeCheckStatus.STRICT);
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class,
objectInput::readObject);
+ Assertions.assertThrows(IOException.class,
objectInput::readObject);
frameworkModel.destroy();
}
}
diff --git
a/dubbo-serialization/dubbo-serialization-hessian2/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializationTest.java
b/dubbo-serialization/dubbo-serialization-hessian2/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializationTest.java
index b43e0a8c80..e94f41b350 100644
---
a/dubbo-serialization/dubbo-serialization-hessian2/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializationTest.java
+++
b/dubbo-serialization/dubbo-serialization-hessian2/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2SerializationTest.java
@@ -379,7 +379,7 @@ class Hessian2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(List.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(List.class));
}
// write pojo, read list failed
@@ -393,7 +393,7 @@ class Hessian2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(LinkedList.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(LinkedList.class));
}
// write pojo, read string failed
@@ -407,7 +407,7 @@ class Hessian2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(String.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(String.class));
}
// write pojo, read other failed
@@ -421,7 +421,7 @@ class Hessian2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(TrustedNotSerializable.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(TrustedNotSerializable.class));
}
// write pojo, read same field failed
@@ -466,7 +466,7 @@ class Hessian2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(TrustedPojo.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(TrustedPojo.class));
}
// write list, read map failed
@@ -483,7 +483,7 @@ class Hessian2SerializationTest {
byte[] bytes = outputStream.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInput objectInput = serialization.deserialize(url,
inputStream);
- Assertions.assertThrows(RuntimeException.class, () ->
objectInput.readObject(Map.class));
+ Assertions.assertThrows(IOException.class, () ->
objectInput.readObject(Map.class));
}
frameworkModel.destroy();
@@ -523,7 +523,7 @@ class Hessian2SerializationTest {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutput objectOutput = serialization.serialize(url, outputStream);
- Assertions.assertThrows(IllegalArgumentException.class, () ->
objectOutput.writeObject(trustedPojo));
+ Assertions.assertThrows(IOException.class, () ->
objectOutput.writeObject(trustedPojo));
frameworkModel.destroy();
}
@@ -539,7 +539,7 @@ class Hessian2SerializationTest {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutput objectOutput = serialization.serialize(url, outputStream);
- Assertions.assertThrows(IllegalArgumentException.class, () ->
objectOutput.writeObject(trustedPojo));
+ Assertions.assertThrows(IOException.class, () ->
objectOutput.writeObject(trustedPojo));
frameworkModel.destroy();
}