{"id":23185974,"url":"https://github.com/lamspace/newproxy","last_synced_at":"2025-06-13T19:04:49.660Z","repository":{"id":238229023,"uuid":"796142924","full_name":"LamSpace/newproxy","owner":"LamSpace","description":"A tool to generate dynamic proxy for interfaces and class. following the concept of JDK's built in Proxy.","archived":false,"fork":false,"pushed_at":"2024-06-01T11:50:18.000Z","size":226,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T19:03:16.373Z","etag":null,"topics":["bcel","proxy"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LamSpace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.MD","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-05T04:08:40.000Z","updated_at":"2024-06-01T11:50:22.000Z","dependencies_parsed_at":"2024-05-22T07:37:38.162Z","dependency_job_id":"d351b4cf-95fc-4695-8b17-0c174f452385","html_url":"https://github.com/LamSpace/newproxy","commit_stats":null,"previous_names":["lamtong/newproxy","lamspace/newproxy"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LamSpace/newproxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LamSpace%2Fnewproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LamSpace%2Fnewproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LamSpace%2Fnewproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LamSpace%2Fnewproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LamSpace","download_url":"https://codeload.github.com/LamSpace/newproxy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LamSpace%2Fnewproxy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259704408,"owners_count":22898858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bcel","proxy"],"created_at":"2024-12-18T10:13:50.236Z","updated_at":"2025-06-13T19:04:49.634Z","avatar_url":"https://github.com/LamSpace.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NewProxy: New Proxy for Java\n\n[中文](./README_CN.md)\n\n![Gitter](https://img.shields.io/gitter/room/lamspace/newproxy)\n[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)\n![Static Badge](https://img.shields.io/badge/NewProxy-New%20Proxy%20for%20Java-color=red)\n![GitHub Repo stars](https://img.shields.io/github/stars/lamspace/newproxy)\n![GitHub forks](https://img.shields.io/github/forks/lamspace/newproxy)\n![GitHub Release](https://img.shields.io/github/v/release/lamspace/newproxy)\n![Maven Central Version](https://img.shields.io/maven-central/v/io.github.lamspace/newproxy)\n\n---\n\n## What is it?\n\n\u003e **NewProxy** is an extension of **Proxy**, It is similar to **CGLIB**.\n\u003e But it is as fast as **CGLIB** as possible, even faster, simpler and smaller than **CGLIB**.\n\nMore details see [GitHub](https://github.com/LamSpace/newproxy-samples)\nor [Gitee](https://gitee.com/LamTong/newproxy-samples).\n\n---\n\n## What does it do?\n\n**NewProxy** is a tool to generate **dynamic proxy** for interfaces, and class also.\n\nIt follows the concept of JDK's built-in **Proxy** class for generating dynamic proxy classes,\nwhich involves creating a proxy class for the target interfaces and then invoking its methods,\nreturning the results to the caller.\nIn contrast to the JDK's **Proxy** class, dynamic proxy class generated by **NewProxy** does not extend **NewProxy**\nitself; instead, it merely implements the specified interfaces (including extra **InvocationDispatcher** interface)\nand extend class, significantly reducing the complexity of the generated proxy classes.\n\nBesides, **NewProxy** also supports generating dynamic proxy class for one class at most like **CGLIB** does.\n\n**NewProxy** provides the following features:\n\n* Generate dynamic proxy classes for public interfaces and class with **public final** modifiers.\n* Generate dynamic proxy classes for non-public interfaces and class with *final* modifier.\n* Check whether the target class if a dynamic proxy class or not.\n* Check if the target object is an instance of a dynamic proxy class or not.\n* Acquire the invocation interceptor instance of the target object if its class is a dynamic proxy class.\n\n---\n\n## Quick Start\n\nIt's straightforward to use **NewProxy** to generate dynamic proxy classes as it is to use **Proxy**.\n\nFirst of all, you need to import the **NewProxy** library into your project.\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.lamspace\u003c/groupId\u003e\n    \u003cartifactId\u003enewproxy\u003c/artifactId\u003e\n    \u003cversion\u003e${latest.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Case 1: Generate dynamic proxy class for only interface(s)\n\n```java\npublic interface Foo {\n\n    void foo();\n\n}\n```\n\nThen you need to do as follows:\n\n```java\nimport io.github.lamspace.newproxy.InvocationInterceptor;\nimport io.github.lamspace.newproxy.MethodDecorator;\nimport io.github.lamspace.newproxy.NewProxy;\n\npublic static void main(String[] args) {\n    InvocationInterceptor interceptor = new InvocationInterceptor() {\n        @Override\n        public Object intercept(Object proxy, MethodDecorator method, Object[] args) {\n            return method.invoke(proxy, fooImpl, args);\n        }\n    };\n    Foo foo = (Foo) NewProxy.newProxyInstance(Foo.class.getClassLoader(), interceptor, null, null, Foo.class);\n    foo.foo();\n}\n```\n\n---\n\n### Case 2: Generate dynamic proxy class for class with non-parameter constructor\n\n```java\npublic class Bar {\n\n    public void bar() {\n        // ...\n    }\n\n}\n```\n\n```java\nimport io.github.lamspace.newproxy.InvocationInterceptor;\nimport io.github.lamspace.newproxy.MethodDecorator;\nimport io.github.lamspace.newproxy.NewProxy;\n\npublic static void main(String[] args) {\n    InvocationInterceptor interceptor = new InvocationInterceptor() {\n        @Override\n        public Object intercept(Object proxy, MethodDecorator method, Object[] args) throws Throwable {\n            return method.invoke(proxy, null, args);\n        }\n    };\n    Bar bar = (Bar) NewProxy.newProxyInstance(Bar.class.getClassLoader(), interceptor, null, null, Bar.class);\n    bar.bar();\n}\n```\n\n### Case 3: Generate dynamic proxy class for class with parameterized constructor\n\n```java\npublic class Bar {\n\n    private final String s;\n\n    public Bar(Strin s) {\n        this.s = s;\n    }\n\n    public void bar() {\n        //...\n    }\n\n}\n```\n\n```java\nimport io.github.lamspace.newproxy.InvocationInterceptor;\nimport io.github.lamspace.newproxy.MethodDecorator;\n\npublic static void main(String[] args) {\n    InvocationInterceptor interceptor = new InvocationInterceptor() {\n        @Override\n        public Object intercept(Object proxy, MethodDecorator method, Object[] args) throws Throwable {\n            return method.invoke(proxy, null, args);\n        }\n    };\n    Bar bar = (Bar) NewProxy.newProxyInstance(Bar.class.getClassLoader(), interceptor, new Class\u003c?\u003e[]{String.class}, new Object[]{\"Hello World!\"}, Bar.class);\n    bar.bar();\n}\n```\n\n### Case 4: Generate dynamic proxy class for interfaces and class\n\n...\n\n---\n\n## Underlying Support\n\n**NewProxy** is built on top of the **Byte Code Engineering Library**\n(simply called [BCEL](https://commons.apache.org/proper/commons-bcel/)).\nMore details can be found in the [BCEL](https://commons.apache.org/proper/commons-bcel/) official website.\n\n---\n\n## Prerequisites\n\nAt least JDK 8 is required.\n\n---\n\n## Contributing\n\nContributions are welcome! Do what you want to do with **Apache License 2.0**!\nPlease check [CONTRIBUTING](./CONTRIBUTING.md).\n\n*Cheers!*\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamspace%2Fnewproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamspace%2Fnewproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamspace%2Fnewproxy/lists"}