{"id":157528,"date":"2020-09-06T19:35:43","date_gmt":"2020-09-06T11:35:43","guid":{"rendered":"http:\/\/4563.org\/?p=157528"},"modified":"2020-09-06T19:35:43","modified_gmt":"2020-09-06T11:35:43","slug":"whats-new-in-dubbo-go-hessian2-v1-7-0","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=157528","title":{"rendered":"What\u2019s New in Dubbo-go-hessian2 v1.7.0"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  What\u2019s New in Dubbo-go-hessian2 v1.7.0               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dubbogo <\/span>  <span><i><\/i> 8<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>Dubbo-go-hessian2 v1.7.0 \u5df2\u53d1\u5e03\uff0c\u8be6\u89c1 https:\/\/github.com\/apache\/dubbo-go-hessian2\/releases\/tag\/v1.7.0\uff0c \u4ee5\u4e0b\u5bf9\u8fd9\u6b21\u66f4\u65b0\u5185\u5bb9\u8fdb\u884c\u8be6\u7ec6\u6574\u7406\u3002<\/p>\n<p>\u53e6\u5916 v1.6.3 \u5c06 attachment \u7c7b\u578b\u7531 map[string]stiring \u6539\u4e3a map[string]interface{} \u5bfc\u81f4\u7248\u672c\u4e0d\u517c\u5bb9\u95ee\u9898\uff0c\u8fd9\u90e8\u5206\u5df2\u8fd8\u539f\uff0c\u540e\u7eed\u7684\u8ba1\u5212\u662f\u5c06 dubbo \u534f\u8bae\u7684 request\/response \u5bf9\u8c61\u6574\u4f53\u8fc1\u79fb\u5230 dubbogo \u9879\u76ee\u4e2d\u8fdb\u884c\u8fed\u4ee3\u4fee\u6539\uff0chessian2 \u4e2d\u5c06\u4e0d\u518d\u6539\u52a8\u5230 request\/response \u5bf9\u8c61\u3002<\/p>\n<h2>1. New Features<\/h2>\n<h3>1.1 add GetStackTrace method into Throwabler and its implements. #207<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/cvictory<\/p>\n<\/blockquote>\n<p>go \u8bed\u8a00 client \u8bf7\u6c42 java \u8bed\u8a00\u670d\u52a1\u65f6\uff0c\u5982\u679c java \u8bed\u8a00\u629b\u51fa\u4e86\u5f02\u5e38\uff0c\u5f02\u5e38\u5bf9\u5e94\u7684\u5806\u6808\u4fe1\u606f\u662f\u88ab\u4fdd\u5b58\u5728 StackTraceElement \u4e2d\u3002<\/p>\n<p>\u8fd9\u4e2a\u5f02\u5e38\u4fe1\u606f\u5728\u65e5\u5fd7\u4e2d\u6700\u597d\u80fd\u88ab\u6253\u5370\u51fa\u6765\uff0c\u4ee5\u65b9\u4fbf\u5ba2\u6237\u7aef\u6392\u67e5\u95ee\u9898\uff0c\u6240\u4ee5\u5728 Throwabler \u548c\u5bf9\u5e94\u5b50\u7c7b\u4e2d\u589e\u52a0\u4e86 StackTraceElement \u7684\u83b7\u53d6\u3002<\/p>\n<p>\u6ce8\uff1a\u5176\u5b9e\u8fd8\u6709\u4e00\u79cd\u66f4\u597d\u7684\u65b9\u6cd5\uff0c\u6240\u6709\u7684\u5177\u4f53\u7684\u5f02\u5e38\u7c7b\u578b\u90fd\u5305\u542b java_exception\/exception.go \u7684 Throwable struct \u3002\u8fd9\u6837\u53ea\u9700\u8981\u5728 Throwable \u4e2d\u589e\u52a0 GetStackTrace \u65b9\u6cd5\u5c31\u53ef\u4ee5\u4e86\u3002\u4f46\u662f\u8fd9\u79cd\u65b9\u5f0f\u9700\u8981\u66f4\u591a\u7684\u6d4b\u8bd5\u9a8c\u8bc1\uff0c\u6539\u52a8\u7684\u903b\u8f91\u76f8\u5bf9\u4f1a\u590d\u6742\u4e00\u4e9b\u3002\u4f46\u662f\u4ee3\u7801\u4f1a\u66f4\u6574\u6d01\u3002 \u8fd9\u91cc\u5148\u4e0d\u7528\u8fd9\u79cd\u65b9\u6cd5\u3002<\/p>\n<h3>1.2 catch user defined exceptions. #208<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/cvictory<\/p>\n<\/blockquote>\n<p>golang \u4e2d\u589e\u52a0\u4e00\u4e2a java \u4e2d Exception \u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u8f93\u51fa\u65b9\u6cd5\uff1a<\/p>\n<pre><code>func JavaException() []byte {  e := hessian.NewEncoder()  exception := java_exception.NewException(\"java_exception\")  e.Encode(exception)  return e.Buffer() } <\/code><\/pre>\n<p>\u5728 output\/output.go \u63d0\u4f9b\u8c03\u7528\u5165\u53e3:\u6dfb\u52a0\u5982\u4e0b\u51fd\u6570\u521d\u59cb\u5316\u58f0\u660e<\/p>\n<pre><code>func init() {     funcMap[\"JavaException\"] = testfuncs.JavaException } <\/code><\/pre>\n<p>java \u4ee3\u7801\u4e2d\u589e\u52a0\u8c03\u7528 go \u65b9\u6cd5\u5e8f\u5217\u5316\u7ed3\u679c: <strong>\u8bf4\u660e<\/strong>: Assert.assertEquals \u4e0d\u80fd\u76f4\u63a5\u6bd4\u8f83 Exception \u5bf9\u8c61\u662f\u5426\u76f8\u7b49<\/p>\n<pre><code>    \/**      * test java java.lang.Exception object and go java_exception Exception struct      *\/     @Test     public void testException() {         Exception exception = new Exception(\"java_exception\");         Object javaException = GoTestUtil.readGoObject(\"JavaException\");         if (javaException instanceof Exception) {             Assert.assertEquals(exception.getMessage(), ((Exception) javaException).getMessage());         }     } <\/code><\/pre>\n<h3>1.3 support java8 time object. #212, #221<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/willson-chen, https:\/\/github.com\/cyb-code<\/p>\n<\/blockquote>\n<p>golang \u4e2d\u589e\u52a0\u4e00\u4e2a java8 \u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u8f93\u51fa\u65b9\u6cd5\uff1a<\/p>\n<pre><code>\/\/ test java8 java.time.Year func Java8TimeYear() []byte {     e := hessian.NewEncoder()     year := java8_time.Year{Year: 2020}     e.Encode(year)     return e.Buffer() }  \/\/ test java8 java.time.LocalDate func Java8LocalDate() []byte {     e := hessian.NewEncoder()     date := java8_time.LocalDate{Year: 2020, Month: 9, Day: 12}     e.Encode(date)     return e.Buffer() } <\/code><\/pre>\n<p>\u5728 output\/output.go \u63d0\u4f9b\u8c03\u7528\u5165\u53e3:\u6dfb\u52a0\u51fd\u6570\u521d\u59cb\u5316\u58f0\u660e<\/p>\n<pre><code>func init() {  funcMap[\"Java8TimeYear\"] = testfuncs.Java8TimeYear  funcMap[\"Java8LocalDate\"] = testfuncs.Java8LocalDate } <\/code><\/pre>\n<p>java \u4ee3\u7801\u4e2d\u589e\u52a0\u8c03\u7528 go \u65b9\u6cd5\u5e8f\u5217\u5316\u7ed3\u679c:<\/p>\n<pre><code>\/**  * test java8 java.time.* object and go java8_time\/* struct  *\/ @Test public void testJava8Year() {     Year year = Year.of(2020);     Assert.assertEquals(year             , GoTestUtil.readGoObject(\"Java8TimeYear\"));     LocalDate localDate = LocalDate.of(2020, 9, 12);     Assert.assertEquals(localDate, GoTestUtil.readGoObject(\"Java8LocalDate\")); } <\/code><\/pre>\n<h3>1.4 support test golang encoding data in java. #213<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/wongoo<\/p>\n<\/blockquote>\n<p>\u4e3a\u4e86\u66f4\u597d\u7684\u6d4b\u8bd5\u9a8c\u8bc1 hessian \u5e93\uff0c\u539f\u6765\u5df2\u7ecf\u652f\u6301\u5728 golang \u4e2d\u6d4b\u8bd5 java \u7684\u5e8f\u5217\u5316\u6570\u636e\uff0c\u73b0\u5728\u589e\u52a0\u5728 java \u4e2d\u6d4b\u8bd5 golang \u7684\u5e8f\u5217\u5316\u6570\u636e\uff0c\u5b9e\u73b0\u53cc\u5411\u6d4b\u8bd5\u9a8c\u8bc1\u3002<\/p>\n<p>golang \u4e2d\u589e\u52a0\u5e8f\u5217\u5316\u8f93\u51fa\u65b9\u6cd5:<\/p>\n<pre><code>func HelloWorldString() []byte {     e := hessian.NewEncoder()     e.Encode(\"hello world\")     return e.Buffer() } <\/code><\/pre>\n<p>\u5c06\u8be5\u65b9\u6cd5\u6ce8\u518c\u5230 output\/output.go \u4e2d<\/p>\n<pre><code> \/\/ add all output func here  func init() {      funcMap[\"HelloWorldString\"] = testfuncs.HelloWorldString } <\/code><\/pre>\n<p>output\/output.go \u63d0\u4f9b\u8c03\u7528\u5165\u53e3:<\/p>\n<pre><code>func main() {     flag.Parse()      if *funcName == \"\" {         _, _ = fmt.Fprintln(os.Stderr, \"func name required\")         os.Exit(1)     }     f, exist := funcMap[*funcName]     if !exist {         _, _ = fmt.Fprintln(os.Stderr, \"func name not exist: \", *funcName)         os.Exit(1)     }      defer func() {         if err := recover(); err != nil {             _, _ = fmt.Fprintln(os.Stderr, \"error: \", err)             os.Exit(1)         }     }()     if _, err := os.Stdout.Write(f()); err != nil {         _, _ = fmt.Fprintln(os.Stderr, \"call error: \", err)         os.Exit(1)     }     os.Exit(0) } <\/code><\/pre>\n<p>java \u4ee3\u7801\u4e2d\u589e\u52a0\u8c03\u7528 go \u65b9\u6cd5\u5e8f\u5217\u5316\u7ed3\u679c:<\/p>\n<pre><code>public class GoTestUtil {      public static Object readGoObject(String func) {         System.out.println(\"read go data: \" + func);         try {             Process process = Runtime.getRuntime()                     .exec(\"go run output\/output.go -func_name=\" + func,                             null,                             new File(\"..\"));              int exitValue = process.waitFor();             if (exitValue != 0) {                 Assert.fail(readString(process.getErrorStream()));                 return null;             }              InputStream is = process.getInputStream();             Hessian2Input input = new Hessian2Input(is);             return input.readObject();         } catch (Exception e) {             e.printStackTrace();             return null;         }     }      private static String readString(InputStream in) throws IOException {         StringBuilder out = new StringBuilder();         InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8);         char[] buffer = new char[4096];          int bytesRead;         while ((bytesRead = reader.read(buffer)) != -1) {             out.append(buffer, 0, bytesRead);         }          return out.toString();     } } <\/code><\/pre>\n<p>\u589e\u52a0 java \u6d4b\u8bd5\u4ee3\u7801:<\/p>\n<pre><code>@Test public void testHelloWordString() {     Assert.assertEquals(\"hello world\"             , GoTestUtil.readGoObject(\"HelloWorldString\")); } <\/code><\/pre>\n<h3>1.5 support java.sql.Time &amp; java.sql.Date. #219<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/zhangshen023<\/p>\n<\/blockquote>\n<p>\u589e\u52a0\u4e86 java \u7c7b java.sql.Time, java.sql.Date \u652f\u6301\uff0c\u5206\u522b\u5bf9\u5e94\u5230 hessian.Time \u548c hessian.Date\uff0c \u8be6\u89c1 https:\/\/github.com\/apache\/dubbo-go-hessian2\/pull\/219\/files \u3002<\/p>\n<h2>2. Enhancement<\/h2>\n<h3>2.1 Export function EncNull. #225<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/cvictory<\/p>\n<\/blockquote>\n<p>\u5f00\u653e hessian.EncNull \u65b9\u6cd5\uff0c\u4ee5\u4fbf\u7528\u6237\u7279\u5b9a\u60c5\u51b5\u4e0b\u4f7f\u7528\u3002<\/p>\n<h2>3. Bugfixes<\/h2>\n<h3>3.1 fix enum encode error in request. #203<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/pantianying<\/p>\n<\/blockquote>\n<p>\u539f\u6765\u5728 dubbo request \u5bf9\u8c61\u4e2d\u6ca1\u6709\u5224\u65ad enum \u7c7b\u578b\u7684\u60c5\u51b5\uff0c\u6b64 pr \u589e\u52a0\u4e86\u5224\u65ad\u662f\u4e0d\u662f POJOEnum \u7c7b\u578b\u3002\u8be6\u89c1 https:\/\/github.com\/apache\/dubbo-go-hessian2\/pull\/203\/files<\/p>\n<h3>3.2 fix []byte field decoding issue. #216<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/wongoo<\/p>\n<\/blockquote>\n<p>v1.7.0 \u4e4b\u524d\u5982\u679c struct \u4e2d\u5305\u542b[]byte \u5b57\u6bb5\u65f6\u65e0\u6cd5\u53cd\u5e8f\u5217\u5316, \u62a5\u9519\u201cerror list tag: 0x29\u201d\uff0c\u4e3b\u8981\u539f\u56e0\u662f\u88ab\u5f53\u505a list \u8fdb\u884c\u5904\u7406\uff0c\u5bf9\u4e8e\u8fd9\u79cd\u60c5\u51b5\u5e94\u8be5\u6309\u7167 binary \u6570\u636e\u8fdb\u884c\u5904\u7406\u5373\u53ef\u3002<\/p>\n<pre><code>type Circular struct {     Num      int  Previous *Circular  Next     *Circular  ResponseDataBytes    []byte \/\/ &lt;----  }  func (Circular) JavaClassName() string {  return \"com.company.Circular\" } <\/code><\/pre>\n<h3>3.3 fix decoding error for map in map. #229<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/wongoo<\/p>\n<\/blockquote>\n<p>v1.7.0 \u4e4b\u524d\u5d4c\u5957 map \u65e0\u6cd5\u6b63\u786e\u89e3\u6790\uff0c\u4e3b\u8981\u539f\u56e0\u662f\u5bf9\u5e94\u7684 map \u5bf9\u8c61\u88ab\u5f53\u505a\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\u5374\u672a\u88ab\u81ea\u52a8\u52a0\u5230\u7c7b\u5f15\u7528\u5217\u8868\u4e2d\uff0c\u800c\u5d4c\u5957 map \u7c7b\u4fe1\u606f\u662f\u540c\u4e00\u7c7b\u578b\u7684\u5f15\u7528\uff0c\u53bb\u7c7b\u5f15\u7528\u5217\u8868\u627e\uff0c\u627e\u4e0d\u5230\u5c31\u62a5\u9519\u4e86\u3002 \u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u65b9\u6cd5\u5c31\u662f\u9047\u5230 map \u7c7b\u5bf9\u8c61\uff0c\u4e5f\u5c06\u5176\u52a0\u5165\u5230\u7c7b\u5f15\u7528\u5217\u8868\u4e2d\u5373\u53ef\u3002 \u95ee\u9898\u8be6\u7ec6\u53c2\u8003 #119.<\/p>\n<h3>3.4 fix fields name mismatch in Duration class. #234<\/h3>\n<blockquote>\n<p>contributed by https:\/\/github.com\/skyao<\/p>\n<\/blockquote>\n<p>\u8fd9\u4e2a PR \u89e3\u51b3\u4e86 Duration \u5bf9\u8c61\u4e2d\u5b57\u6bb5\u9519\u8bef\u5b9a\u4e49\uff0c\u539f\u6765\u662f&#8221;second\/nano&#8221;\uff0c \u5e94\u8be5\u662f&#8221;seconds\/nanos&#8221;\u3002<\/p>\n<p>\u540c\u65f6\u6539\u5584\u4e86\u6d4b\u8bd5\u9a8c\u8bc1\u6570\u636e\u3002\u4e4b\u524d\u4f7f\u7528 0 \u4f5c\u4e3a int \u5b57\u6bb5\u7684\u6d4b\u8bd5\u6570\u636e\uff0c\u8fd9\u662f\u4e0d\u51c6\u786e\u7684\uff0c\u56e0\u4e3a int \u7c7b\u578b\u9ed8\u8ba4\u503c\u5c31\u662f 0.<\/p>\n<h2>\u6b22\u8fce\u52a0\u5165 dubbo-go \u793e\u533a<\/h2>\n<p>\u6709\u4efb\u4f55 dubbo-go \u76f8\u5173\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u52a0\u6211\u4eec\u7684\u9489\u9489\u7fa4 23331795 \u8be2\u95ee\u63a2\u8ba8\uff0c\u6211\u4eec\u4e00\u5b9a\u7b2c\u4e00\u65f6\u95f4\u7ed9\u51fa\u53cd\u9988\u3002 <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/09\/20200921_5f68a1d6237c5.jpg\" alt=\"What\u2019s New in Dubbo-go-hessian2 v1.7.0\" \/><\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>What\u2019s New in Dub&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/157528"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=157528"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/157528\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=157528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=157528"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=157528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}