Suppose you have a Client and a TargetSessionBean, with TargetSessionHome and TargetSession interfaces. You want to place a proxy in front of the session bean, transparantly for the client.
First of all, create the proxy as a session bean – statefull or stateless, depending on the target bean type - with the same interfaces as the TargetSessionBean. This gives you a ProxySessionBean, with TargetSession and TargetSessionHome interfaces.
Now you have to implement the ProxySessionBean. In the ejbCreate() method, create an instance of TargetSessionBean and cache this in the proxy. Forward each business method of the ProxySessionBean to the target:
public Object executeBusinessMethod(Object input)
{
//pre-processing here
Object result = targetSession.execute(input);
//post-processing here
return result;
}
Use local interfaces for the communication between proxy and target to speed up performance. Clean-up the target instance in the ejbRemove() of the proxy and use the same transaction and security settings for both proxy and target. Finally you get a proxy object that is a perfect surrogate for the target.
But what about the client, how does it know that it should call the proxy and not the target anymore? Well, this is the nice part: take as JNDI name for the ProxySessionBean the name from the target, and give this TargetSessionBean another name that the proxy can use. Or, if the client is an ejb, change the ejb-ref entry in the client.
Summarized, you have created a proxy to your target bean without changing the existing application!
-
Sessionbean Smart Reference (proxy) (14 messages)
- Posted by: Tim Pijpops
- Posted on: December 20 2001 18:13 EST
Threaded Messages (14)
- Sessionbean Smart Reference (proxy) by Tim Pijpops on December 20 2001 18:17 EST
- Sessionbean Smart Reference (proxy) by yi fe on December 21 2001 02:42 EST
-
Sessionbean Smart Reference (proxy) by Tim Pijpops on December 21 2001 03:30 EST
- Sessionbean Smart Reference (proxy) by Dimitri Rakitine on December 21 2001 09:46 EST
- Sessionbean Smart Reference (proxy) by Johan Eltes on January 06 2002 03:05 EST
-
Sessionbean Smart Reference (proxy) by Avi Abrami on January 15 2002 02:36 EST
- Sessionbean Smart Reference (proxy) by Tim Pijpops on January 15 2002 05:30 EST
- Sessionbean Smart Reference (proxy) by Dieter Cailliau on January 15 2002 06:09 EST
- Sessionbean Smart Reference (proxy) by Dieter Cailliau on January 15 2002 06:09 EST
- Sessionbean Smart Reference (proxy) by Dieter Cailliau on January 15 2002 06:09 EST
-
Sessionbean Smart Reference (proxy) by Tim Pijpops on December 21 2001 03:30 EST
- Sessionbean Smart Reference (proxy) by yi fe on December 21 2001 02:42 EST
- Sessionbean Smart Reference (proxy) by Pankaj Bansal on February 11 2002 08:42 EST
- Sessionbean Smart Reference (proxy) by Tim Pijpops on March 12 2002 08:13 EST
- Sessionbean Smart Reference (proxy) by fab trix on August 27 2002 06:52 EDT
- Sessionbean Smart Reference (proxy) by Tim Pijpops on March 12 2002 08:13 EST
- Sessionbean Smart Reference (proxy) by Web Master on September 28 2002 02:40 EDT
-
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Tim Pijpops
- Posted on: December 20 2001 18:17 EST
- in response to Tim Pijpops
Sorry guys, there was a small error in the code example. Obviously the methods in proxy and target should match exactly:
public Object execute(Object input)
{
//pre-processing here
Object result = targetSession.execute(input);
//post-processing here
return result;
}
-
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: yi fe
- Posted on: December 21 2001 02:42 EST
- in response to Tim Pijpops
No , it 's not necessary the proxy need match the target session , normal the articles metioned is the session Facade pattern ,which publish from sun blueprints ,it 's mainly advantage is reduce more remote call , just operate a proxy sessionbean who wraper some workflow EJBs method ,not only a sessionbean or entityBeans'.
you can read more in
http://java.sun.com/blueprints/patterns/j2ee_patterns/session_facade/index.html -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Tim Pijpops
- Posted on: December 21 2001 03:30 EST
- in response to yi fe
It's not the session facade. Main goal of this pattern is to add an 'invisible' proxy in front of a session bean. It's the J2EE version of the proxy pattern in the GoF book. Or, in some implementations, you probably could consider it as a decorator pattern (also GoF) too. Therefore it is very important that the proxy and the target implement exactly the same interface, otherwise it wouldn't be invisible for the client. -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Dimitri Rakitine
- Posted on: December 21 2001 21:46 EST
- in response to Tim Pijpops
Some while ago I needed this functionality - Here is a very simple example (for WebLogic 6.1) which does it transparently by replacing InitialContext factory. -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Johan Eltes
- Posted on: January 06 2002 15:05 EST
- in response to Tim Pijpops
I would say it is fairly close to the BusinessDelegate pattern of "Sun Core J2EE Patterns". If you use the BusinessDelegate, the implementaion could also serve as implementation for the "Sessionbean Smart Reference" pattern. -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Avi Abrami
- Posted on: January 15 2002 02:36 EST
- in response to Tim Pijpops
Pardon my ignorance, but I fail to see what this pattern
gives you! I see that it adds an extra layer. The client
still needs to do a "lookup" of the session bean. So instead
of directly looking up TargetSessionBean, the client looks
up ProxySessionBean that, in turn, looks up
TargetSessionBean. All right, ProxySessionBean can
communicate with TargetSessionBean via a local interface,
but let's face it, at this point in time, how many app
servers implement local EJB interfaces? (Contrary to popular
belief, WebLogic is _not_ the _only_ EJB container around!)
Please elighten me!
TIA,
Avi.
-
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Tim Pijpops
- Posted on: January 15 2002 05:30 EST
- in response to Avi Abrami
It gives you the same advantages as the proxy pattern from the GoF. It can act as a smart reference to intercept messages and act upon them. Moreover, you don't need to adapt neither the sending nor the receiving component. You just need to play with the JNDI names. Clearly this is useful when you don't have the source code of sender or receiver. -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Dieter Cailliau
- Posted on: January 15 2002 06:09 EST
- in response to Avi Abrami
i have discovered a very interesting thing usefull for decorator: dynamic proxies.
A dynamic proxy is an objects that implements an interface specified at runtime!
Thus in stead of duplicating the bean and calling the one from the other, i have a (java interface) and an (implementation class). The beans remote interface extends the (java interface), the bean implementation is wrapper code : forward methods to the (implementation class).
If i need "generic" pre/post processing (i mean: for each method the same pre/post processing) (like debugging: "this method was called...") i put a dynamic proxy in between the bean and it's implementation. Thus the bean forwards to the dynami proxy, and the proxy to my original implementation.
The interesting thing about dynamic proxy is that you have one method which is called for every method in the interface. You don't have to change it when your interface grows or changes... -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Dieter Cailliau
- Posted on: January 15 2002 06:09 EST
- in response to Avi Abrami
i have discovered a very interesting thing usefull for decorator: dynamic proxies.
A dynamic proxy is an objects that implements an interface specified at runtime!
Thus in stead of duplicating the bean and calling the one from the other, i have a (java interface) and an (implementation class). The beans remote interface extends the (java interface), the bean implementation is wrapper code : forward methods to the (implementation class).
If i need "generic" pre/post processing (i mean: for each method the same pre/post processing) (like debugging: "this method was called...") i put a dynamic proxy in between the bean and it's implementation. Thus the bean forwards to the dynami proxy, and the proxy to my original implementation.
The interesting thing about dynamic proxy is that you have one method which is called for every method in the interface. You don't have to change it when your interface grows or changes... -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Dieter Cailliau
- Posted on: January 15 2002 06:09 EST
- in response to Avi Abrami
i have discovered a very interesting thing usefull for decorator: dynamic proxies.
A dynamic proxy is an objects that implements an interface specified at runtime!
Thus in stead of duplicating the bean and calling the one from the other, i have a (java interface) and an (implementation class). The beans remote interface extends the (java interface), the bean implementation is wrapper code : forward methods to the (implementation class).
If i need "generic" pre/post processing (i mean: for each method the same pre/post processing) (like debugging: "this method was called...") i put a dynamic proxy in between the bean and it's implementation. Thus the bean forwards to the dynami proxy, and the proxy to my original implementation.
The interesting thing about dynamic proxy is that you have one method which is called for every method in the interface. You don't have to change it when your interface grows or changes... -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Pankaj Bansal
- Posted on: February 11 2002 08:42 EST
- in response to Tim Pijpops
Pardon my ignorance, but I fail to see what this pattern
gives you! I see that it adds an extra layer. The client
still needs to do a "lookup" of the session bean. So instead
of directly looking up TargetSessionBean, the client looks
up ProxySessionBean that, in turn, looks up
TargetSessionBean. All right, ProxySessionBean can
communicate with TargetSessionBean via a local interface but to what advantage, the client has to make a remote call to the proxy bean..
in case I have wrongly interpretted the pattern kindly let me know..but please elaborate..
Pankaj
email :
[email protected] -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Tim Pijpops
- Posted on: March 12 2002 08:13 EST
- in response to Pankaj Bansal
First of all: the client doesn't have to make a remote call to the proxy, it can be a local call as well if it is a local client. The main advantage of the pattern is that you can place a proxy in between of a session bean, without rewriting the caller's code. This is particulary usefull in existing applications, where you don't have the source code. In the datamining world for instance, where I work, one often needs to capture the communication between existing components, without changing them. This can be accomplished using this pattern. -
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: fab trix
- Posted on: August 27 2002 06:52 EDT
- in response to Tim Pijpops
It's work....Tim, now try to imagine and help me:
if you pass to the proxy
1- the local JNDI name
2- the method to call
3- a List of the parameters
with a little effort and introspection we can realize an SSLProxyBean object that completely uncouples the client from the interface of every SSL bean other than this ProxyBean.
Right??!!
-
Sessionbean Smart Reference (proxy)[ Go to top ]
- Posted by: Web Master
- Posted on: September 28 2002 02:40 EDT
- in response to Tim Pijpops
Could someone please point me to an example of using this pattern (or one similar) for auditing (audit trail creation or simple logging) purposes?
Thanks
- Chris