LibraryToggle FramesPrintFeedback

Example 5.4 shows code for attaching an interceptor to the inbound interceptor chain of a JAX-WS consumer.

Example 5.4. Attaching an interceptor to a consumer programmatically

package com.fusesource.demo; 

import java.io.File; 
import java.net.URL; 
import javax.xml.namespace.QName; 
import javax.xml.ws.Service; 

import org.apache.cxf.endpoint.ClientProxy;
import org.apache.cxf.endpoint.ClientProxy;

public class Client 
{ 
  public static void main(String args[]) 
  { 
    QName serviceName = new QName("http://demo.eric.org", "stockQuoteReporter"); 
    Service s = Service.create(serviceName); 1

    QName portName = new QName("http://demo.eric.org", "stockQuoteReporterPort"); 
    s.addPort(portName, "http://schemas.xmlsoap.org/soap/", "http://localhost:9000/EricStockQuote"); 2
 
    quoteReporter proxy = s.getPort(portName, quoteReporter.class); 3

    Client cxfClient = ClientProxy.getClient(proxy); 4

    ValidateInterceptor validInterceptor = new ValidateInterceptor(); 5
    cxfClient.getInInterceptor().add(validInterceptor); 6

    ...
  } 
}

The code in Example 5.4 does the following:

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 Fuse Services Framework Client object associated with the proxy.

5

Creates an instance of the interceptor.

6

Attaches the interceptor to the inbound interceptor chain.

Example 5.5 shows code for attaching an interceptor to a service provider's outbound interceptor chain.


The code in Example 5.5 does the following:

1

Creates a ServerFactoryBean object that will provide access to the underlying Fuse Services Framework objects.

2

Gets the Server object that Fuse Services Framework uses to represent the endpoint.

3

Gets the Fuse Services Framework EndpointImpl object for the service provider.

4

Creates an instance of the interceptor.

5

Attaches the interceptor to the endpoint;s outbound interceptor chain.

Example 5.6 shows code for attaching an interceptor to a bus' inbound interceptor chain.

Example 5.6. Attaching an interceptor to a bus

import org.apache.cxf.BusFactory;
org.apache.cxf.Bus;

...

Bus bus = BusFactory.getDefaultBus(); 1

WatchInterceptor watchInterceptor = new WatchInterceptor(); 2

bus..getInInterceptor().add(watchInterceptor); 3

...

The code in Example 5.6 does the following:

1

Gets the default bus for the runtime instance.

2

Creates an instance of the interceptor.

3

Attaches the interceptor to the inbound interceptor chain.

The WatchInterceptor will be attached to the inbound interceptor chain of all endpoints created by the runtime instance.

Comments powered by Disqus