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
5
votes
2 answers

Create a dynamic proxy for an abstract class with an internal constructor

I'd like to create dynamic proxy for a type in the BCL that is an abstract class with an internal constructor. I've been castle's dynamic proxy and this fails with an exception stating there is no parameterless constructor (their is - it's…
Robert
  • 6,407
  • 2
  • 34
  • 41
5
votes
3 answers

How can I use a dynamic proxy on constructors that take arguments?

I've tried to use the code Sun posted on their Proxy usage page, and I tried to use the DebugProxy to print which method is invoked. The thing is, the object I'm creating a proxy for, needs to have an argument. If I try to create the proxy with an…
Geo
  • 93,257
  • 117
  • 344
  • 520
4
votes
0 answers

Dynamic Proxying IEnumerable

I'm trying to create a dynamic proxy to a list of objects of a specific class. For example: var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof (IEnumerable), …
HellSpam
  • 81
  • 1
  • 4
4
votes
3 answers

Avoiding raw types in Java message dispatcher

Objective I am trying to build a MessageDispatcher that converts messages from a 3rd party API in to user defined messages and then dispatches them to a user registered listener. The user will be expected to: Define an interface for each type of…
Karle
  • 880
  • 2
  • 12
  • 21
4
votes
0 answers

Set ProxySelector and Authenticator back to their default

I was tasked to write a custom ProxySelector implementation for our current OSGi project. In order to use authentication for proxies I also had to write a custom Authenticator. Setting these custom implementations when the OSGi bundle starts works…
Jens
  • 20,533
  • 11
  • 60
  • 86
4
votes
1 answer

spring scoped proxy and JAXB

JAXBContext is thread-safe but the Unmarshaller is not. I'd like to make the unmarshaller a request scope bean, and I'm doing this:
Kevin
  • 24,871
  • 19
  • 102
  • 158
4
votes
2 answers

java.lang.reflect.Proxy: Huge exception stack trace

Here is a simple Java application: import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; public class Main { interface MyInterface { void myMethod(); } public static void…
Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110
4
votes
1 answer

When to use "Dynamic Proxy class" or "standard proxy" pattern?

Why should one use a "Dynamic Proxy class" instead of the "standard proxy" pattern? What are the disadvantages or advantages of both? It seems like they both have the same end result, except that they are implemented differently. Dynamic proxy…
G-J
  • 401
  • 7
  • 17
4
votes
4 answers

How do I replace a method implementation at runtime?

I'd like to have property getters and methods that I can decorate with my own custom attribute and based on the presence of that attribute replace the method bodies with a different implementation. Also, that different implementation will need to…
quentin-starin
  • 26,121
  • 7
  • 68
  • 86
4
votes
1 answer

Intercept Properties With Castle Windsor IInterceptor

Does anyone have a suggestion on a better way to intercept a properties with Castle DynamicProxy? Specifically, I need the PropertyInfo that I'm intercepting, but it's not directly on the IInvocation, so what I do is: public static PropertyInfo…
Jeff
  • 35,755
  • 15
  • 108
  • 220
4
votes
2 answers

Are all methods proxied when using Spring AOP?

When using Spring AOP to create a proxy for a class using NameMatchMethodPointcutAdvisor and BeanNameAutoProxyCreator does this essentially proxy every call to the object, but only apply the advice to the matched methods, or somehow create a Proxied…
Gandalf
  • 9,648
  • 8
  • 53
  • 88
4
votes
1 answer

Dynamic proxy classes in C++. Is it possible?

First of all, let me say that I'm not a guru C++ programmer. I have a few years of experience in C++, but my main area is .NET/C#. I'm looking into a way to create dynamic proxy/wrapper classes in C++. Particularly, what I want to achieve is to…
Davita
  • 8,928
  • 14
  • 67
  • 119
4
votes
2 answers

How to intercept a call to a nonvirtual method from/to thirdy-party libraries in .Net?

I think what I need is something the .net folks call "transparent dynamic proxy", but all the implementations I've seen this far (Castle DynamicProxy, Spring.NET AOP, etc) require me to do at least one of these: Declare intercepted method as…
ygormutti
  • 358
  • 3
  • 17
4
votes
2 answers

How to avoid double construction of proxy with DynamicProxy::CreateClassProxyWithTarget?

I am decorating an existing object using the CreateClassProxyWithTarget method. However, the constructor and therefore, initialization code, is being called twice. I already have a "constructed" instance (the target). I understand why this happens,…
Belvasis
  • 238
  • 1
  • 9
3
votes
1 answer

DynamicProxyFactory error with received data size

I use a dynamicproxyfactory in order to call any webservice by a wsdl string path. Unfortunalty, when a webservice answers a lot of data, an exception is raised : System.ServiceModel.CommunicationException: Le quota de taille maximale autorisée …
BaptX
  • 561
  • 1
  • 7
  • 21