Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.56.3. Adding interceptors programmatically
- the
InterceptorProvider
API - Java annotations
InterceptorProvider
API allows the developer to attach interceptors to any of the runtime components that have interceptor chains, but it requires working with the underlying Apache CXF classes. The Java annotations can only be added to service interfaces or service implementations, but they allow developers to stay within the JAX-WS API or the JAX-RS API.
56.3.1. Using the interceptor provider API Copy linkLink copied to clipboard!
Overview Copy linkLink copied to clipboard!
InterceptorProvider
interface shown in Example 56.3, “The interceptor provider interface”.
Example 56.3. The interceptor provider interface
List
object. Using the methods offered by the Java List
object, developers can add and remove interceptors to any of the chains.
Procedure Copy linkLink copied to clipboard!
InterceptorProvider
API to attach an interceptor to a runtime component's interceptor chain, you must:
- Get access to the runtime component with the chain to which the interceptor is being attached.Developers must use Apache CXF specific APIs to access the runtime components from standard Java application code. The runtime components are usually accessible by casting the JAX-WS or JAX-RS artifacts into the underlying Apache CXF objects.
- Create an instance of the interceptor.
- Use the proper get method to retrieve the desired interceptor chain.
- Use the
List
object'sadd()
method to attach the interceptor to the interceptor chain.TipThis step is usually combined with retrieving the interceptor chain.
Attaching an interceptor to a consumer Copy linkLink copied to clipboard!
Example 56.4. Attaching an interceptor to a consumer programmatically
- 1
- Creates a JAX-WS
Service
object for the consumer. - 2
- Adds a port to the
Service
object that provides the consumer's target address. - 3
- Creates the proxy used to invoke methods on the service provider.
- 4
- Gets the Apache CXF
Client
object associated with the proxy. - 5
- Creates an instance of the interceptor.
- 6
- Attaches the interceptor to the inbound interceptor chain.
Attaching an interceptor to a service provider Copy linkLink copied to clipboard!
Example 56.5. Attaching an interceptor to a service provider programmatically
- 1
- Creates a
ServerFactoryBean
object that will provide access to the underlying Apache CXF objects. - 2
- Gets the
Server
object that Apache CXF uses to represent the endpoint. - 3
- Gets the Apache CXF
EndpointImpl
object for the service provider. - 4
- Creates an instance of the interceptor.
- 5
- Attaches the interceptor to the endpoint;s outbound interceptor chain.
Attaching an interceptor to a bus Copy linkLink copied to clipboard!
Example 56.6. Attaching an interceptor to a bus
WatchInterceptor
will be attached to the inbound interceptor chain of all endpoints created by the runtime instance.
56.3.2. Using Java annotations Copy linkLink copied to clipboard!
Overview Copy linkLink copied to clipboard!
Where to place the annotations Copy linkLink copied to clipboard!
- the service endpoint interface(SEI) defining the endpointIf the annotations are placed on an SEI, all of the service providers that implement the interface and all of the consumers that use the SEI to create proxies will be affected.
- a service implementation classIf the annotations are placed on an implementation class, all of the service providers using the implementation class will be affected.
The annotations Copy linkLink copied to clipboard!
Listing the interceptors Copy linkLink copied to clipboard!
Example 56.7. Syntax for listing interceptors in a chain annotation
interceptors={"interceptor1", "interceptor2", ..., "interceptorN"}
interceptors={"interceptor1", "interceptor2", ..., "interceptorN"}
Example Copy linkLink copied to clipboard!
SayHiImpl
.
Example 56.8. Attaching interceptors to a service implementation