You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Lucas Madar <ma...@samsix.com> on 2010/11/19 20:00:23 UTC
Accessing the web service implementation class from an interceptor
I need to access the web service implementation class from an
interceptor to see if it has a particular custom annotation on it. How
do I find out the class of the service implementation from an
interceptor? Since I only need to read the annotation from the class
itself, in this case I don't need the instance, just the class.
However, in another case, I would like to be able to inject something
into the class in an interceptor (this isn't as important, though). Is
it possible to get access to the class instance as well?
Thanks,
Lucas Madar
Re: Accessing the web service implementation class from an interceptor
Posted by Daniel Kulp <dk...@apache.org>.
On Friday 19 November 2010 2:00:23 pm Lucas Madar wrote:
> I need to access the web service implementation class from an
> interceptor to see if it has a particular custom annotation on it. How
> do I find out the class of the service implementation from an
> interceptor? Since I only need to read the annotation from the class
> itself, in this case I don't need the instance, just the class.
>
If the interceptor runs fairly late in the chain (like the USER_LOGICAL
phase), you should be able to do something like:
Exchange exchange = msg.getExchange();
BindingOperationInfo bop = exchange.get(BindingOperationInfo.class);
MethodDispatcher md = (MethodDispatcher)
exchange.get(Service.class).get(MethodDispatcher.class.getName());
That should give you the Method that was bound in so you can get the declared
class or the annotations, etc...
> However, in another case, I would like to be able to inject something
> into the class in an interceptor (this isn't as important, though). Is
> it possible to get access to the class instance as well?
With the "default" things, you could do something like:
Endpoint endpoint = exchange.get(Endpoint.class);
Service service = endpoint.getService();
Invoker invoker = service.getInvoker();
((FactoryInvoker)invoker).getServiceObject(exchange);
to get the object. That really will only work if you're dealing with a
singleton though. (which is the default) If you configure in some other
factory (like to use a pool or per-request), then this really won't work. In
that case, you would need to not use an interceptor. Instead, you would need
to subclass the JAXWSMethodInvoker and override the invoke method to muck
with the object right before it invokes the method.
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog