Questions tagged [dynamic-proxy]

A Dynamic Proxy is a class that implements a list of interfaces specified at runtime such that a method invocation through one of the interfaces on an instance of the class will be encoded and dispatched to another object through a uniform interface.

A Dynamic Proxy is a class that implements a list of interfaces specified at runtime such that a method invocation through one of the interfaces on an instance of the class will be encoded and dispatched to another object through a uniform interface. Thus, a dynamic proxy class can be used to create a type-safe proxy object for a list of interfaces without requiring pre-generation of the proxy class, such as with compile-time tools. Method invocations on an instance of a dynamic proxy class are dispatched to a single method in the instance's invocation handler, and they are encoded with a java.lang.reflect.Method object identifying the method that was invoked and an array of type Object containing the arguments.

Dynamic proxy classes are useful to an application or library that needs to provide type-safe reflective dispatch of invocations on objects that present interface APIs. For example, an application can use a dynamic proxy class to create an object that implements multiple arbitrary event listener interfaces (interfaces that extend java.util.EventListener) to process a variety of events of different types in a uniform fashion, such as by logging all such events to a file.

226 questions
0
votes
1 answer

java.lang.IllegalArgumentException thrown when trying to an set instance by reflection

My goal is to create an instance for a class while invoking its getter method, after that set a value for the new instance fields. (in this case, shown at the code the class is a String, but it could be another class "Like Person class") ...Entity…
Ali Taha
  • 199
  • 1
  • 2
  • 16
0
votes
1 answer

java.lang.ClassCastException on Proxy creation

My goal is to create an instance from a class that implements an interface and extends another class. ...Entity annotation: @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.FIELD}) public @interface Entity { String…
Ali Taha
  • 199
  • 1
  • 2
  • 16
0
votes
1 answer

Synchonizing on Java Class instance to store and retrieve Dynamically created Proxy classes at runtime

In our web application exists 'Access Bean' classes with some methods on them which perform queries on a DB, these are invoked multiple times per request. Therefore they need to be cached but the original classes cannot be altered as they are from…
0
votes
0 answers

Java Proxy invoke for nested calls

I'm having problems implementing a Proxy for a class that has to print the stacktrace for every call on a function of a class, because the functions are nested one with the other. The problem is very similar if not the same to one another user had,…
LowRez
  • 125
  • 2
  • 14
0
votes
1 answer

How can I log webdriver calls, proxy is not working

I'm attempting to write a proxy for RemoteWebDriver to add custom logging for methods such as findElement etc. As an experiment I found a TimingHandler that just provides a start/stop time stamp for methods - it works fine outside of selenium.…
mancocapac
  • 812
  • 6
  • 23
0
votes
0 answers

Proxy usage in Spring

We know that Spring uses proxies for specific features like AOP and transaction management. But does it use Java dynamic proxies or CGLib proxies for handling Beans ? If so wouldn't that carry a performance penalty ?
psaw.mora
  • 868
  • 1
  • 7
  • 18
0
votes
1 answer

How do I correctly generate a dynamic proxy class that's based on the right class?

I have an interface defined as follows: public interface Cache { } Then an abstract class implementing the above: public abstract class AbstractCache implements Cache { } Then a concrete class inheriting from above: public class RealTimeCache…
Ahmad
  • 12,886
  • 30
  • 93
  • 146
0
votes
1 answer

Wpf ComboBox SelectedItem doesn't work with dynamicProxy

Here I checked both ItemSource and SelectedItem and they both have the values I want. 'Tedarikciler' comes from database so it is an ObservableCollection which has a list of 'DynamicProxy.Tedarikci'. The type of SeciliIplik.Tedarikci is also…
0
votes
1 answer

Can static methods be intercepted with Castle DynamicProxy?

Can static methods be intercepted with Castle DynamicProxy? And if so, how?
SteveC
  • 15,808
  • 23
  • 102
  • 173
0
votes
1 answer

Using Dynamic Proxies for Feature Toggle

We've been using Guice for DI in AWS Lambdas, but now are moving to Spring Boot and long running services. We've got feature toggles working as dynamic proxies in Guice, but need to implement in Spring. Say we have a SomeFeature interface and two…
Eric
  • 283
  • 5
  • 12
0
votes
1 answer

Proxy for a class with no empty constructor using ByteBuddy

Is there a way to create a proxy for a class with no empty constructor using ByteBuddy? The idea is to create a proxy for a given concrete type and then redirect all the methods to a handler. This test showcases the scenario of creation of a proxy…
diegomtassis
  • 3,557
  • 2
  • 19
  • 29
0
votes
0 answers

Registering Dynamic Proxy on Net Core

I'm dabbling into AOP with Castle's Dynamic Proxy. I've made my first interceptors a selector and now was trying to use the proxy generator on the startup class: public class Startup { private static readonly ProxyGenerator _generator = new…
0
votes
1 answer

Entity Framework 4 cast object to dynamic proxy

In EF4, is it possible to convert a POCO object (created using new MyObject()) to a Dynamic Proxy (like you would get with ObjectContext.CreateObject())? Using EF4 with T4 template for POCO.
johan
  • 1
0
votes
1 answer

How to Dynamically Extend Concrete Classes with ByteBuddy

I've been playing with the ByteBuddy library for a while and I find myself stuck. I had this method working when the tested classes were within the same file (as static inner classes), but now that I've separated the logic into a separate file, it's…
A Frayed Knot
  • 476
  • 5
  • 20
0
votes
1 answer

Wrapping a service in a SleepyProxy to simulate lag

I am attempting to wrap a service in a proxy to simulate lag during tests. The following class is meant to wrap an object and sleep the thread for 100ms for any invoked method. import java.lang.reflect.InvocationHandler; import…
Chris
  • 387
  • 5
  • 16