前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Implement CGLIB in ABAP

Implement CGLIB in ABAP

作者头像
Jerry Wang
发布2019-12-17 18:45:17
2870
发布2019-12-17 18:45:17
举报

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
clipboard1

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

clipboard2
clipboard2

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

clipboard3
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
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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-12-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • How can CGLIB be implemented in ABAP?
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档