MCPcopy Index your code
hub / github.com/Ericsson/proxy

github.com/Ericsson/proxy @1.2.28

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.2.28 ↗ · + Follow
769 symbols 2,326 edges 101 files 68 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Build Status license maven

Proxy

A small yet powerful interception library that lets you manipulate existing objects and classes behavior runtime, It's achieving this by using javassist to do bytecode manipulation, Proxy has a fluent interception API:

package examples;

import static com.ericsson.commonlibrary.proxy.Proxy.with;

public class FluentExample {

    public static class SomeImpl { //sample class

        public void log(String log) {
            System.out.println(log);
        }
    }

    public static void main(String[] args) throws SecurityException, NoSuchMethodException {

        //lambda on class
        SomeImpl obj = with(SomeImpl.class)
                .interceptAll(i -> {
                    System.out.println("before method: " + i.getMethodName() + " param: " + i.getParameter0());
                    return i.invoke();
                }).get();
        obj.log("123");
        //Console output:
        //        before method: log param: 123
        //        123

        //lambda on object
        SomeImpl obj2 = with(new SomeImpl())
                .interceptAll(i -> {
                    Object result = i.invoke();
                    System.out.println("after method: " + i.getMethodName() + " param: " + i.getParameter0());
                    return result;
                }).get();
        obj2.log("321");
        //Console output:
        //        321
        //        after method: log param: 321

        //lambda without return.
        SomeImpl obj3 = with(SomeImpl.class)
                .interceptAll((i) -> System.out.println("Replace method invocation: " + i.getMethodName()))
                .get();
        obj3.log("12345");
        //Console output:
        //        Replace method invocation: log
    }
}

What is Proxy and why use it?

Proxy is a highly general-purpose library that solve a typical Java development problem (Runtime change of behavior for classes and objects) that no other open source solution does today. Proxy is powerful interception library that lets you manipulate existing objects and classes(by internally using bytecode manipulation).

Using Proxy can allow you to architecturally implement your code completely differently using it’s features like:

  • Building complex object from small objects.
  • Create simple java beans objects without providing an implementation.
  • Dynamically change an interface of an object (duck typing)
  • Replacing an existing object with modified version.
  • Mixin / multiple inheritance functionality. (Not present in Java by default)
  • AOP like features.

Proxy is a great building block for creating other innovative solutions.

Alternative Solutions

  • Proxy like functionality is already included in Java itself but limited to interfaces only which is often not enough.
  • Often referred to as JDK dynamic proxies
  • https://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html
  • AspectJ very powerful but requires special plugins and learn a new language
  • Great at static interception done during compilation
  • Is missing most of the runtime features of Proxy.
  • Spring-AOP
  • Proxy is much more lightweight in comparison.
  • It does bytecode manipulation with cglib similarly to how Proxy does the same with Javassist
  • It is missing features like: recursive interception and delegation and object interception

User Guide

Under Construction: https://ericsson.github.io/proxy

How to Propose Changes

Anyone is welcome to propose changes to this repository by creating a new Issue ticket in GitHub. These requests may concern anything contained in the repo: changes to documentation, changes to interfaces, changes to implementations, additional tests et cetera.

When posting a new issue, try to be as precise as possible and phrase your arguments for your request carefully. Keep in mind that collaborative software development is often an exercise in finding workable compromises between multiple and often conflicting needs. In particular, pay attention to the following: 1. What type of change is requested? 1. Why would you like to see this change? 1. Can you provide any concrete examples? 1. Which arguments in favor can you think of? 1. Which arguments against can you think of, and why are they outweighed by the arguments in favor?

Also, keep in mind that just as anyone is welcome to propose a change, anyone is welcome to disagree with and criticize that proposal.

How to Contribute

While we welcome requests for changes (in the form of Issues), we absolutely love ready solutions (in the form of Pull Requests). The best requests are the ones with Pull Requests to go along with them.

