AlbumenJ commented on code in PR #10636:
URL: https://github.com/apache/dubbo/pull/10636#discussion_r973902572


##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleExceptionWrapperUtils.java:
##########
@@ -0,0 +1,131 @@
+package org.apache.dubbo.rpc.protocol.tri;

Review Comment:
   Please add ASF license header for all newly created files



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/stream/TripleClientStream.java:
##########
@@ -283,7 +286,23 @@ private TriRpcStatus statusFromTrailers(Http2Headers 
trailers) {
             final Integer intStatus = 
trailers.getInt(TripleHeaderEnum.STATUS_KEY.getHeader());
             TriRpcStatus status = intStatus == null ? null : 
TriRpcStatus.fromCode(intStatus);
             if (status != null) {
-                final CharSequence message = 
trailers.get(TripleHeaderEnum.MESSAGE_KEY.getHeader());
+                CharSequence message = 
trailers.get(TripleHeaderEnum.MESSAGE_KEY.getHeader());
+                CharSequence messageException = 
trailers.get(TripleHeaderEnum.EXCEPTION_KEY.getHeader());
+                if (messageException != null) {
+                    String decodeMessageException = 
TriRpcStatus.decodeMessage(messageException.toString());
+                    byte[] decodeMessageExceptionByte = 
StreamUtils.decodeASCIIByte(decodeMessageException);
+                    TripleExceptionWrapperUtils tripleExceptionWrapperUtils = 
TripleExceptionWrapperUtils.
+                        init(null, URL.valueOf("TEST"));
+                    Object messageExceptionObj = null;
+                    try {
+                        messageExceptionObj = 
tripleExceptionWrapperUtils.unPackRequest(decodeMessageExceptionByte);
+                    } catch (Exception e) {
+                        e.printStackTrace();

Review Comment:
   use logger



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/stream/TripleServerStream.java:
##########
@@ -21,13 +21,11 @@
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.rpc.HeaderFilter;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.PathResolver;
-import org.apache.dubbo.rpc.TriRpcStatus;
+import org.apache.dubbo.rpc.*;

Review Comment:
   do not use comma import



##########
dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/support/IGreeterException.java:
##########
@@ -0,0 +1,12 @@
+package org.apache.dubbo.rpc.protocol.tri.support;
+
+public class IGreeterException extends Exception {
+        //异常信息

Review Comment:
   comment in eng



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/stream/TripleServerStream.java:
##########
@@ -190,6 +189,19 @@ private Http2Headers getTrailers(TriRpcStatus rpcStatus, 
Map<String, Object> att
                 StreamUtils.encodeBase64ASCII(status.toByteArray()));
             return headers;
         }
+
+        URL url = URL.valueOf("TEST");
+        TripleExceptionWrapperUtils tripleExceptionWrapperUtils = 
TripleExceptionWrapperUtils.init(throwable, url);
+        try {
+            byte[] exceptionBytes = 
tripleExceptionWrapperUtils.packRequest(throwable);
+            String exceptionMessage = 
StreamUtils.encodeBase64ASCII(exceptionBytes);
+            exceptionMessage = TriRpcStatus.encodeMessage(exceptionMessage);
+            headers.set(TripleHeaderEnum.EXCEPTION_KEY.getHeader(),
+                exceptionMessage);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }

Review Comment:
   same



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleExceptionWrapperUtils.java:
##########
@@ -0,0 +1,131 @@
+package org.apache.dubbo.rpc.protocol.tri;
+
+import com.google.protobuf.ByteString;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.common.serialize.MultipleSerialization;
+import org.apache.dubbo.common.serialize.support.DefaultSerializationSelector;
+import org.apache.dubbo.config.Constants;
+import org.apache.dubbo.rpc.model.PackableMethod;
+import org.apache.dubbo.triple.TripleWrapper;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import static org.apache.dubbo.remoting.Constants.SERIALIZATION_KEY;
+
+
+public class TripleExceptionWrapperUtils {
+
+    private final WrapExceptionResponsePack wrapExceptionResponsePack;
+    private final WrapExceptionResponseUnpack wrapExceptionResponseUnPack;
+
+    public WrapExceptionResponsePack getWrapExceptionResponsePack() {
+        return wrapExceptionResponsePack;
+    }
+
+    public WrapExceptionResponseUnpack getWrapExceptionResponseUnPack() {
+        return wrapExceptionResponseUnPack;
+    }
+
+    public byte[] packRequest(Object request) throws IOException {
+        return getWrapExceptionResponsePack().pack(request);
+    }
+
+    public Object unPackRequest(byte[] bytes) throws IOException, 
ClassNotFoundException {
+        return getWrapExceptionResponseUnPack().unpack(bytes);
+    }
+
+    public TripleExceptionWrapperUtils(Object object, URL url, String 
serializeName) {
+        final MultipleSerialization serialization = 
url.getOrDefaultFrameworkModel()
+            .getExtensionLoader(MultipleSerialization.class)
+            .getExtension(url.getParameter(Constants.MULTI_SERIALIZATION_KEY,
+                CommonConstants.DEFAULT_KEY));
+        String returnType = null;
+        if (object != null) {
+            returnType = object.getClass().getName();
+        }
+        this.wrapExceptionResponsePack = new 
WrapExceptionResponsePack(serialization,
+            url, returnType);
+        this.wrapExceptionResponseUnPack = new 
WrapExceptionResponseUnpack(serialization, url);
+    }
+
+    public static TripleExceptionWrapperUtils init(Object object, URL url) {
+        final String serializeName = url.getParameter(SERIALIZATION_KEY,
+            DefaultSerializationSelector.getDefaultRemotingSerialization());
+        TripleExceptionWrapperUtils tripleExceptionWrapperUtils = new 
TripleExceptionWrapperUtils(
+            object, url, serializeName);
+        return tripleExceptionWrapperUtils;
+    }
+
+    private static String convertHessianFromWrapper(String serializeType) {
+        if (TripleConstant.HESSIAN4.equals(serializeType)) {
+            return TripleConstant.HESSIAN2;
+        }
+        return serializeType;
+    }
+
+    private static class WrapExceptionResponsePack implements 
PackableMethod.Pack {
+
+        private final MultipleSerialization multipleSerialization;
+        private final URL url;
+        private final String returnType;
+        String serialize = "hessian4";
+
+        private WrapExceptionResponsePack(MultipleSerialization 
multipleSerialization, URL url,
+                                          String returnType) {
+            this.multipleSerialization = multipleSerialization;
+            this.url = url;
+            this.returnType = returnType;
+        }
+
+        @Override
+        public byte[] pack(Object obj) throws IOException {
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            multipleSerialization.serialize(url, serialize, null, obj, bos);
+            return TripleWrapper.TripleExceptionWrapper.newBuilder()
+                .setSerialization(serialize)
+                .setClassName(obj.getClass().getSimpleName())
+                .setData(ByteString.copyFrom(bos.toByteArray()))
+                .build()
+                .toByteArray();
+        }
+    }
+
+    private static class WrapExceptionResponseUnpack implements 
PackableMethod.UnPack {
+
+        private final MultipleSerialization serialization;
+        private final URL url;
+
+        private WrapExceptionResponseUnpack(MultipleSerialization 
serialization, URL url) {
+            this.serialization = serialization;
+            this.url = url;
+        }
+
+        @Override
+        public Object unpack(byte[] data) throws IOException, 
ClassNotFoundException {
+
+            TripleWrapper.TripleExceptionWrapper wrapper = 
TripleWrapper.TripleExceptionWrapper.parseFrom(
+                data);
+            final String serializeType = 
convertHessianFromWrapper(wrapper.getSerialization());
+            ByteArrayInputStream bais = new 
ByteArrayInputStream(wrapper.getData().toByteArray());
+            return serialization.deserialize(url, serializeType, 
wrapper.getClassName(), bais);
+        }
+    }
+
+//    public static void main(String[] args) throws IOException, 
ClassNotFoundException {
+//        ScoreException exception = new ScoreException();
+//        URL url = URL.valueOf("www.baidu.com");
+//        TripleExceptionWrapperUtils tripleExceptionWrapperUtils = 
TripleExceptionWrapperUtils.init(new ScoreException(), url);
+//        byte[] tripleExceptionWrapperBytes = 
tripleExceptionWrapperUtils.packRequest(exception);
+//        CharSequence msg = 
StreamUtils.encodeBase64ASCII(tripleExceptionWrapperBytes);
+//        msg = TriRpcStatus.encodeMessage((String) msg);
+//        msg = TriRpcStatus.decodeMessage(msg.toString());
+//        byte[] tripleExceptionWrapperDecodeBytes = 
StreamUtils.decodeASCIIByte(msg);
+////        TripleExceptionWrapperUtils tripleExceptionWrapperUtils2 = 
TripleExceptionWrapperUtils.init(new ScoreException(), url);
+//        Object object1 = 
tripleExceptionWrapperUtils.unPackRequest(tripleExceptionWrapperDecodeBytes);
+//        System.out.println(object1 instanceof ScoreException);
+//        System.out.println(object1);
+//    }

Review Comment:
   remove unused code



##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/stream/TripleClientStream.java:
##########
@@ -283,7 +286,23 @@ private TriRpcStatus statusFromTrailers(Http2Headers 
trailers) {
             final Integer intStatus = 
trailers.getInt(TripleHeaderEnum.STATUS_KEY.getHeader());
             TriRpcStatus status = intStatus == null ? null : 
TriRpcStatus.fromCode(intStatus);
             if (status != null) {
-                final CharSequence message = 
trailers.get(TripleHeaderEnum.MESSAGE_KEY.getHeader());
+                CharSequence message = 
trailers.get(TripleHeaderEnum.MESSAGE_KEY.getHeader());
+                CharSequence messageException = 
trailers.get(TripleHeaderEnum.EXCEPTION_KEY.getHeader());
+                if (messageException != null) {
+                    String decodeMessageException = 
TriRpcStatus.decodeMessage(messageException.toString());
+                    byte[] decodeMessageExceptionByte = 
StreamUtils.decodeASCIIByte(decodeMessageException);
+                    TripleExceptionWrapperUtils tripleExceptionWrapperUtils = 
TripleExceptionWrapperUtils.
+                        init(null, URL.valueOf("TEST"));

Review Comment:
   Should this utils be a field of the stream?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to