Return-Path: Delivered-To: apmail-incubator-cxf-dev-archive@locus.apache.org Received: (qmail 32155 invoked from network); 21 Mar 2007 08:12:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Mar 2007 08:12:10 -0000 Received: (qmail 894 invoked by uid 500); 21 Mar 2007 08:12:18 -0000 Delivered-To: apmail-incubator-cxf-dev-archive@incubator.apache.org Received: (qmail 730 invoked by uid 500); 21 Mar 2007 08:12:18 -0000 Mailing-List: contact cxf-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-dev@incubator.apache.org Received: (qmail 716 invoked by uid 99); 21 Mar 2007 08:12:18 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Mar 2007 01:12:18 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of andrea.smyth@iona.com designates 62.221.12.33 as permitted sender) Received: from [62.221.12.33] (HELO emea-smg1.iona.com) (62.221.12.33) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Mar 2007 01:12:09 -0700 Received: from emea-ems1.ionaglobal.com (dutec.ie [10.2.1.125]) by emea-smg1.iona.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id l2L98gOq006241; Wed, 21 Mar 2007 09:08:42 GMT Received: from [10.5.2.195] ([10.5.2.195]) by emea-ems1.ionaglobal.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 21 Mar 2007 08:11:47 +0000 Message-ID: <4600E891.60009@iona.com> Date: Wed, 21 Mar 2007 08:10:57 +0000 From: Andrea Smyth User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: cxf-dev@incubator.apache.org CC: cxf-user@incubator.apache.org Subject: Re: Programatically installing interceptors per (Bus|Service|Endpoint) References: <9D30D376-CC2B-44FC-944E-0FE0AD7AAF71@dushin.net> In-Reply-To: <9D30D376-CC2B-44FC-944E-0FE0AD7AAF71@dushin.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 21 Mar 2007 08:11:47.0844 (UTC) FILETIME=[925DEC40:01C76B90] X-Virus-Checked: Checked by ClamAV on apache.org Fred Dushin wrote: > I understand that CXF provides APIs for installed interceptors > through the InterceptorProvider interface, which the Bus, Endpoint, > and Service types all extend (among other types). > > Suppose I want to create, via configuration, some sort of CXF plugin > (I hesitate to call this an interceptor, for reasons which should > become obvious). The purpose of this plugin is to install > interceptors programatically into the call chain. > > I can see how to do this using a reference to a Bus -- e.g., I can > spring-load the plugin I want to install, and wire it up to the Bus > -- common pattern. And from there, I can get access to the Bus-level > InterceptorProvider, since the Bus extends that type. > > That would work in the case where I want my plugin to install these > interceptors globally, i.e, for all services and endpoints in a Bus; > however, suppose I want to install my interceptors at a finer level > of granularity, e.g., per endpoint. Is there a way for my plugin, > which seems to be loaded at Bus initialization time, to get a handle > on the Service or Endpoint (which also implement InterceptorProvider) > for which it is (or counterfactually would be) configured? Is this > an envisioned pattern? Or is there some other sort of interceptor I > don't know of, e.g, which hooks into Service or Endpoint creation? > > Thanks! > -Fred Hi Fred, On the client side you can manage interceptors at the client, endpoint, service and bus level. If you have created your proxy using JAXWS APIs, you need to first obtain a reference to the underlying CXF client object as follows: BasicGreeterService gs = new BasicGreeterService(); Greeter greeter = gs.getGreeterPort(); org.apache.cxf.endpoint.Client client = org.apache.cxf.frontend.ClientProxy.getClient(greeter); client.getOutInterceptors().add(...); org.apache.cxf.endpoint.Endpoint endpoint = client.getEndpoint(); endpoint.getOutInterceptors().add(...); org.apache.cxf.service.Service service = endpoint.getService(); service.getOutInterceptors().add(...); On the server side, if you use the JAXWS API, cast the javax.xml.ws.Endpoint object you obtained from publish to get access to its underlying CXF endpoint. Note that Server - unlike Client - is not an interceptor provider, which is a bit asymmetric. javax.xml.ws.Endpoint jaxwsEndpoint = javax.xml.ws.Endpoint.publish("http://localhost:9020/SoapContext/GreeterPort", new GreeterImpl();); LoggingOutInterceptor out = new LoggingOutInterceptor(); org.apache.cxf.jaxws.EndpointImpl jaxwsEndpointImpl = (org.apache.cxf.jaxws.EndpointImpl)endpoint; org.apache.cxf.endpoint.Server server = jaxwsEndpointImpl.getServer(); org.apache.cxf.endpoint.Endpoint endpoint = server.getEndpoint(); endpoint.getOutInterceptors().add(...); org.apache.cxf.service.Service service = endpoint.getService(); service.getOutInterceptors().add(...); You can also have an interceptor installed at bus level which, when executing, adds further interceptors to the chain, possibly on a per message basis. This is done for example in org.apache.cxf.ws.policy.ClientPolicyOutInterceptor. Cheers, Andrea.