sofastack / sofa-rpc

SOFARPC is a high-performance, high-extensibility, production-level Java RPC framework.
https://www.sofastack.tech/sofa-rpc/docs/Home
Apache License 2.0
3.81k stars 1.17k forks source link

修改请求参数转换逻辑 #1347

Closed miaomiaoLmm closed 8 months ago

miaomiaoLmm commented 11 months ago

修改请求参数转换逻辑: 问题:rpc请求序列化异常,rpc请求进行request参数序列化,由于子类没有重写apply方法,导致从父类获取apply方法中的request和response类型,由于类型定义为范型,request参数序列化过程会自动转换为linkedHashMap类型并请求apply方法,由于apply方法中调用的process方法确定了实际的request类型,导致linkedHashMap转换Request类型异常

interface A<T,R>{
  R apply(T t);
}

public abstract class B<T,R> implements A<T,R>{
   @Override
    public R apply(T request) {
        return this.process(request);
    }

protected abstract R process(T request);
}      

class C extends B<Request,Response>{
    @Override
    protected Response process(Request request) {
        logger.info("Hello FaaS !");
        Response resp = new Response();
        resp.setUrl(request.getUrl());
        return resp;
    }

}

}

解决方案:判断重写apply方法的class类是否为目标类,如果不是目标类,通过获取目标类上确定的Request和Response类型进行请求参数序列化。

sofastack-cla[bot] commented 11 months ago

Hi @miaomiaoLmm, welcome to SOFAStack community, Please sign Contributor License Agreement!

After you signed CLA, we will automatically sync the status of this pull request in 3 minutes.

sofastack-cla[bot] commented 11 months ago

Hi @miaomiaoLmm, welcome to SOFAStack community, Please sign Contributor License Agreement!

After you signed CLA, we will automatically sync the status of this pull request in 3 minutes.

codecov[bot] commented 11 months ago

Codecov Report

Merging #1347 (d4489eb) into master (8ca4f28) will decrease coverage by 0.01%. Report is 4 commits behind head on master. The diff coverage is 88.88%.

:exclamation: Current head d4489eb differs from pull request most recent head c37390e. Consider uploading reports for the commit c37390e to get more accurate results

@@             Coverage Diff              @@
##             master    #1347      +/-   ##
============================================
- Coverage     72.05%   72.05%   -0.01%     
- Complexity      783      784       +1     
============================================
  Files           416      416              
  Lines         17661    17668       +7     
  Branches       2752     2753       +1     
============================================
+ Hits          12726    12730       +4     
  Misses         3533     3533              
- Partials       1402     1405       +3     
Files Changed Coverage Δ
...m/alipay/sofa/rpc/codec/jackson/JacksonHelper.java 84.78% <88.88%> (+0.16%) :arrow_up:

... and 2 files with indirect coverage changes

Lo1nt commented 11 months ago

pls do a 'mvn clean package -Dmaven.test.skip=true' before u commit and push

stale[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.