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.
In debugger you can find that the variable in line 17 is mocked by CGLIB:
Its byte code is generated dynamically and stored in variable byte[] b in line 217.
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.
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的原创文章,请关注公众号"汪子熙":
相关文章
- 使用jxls导出报错:Connot load XLS transformer please make sure a Transformer implementation is in classpath
- CF587D Duff in Mafia
- ORA-19320: Host name not specified in HTTP URL ORACLE 报错 故障修复 远程处理
- ORA-32416: one or more commit SCN-based materialized view logs are not in consistent state for fast refresh ORACLE 报错 故障修复 远程处理
- ORA-55374: query constants not in the database; no rows selected ORACLE 报错 故障修复 远程处理
- ORA-64006: lock conflict in current operation ORACLE 报错 故障修复 远程处理
- ORA-01156: recovery or flashback in progress may need access to files ORACLE 报错 故障修复 远程处理
- ORA-06608: LU6.2 Driver: Reset occurred in receive state ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-011768; Symbol: ER_LDAP_AUTH_FAILED_TO_INITIALIZE_POOL_IN_INIT_STATE; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-15003: diskgroup “string” already mounted in another lock name space ORACLE 报错 故障修复 远程处理
- ORA-15503: cannot startup instance when procedures in “DBMS_WORKLOAD_CAPTURE” or “DBMS_WORKLOAD_REPLAY” are in the middle of their execution ORACLE 报错 故障修复 远程处理
- Linux: A Powerhouse in the IT World(linux.h)
- MySQL中的IN运算符技巧(mysql查in)
- 搜索MySQL中IN搜索的应用(mysql包含in)
- 子查询MySQL:实现多条件 IN 子查询(mysql多条件in)
- Oracle中使用IN函数查找元素(oracle 函数 in)
- MSSQL条件查询IN机制优化技巧(mssql条件查询in)
- MySQL中利用IN查询实现多参数搜索(mysql的in查询)
- 使用in操作符时MySQL是否能够充分利用索引MySQL In操作符优化技巧(mysql中in走索引吗)
- MySQL中IN操作符的用法与注意事项(mysql中in的写法)
- MySQL中使用IN子句出现重复值问题的解决方法(mysql中in有重复值)
- MySQL中IN操作最大长度详解(mysql中in最大长度)
- MySQL如何使用IN查询语句(mysql不能用in吗)
- 利用Oracle中的IN语句优化查询效率(oracle中的in语句)
- Oracle In决定系统新时代的一种转变(oracle in 代表)