Hi,
yeah, if Guice doesn't create the instance than there is no way to get
in the interceptors.
One way I can think of without using any hacks is to put in some
delegates like in your case you'd have:
interface IReportingServiceDelegate extends IReportingService
class IReportingServiceDelegateImpl implements
IReportingServiceDelegate{
private final IReportingService delegate;
@Inject
// will use your own class created by custom factory but this class
will be Guice created so interceptors will work
public IReportingServiceDelegateImpl(IReportingService delegate){
this.delegate = delegate;
}
@LogMe
public void someMethod(){
delegate.someMethod();
}
...
}
and then use the delegate instead of the original. It is a bit more
visual noise. Most IDEs know how to make delegates automatically.
It should be possible to make the delegates automatically behind the
curtains with some CG magic.
Your solution is independent of bindInterceptor;)
HTH,
Alen
On Mar 20, 9:24 pm, Richard Hauswald <
richard.hausw...@googlemail.com>
wrote:
> I did a dirty hack... it enables me to somehow, in a very dirty way,
> apply java proxies to instances created by guice and providers. I
> attached the solutions classes. Here is how it works:
> bind(MyService.class).annotatedWith(Names.named("intercept")).to(MyServiceImpl.class);
> bind(MyService.class).toProvider(new
> ProxyBindingProvider<MyService>(Key.get(MyService.class,
> Names.named("intercept")),CallTimeProxy.class));
>
> I'd be glad if somebody would be so kind to give it short look and
> maybe write his/her thoughts.
> Thanks,
> Richard
>
> 2009/3/20 Richard <
Richard.Hausw...@googlemail.com>:
>
>
>
> > Hello,
> > this way i have to create my webservice client:
> > private static class ReportingServiceProvider implements
> > Provider<IReportingService> {
> > @Inject
> > @Named("webservices.properties.ReportingService")
> > private String url;
>
> > public IReportingService get() {
> > HessianProxyFactory factory = new HessianProxyFactory();
> > factory.setHessian2Reply(true);
> > factory.setHessian2Request(true);
> > try {
> > return (IReportingService) factory.create(IReportingService.class,
> > url);
> > } catch (MalformedURLException e) {
> > throw new RuntimeException(
> > e);
> > }
> > }
> > }
>
> > Now I want to bind an Interceptor to it:
> > bindInterceptor(Matchers.subclassesOf(IReportingService.class),
> > Matchers.any(), new CallTimeInterceptor());
>
> > But this is not working. I remember a new group entry saying that
> > guice only installs interceptors to objects it creates. Any ideas how
> > to work around this problem?
>
>
>
> RawTypeExtractor.java
> < 1KViewDownload
>
> ProxyBindingProvider.java
> 2KViewDownload
>
> ProxyBindingProviderTest.java
> 3KViewDownload