• Implement CGLIB in ABAP


    What is cglib?A Byte Code Generation Library which is high level API to generate and transform Java byte code. It is used in various scenarios such as AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.
    See one example in unit test.
    In line 17, a new dynamic proxy class is generated as mock.
    In line 19, we tell the proxy, "if get(0) is called on this mock class, then return mocked data "hello, world".
    As a result, in line 23 "result: hello, world" will be printed out.

    clipboard1

    In debugger you can find that the variable in line 17 is mocked by CGLIB:

    clipboard2

    Its byte code is generated dynamically and stored in variable byte[] b in line 217.

    clipboard3

    Let's see another example of injecting pre-exit and post-exit ( which ABAPers are very familiar with ) into a given method via dynamic proxy generated by CGLIB:
    I have a class MyMEthodExitDemo which has a normal method myFun.
    A new dynamic proxy class is generated in method createProxy which has a method with equal name as original class plus custom enhancement covered by class JerryEnhancement.
    clipboard4

    The pre-exit and post-exit are defined in class JerryEnhancement which implements interface MethodInterceptor defined in CGLIB library. The original method is generated in line 14, with pre-exit before it ( line 13 ) and post-exit after it ( line 15 ).

    Execute result:

    How can CGLIB be implemented in ABAP?

    See my implementation here

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":
    公众号截图

  • 相关阅读:
    linux同一客户端多个git账号的配置
    linux同一台机子上用多个git 账号
    执行ssh-add时出现Could not open a connection to your authentication agent
    国内常用NTP服务器地址及IP
    PHP双引号的隐患
    mysql 累加求和
    php实现Facebook风格的 time ago函数
    Mysql之数据库设计规范
    搭建Git服务器
    win7下如何根据端口号杀掉进程
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/12021011.html
Copyright © 2020-2023  润新知