Skip to content

Commit 1f84cdc

Browse files
committed
Merge remote-tracking branch 'dubbo_rem/master'
2 parents 96292bc + e1a7991 commit 1f84cdc

File tree

8 files changed

+102
-6
lines changed

8 files changed

+102
-6
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.remoting;
18+
19+
import java.net.InetSocketAddress;
20+
21+
/**
22+
* SerializationException. (API, Prototype, ThreadSafe)
23+
*
24+
* @export
25+
* @see org.apache.dubbo.remoting.exchange.support.DefaultFuture#get()
26+
*/
27+
public class SerializationException extends Exception {
28+
29+
private static final long serialVersionUID = -3160452149606778709L;
30+
31+
private InetSocketAddress localAddress;
32+
33+
private InetSocketAddress remoteAddress;
34+
35+
public SerializationException(Channel channel, String msg) {
36+
this(channel == null ? null : channel.getLocalAddress(), channel == null ? null : channel.getRemoteAddress(),
37+
msg);
38+
}
39+
40+
public SerializationException(InetSocketAddress localAddress, InetSocketAddress remoteAddress, String message) {
41+
super(message);
42+
43+
this.localAddress = localAddress;
44+
this.remoteAddress = remoteAddress;
45+
}
46+
47+
public SerializationException(Channel channel, Throwable cause) {
48+
this(channel == null ? null : channel.getLocalAddress(), channel == null ? null : channel.getRemoteAddress(),
49+
cause);
50+
}
51+
52+
public SerializationException(InetSocketAddress localAddress, InetSocketAddress remoteAddress, Throwable cause) {
53+
super(cause);
54+
55+
this.localAddress = localAddress;
56+
this.remoteAddress = remoteAddress;
57+
}
58+
59+
public SerializationException(Channel channel, String message, Throwable cause) {
60+
this(channel == null ? null : channel.getLocalAddress(), channel == null ? null : channel.getRemoteAddress(),
61+
message, cause);
62+
}
63+
64+
public SerializationException(InetSocketAddress localAddress, InetSocketAddress remoteAddress, String message,
65+
Throwable cause) {
66+
super(message, cause);
67+
68+
this.localAddress = localAddress;
69+
this.remoteAddress = remoteAddress;
70+
}
71+
72+
public InetSocketAddress getLocalAddress() {
73+
return localAddress;
74+
}
75+
76+
public InetSocketAddress getRemoteAddress() {
77+
return remoteAddress;
78+
}
79+
}

dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Response.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public class Response {
2828
*/
2929
public static final byte OK = 20;
3030

31+
/**
32+
* serialization error
33+
*/
34+
public static final byte SERIALIZATION_ERROR = 25;
35+
3136
/**
3237
* client side timeout.
3338
*/

dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/codec/ExchangeCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ protected void encodeResponse(Channel channel, ChannelBuffer buffer, Response re
347347
// send error message to Consumer, otherwise, Consumer will wait till timeout.
348348
if (!res.isEvent() && res.getStatus() != Response.BAD_RESPONSE) {
349349
Response r = new Response(res.getId(), res.getVersion());
350-
r.setStatus(Response.BAD_RESPONSE);
350+
r.setStatus(Response.SERIALIZATION_ERROR);
351351

352352
if (t instanceof ExceedPayloadLimitException) {
353353
logger.warn(t.getMessage(), t);

dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.dubbo.common.utils.NamedThreadFactory;
2727
import org.apache.dubbo.remoting.Channel;
2828
import org.apache.dubbo.remoting.RemotingException;
29+
import org.apache.dubbo.remoting.SerializationException;
2930
import org.apache.dubbo.remoting.TimeoutException;
3031
import org.apache.dubbo.remoting.exchange.Request;
3132
import org.apache.dubbo.remoting.exchange.Response;
@@ -203,7 +204,9 @@ private void doReceived(Response res) {
203204
this.complete(res.getResult());
204205
} else if (res.getStatus() == Response.CLIENT_TIMEOUT || res.getStatus() == Response.SERVER_TIMEOUT) {
205206
this.completeExceptionally(new TimeoutException(res.getStatus() == Response.SERVER_TIMEOUT, channel, res.getErrorMessage()));
206-
} else {
207+
} else if(res.getStatus() == Response.SERIALIZATION_ERROR){
208+
this.completeExceptionally(new SerializationException(channel, res.getErrorMessage()));
209+
}else {
207210
this.completeExceptionally(new RemotingException(channel, res.getErrorMessage()));
208211
}
209212

dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/codec/ExchangeCodecTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public void testMessageLengthExceedPayloadLimitWhenEncode() throws Exception {
498498
codec.encode(channel, encodeBuffer, response);
499499
Assertions.assertTrue(channel.getReceivedMessage() instanceof Response);
500500
Response receiveMessage = (Response) channel.getReceivedMessage();
501-
Assertions.assertEquals(Response.BAD_RESPONSE, receiveMessage.getStatus());
501+
Assertions.assertEquals(Response.SERIALIZATION_ERROR, receiveMessage.getStatus());
502502
Assertions.assertTrue(receiveMessage.getErrorMessage().contains("Data length too large: "));
503503
}
504504
}

dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/codec/DeprecatedExchangeCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ protected void encodeResponse(Channel channel, OutputStream os, Response res) th
279279
logger.warn("Fail to encode response: " + res + ", send bad_response info instead, cause: " + t.getMessage(), t);
280280

281281
Response r = new Response(res.getId(), res.getVersion());
282-
r.setStatus(Response.BAD_RESPONSE);
282+
r.setStatus(Response.SERIALIZATION_ERROR);
283283
r.setErrorMessage("Failed to send response: " + res + ", cause: " + StringUtils.toString(t));
284284
channel.send(r);
285285

dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClientHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.dubbo.remoting.transport.netty4;
1818

19+
import io.netty.handler.codec.EncoderException;
1920
import org.apache.dubbo.common.URL;
2021
import org.apache.dubbo.common.Version;
2122
import org.apache.dubbo.common.logger.Logger;
@@ -154,7 +155,11 @@ public void handshakeCompleted(SslHandlerInitializer.HandshakeCompletionEvent ev
154155
*/
155156
private static Response buildErrorResponse(Request request, Throwable t) {
156157
Response response = new Response(request.getId(), request.getVersion());
157-
response.setStatus(Response.BAD_REQUEST);
158+
if(t instanceof EncoderException){
159+
response.setStatus(Response.SERIALIZATION_ERROR);
160+
}else{
161+
response.setStatus(Response.BAD_REQUEST);
162+
}
158163
response.setErrorMessage(StringUtils.toString(t));
159164
return response;
160165
}

dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AsyncToSyncInvoker.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.dubbo.common.URL;
2020
import org.apache.dubbo.remoting.RemotingException;
21+
import org.apache.dubbo.remoting.SerializationException;
2122
import org.apache.dubbo.remoting.TimeoutException;
2223
import org.apache.dubbo.rpc.Invocation;
2324
import org.apache.dubbo.rpc.InvokeMode;
@@ -69,7 +70,10 @@ public Result invoke(Invocation invocation) throws RpcException {
6970
if (t instanceof TimeoutException) {
7071
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "Invoke remote method timeout. method: " +
7172
invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e);
72-
} else if (t instanceof RemotingException) {
73+
} else if(t instanceof SerializationException){
74+
throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, "Failed to invoke remote method: " +
75+
invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e);
76+
}else if (t instanceof RemotingException) {
7377
throw new RpcException(RpcException.NETWORK_EXCEPTION, "Failed to invoke remote method: " +
7478
invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e);
7579
} else {

0 commit comments

Comments
 (0)