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
}
}
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:
Proxy is a great building block for creating other innovative solutions.
Under Construction: https://ericsson.github.io/proxy
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.
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.
Proxy is licensed under the MIT License.
$ claude mcp add proxy \
-- python -m otcore.mcp_server <graph>