Contributions can be made by anyone using the standard GitHub Fork and Pull model. When making a pull request, keep a few things in mind. 1. Always explicitly connect a pull request to an Issue. See How to Propose Changes above for further information. 1. Pull Requests will be publicly reviewed, criticized, and potentially rejected. Don't take it personally.

License

Proxy is licensed under the MIT License.

Code of Conduct

Extension points exported contracts — how you extend this code

JavaBean41 (Interface)
This is the example class of the class JavaBean4 in src/test/resources/external.jar and external-sign.jar. The si [6 implementers]
src/test/java/com/ericsson/commonlibrary/proxy/external/JavaBean41.java
Interceptor (Interface)
Interface that lets you intercept invocations of method calls. @author Elis Edlund (elis.edlund@ericsson.com) [39 implementers]
src/main/java/com/ericsson/commonlibrary/proxy/Interceptor.java
JavaBean3 (Interface)
(no doc) [6 implementers]
src/test/java/com/ericsson/commonlibrary/proxy/JavaBean3.java
InterceptorConsumer (Interface)
Interface that lets you intercept invocations of method calls. @author Elis Edlund (elis.edlund@ericsson.com) [27 implementers]
src/main/java/com/ericsson/commonlibrary/proxy/InterceptorConsumer.java
JavaBean2 (Interface)
(no doc) [6 implementers]
src/test/java/com/ericsson/commonlibrary/proxy/JavaBean2.java
InterceptableProxy (Interface)
Interface with methods an intercepteable proxy should implement to be able to add/remove Interceptors dynamicall
src/main/java/com/ericsson/commonlibrary/proxy/InterceptableProxy.java
PublicInterface (Interface)
(no doc) [9 implementers]
src/test/java/com/ericsson/commonlibrary/proxy/issues/packagescope/PublicInterface.java
JavaBean (Interface)
(no doc) [5 implementers]
src/test/java/examples/JavaBeanExample.java

Core symbols most depended-on inside this repo

add
called by 102
src/test/java/com/ericsson/commonlibrary/proxy/helpobjects/IAdd.java
intercept
called by 83
src/main/java/com/ericsson/commonlibrary/proxy/Proxy.java
delegate
called by 57
src/main/java/com/ericsson/commonlibrary/proxy/Proxy.java
getMethod
called by 57
src/main/java/com/ericsson/commonlibrary/proxy/Invocation.java
castStringValueToObject
called by 43
src/main/java/com/ericsson/commonlibrary/proxy/Util.java
javaBean
called by 35
src/main/java/com/ericsson/commonlibrary/proxy/Proxy.java
with
called by 22
src/main/java/com/ericsson/commonlibrary/proxy/Proxy.java
getMethodName
called by 21
src/main/java/com/ericsson/commonlibrary/proxy/Invocation.java

Shape

Method 531
Class 122
Function 93
Interface 21
Enum 2

Languages

Java88%
TypeScript12%

Modules by API surface

docs/js/apache-maven-fluido-1.7.min.js91 symbols
src/test/java/com/ericsson/commonlibrary/proxy/UtilCastStringValueToObjectTest.java43 symbols
src/main/java/com/ericsson/commonlibrary/proxy/Util.java34 symbols
src/test/java/com/ericsson/commonlibrary/proxy/UtilTest.java24 symbols
src/test/java/com/ericsson/commonlibrary/proxy/JavaBeanProxyTest.java24 symbols
src/main/java/com/ericsson/commonlibrary/proxy/InterceptableProxyFactory.java24 symbols
src/test/java/com/ericsson/commonlibrary/proxy/ProxyFluentTest.java20 symbols
src/test/java/com/ericsson/commonlibrary/proxy/InterceptObjectTest.java19 symbols
src/test/java/examples/BuildingObjectsExample.java18 symbols
src/test/java/com/ericsson/commonlibrary/proxy/InterceptClassTest.java18 symbols
src/test/java/com/ericsson/commonlibrary/proxy/DelegateProxyTest.java18 symbols
src/main/java/com/ericsson/commonlibrary/proxy/Proxy.java15 symbols

For agents

$ claude mcp add proxy \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact