Interceptors  Locate

Interceptors can monitor or modify the requests and responses of Oracle Service Registry as shown in Figure 9. They are at the lowest level of Oracle Service Registry API call processing, and can be used for:

Figure 9. Registry Interceptors

Registry Interceptors

There are three types of Oracle Service Registry interceptor:

If you want to directly access the Oracle Service Registry API see Accessing Registry APIs for more information.

Creating and Deploying Interceptors  Locate

To create an Interceptor, follow these steps:

  1. Write a class that implements the org.systinet.uddi.interceptor interface.

  2. Copy your interceptor implementation class to the directory REGISTRY_HOME/app/uddi/services/Wasp-inf/classes.

  3. Create a configuration file for your interceptor in the REGISTRY_HOME/app/uddi/conf directory. See Interceptor Configuration.

  4. Shutdown Oracle Service Registry, delete the REGISTRY_HOME/work directory, and restart the registry.

Logging Interceptor Sample  Locate

This section includes step-by-step instructions how to create the interceptor that logs requests.

To create a logging interceptor:

  1. Create Java file LoggingInterceptor.java as shown in Example 8.

  2. Compile the interceptor using Java -classpath "%REGISTRY_HOME%\app\uddi\services\Wasp-inf\lib\application_core.jar; %REGISTRY_HOME%\lib\wasp.jar" LoggingInterceptor.java

  3. Copy LoggingInterceptor.class to the REGISTRY_HOME/app/uddi/services/Wasp-inf/classes/interceptor directory.

  4. Create the configuration file Myinterceptor.xml in REGISTRY_HOME/app/uddi/conf folder. For details, please see Example 9.

  5. Shutdown Oracle Service Registry, delete the REGISTRY_HOME/work directory, and restart the registry.

Example 8. Logging Interceptor Class

package interceptor;

import org.idoox.config.Configurable;
import org.idoox.wasp.WaspInternalException;
import org.idoox.wasp.interceptor.InterceptorChain;
import org.systinet.uddi.interceptor.ExceptionInterceptor;
import org.systinet.uddi.interceptor.RequestInterceptor;
import org.systinet.uddi.interceptor.ResponseInterceptor;
import org.systinet.uddi.interceptor.StopProcessingException;
import java.lang.reflect.Method;


public class LoggingInterceptor implements RequestInterceptor, 
                     ResponseInterceptor, ExceptionInterceptor {

    public void load(Configurable config) 
        throws WaspInternalException { 
        // no initialization required
    }

    public void destroy() {
        // no destroy required
    }

    public void intercept(Method method,
                          Object[] args,
                          InterceptorChain chain,
                          int position)
        throws StopProcessingException, Exception {
        System.out.println("request: " + method.getName());
    }

    public Object intercept(Method method,
                            Object returnValue,
                            InterceptorChain chain,
                            int position)
        throws Exception {
        System.out.println("response: " + method.getName());
        return returnValue;
    }

    public Exception intercept(Method method,
                               Exception e,
                               InterceptorChain chain,
                               int position) {
        System.out.println("exception: " + method.getName());
        return e;
    }
}

Example 9. Logging Interceptor Configuration File

<?xml version="1.0" encoding="UTF-8"?>
<config name="MyInterceptorConfig">
  <UDDIInterceptorInstance name="LoggingInterceptorInstance"
    instancePerCall="false"
    className="interceptor.LoggingInterceptor"/>  
  <UDDIInterceptor name="LoggingInterceptor"
    instanceName="LoggingInterceptorInstance"
    interceptorChain="inquiry_v3"
    request="true"
    response="true"
    fault="true" />
</config>
Interceptor Configuration  Locate

The configuration file must be present in the REGISTRY_HOME/app/uddi/conf directory. For details please see Example 9. Interceptors are called in the same order as they appear in the configuration file.

  • config name - the unique (unambiguous) name of the configuration.

  • UDDIInterceptorInstance - contains information about the implementation class and its instantiation.

    • name - The name of interceptor instance. This name is used as a link to the UDDIInterceptor/instanceName section of the configuration.

    • instancePerCall - If the instancePerCall attribute is set to true, then the class will be instantiated once per API call. Otherwise, this interceptor instantiates only once for all calls.

    • className - name of the class that implements the interceptor.

  • UDDIInterceptor - The UDDIInterceptor contains references to UDDI Interceptors and their types.

    • name - name of the interceptor.

    • instanceName - this attribute contains the name of the UDDIInterceptorInstance section of the configuration file.

    • interceptorChain - UDDIInterceptorChains are defined for each API in their configuration files. This attribute contains a reference to the required API.

    • request - when set true, the interceptor catches requests.

    • response - when set true, the interceptor catches responses.

    • fault - when set true, the interceptor catches faults.

Request Counter Interceptor Sample  Locate

In this section, we will create an interceptor that counts requests and stores the number of request to a configuration file. The steps required to create a Request Counter Interceptor are the same as those in the Logging Interceptor Sample.

Interceptor implementation is shown in Example 10; the configuration file is shown in Example 11.

Example 10. Request Counter Interceptor Class

package interceptor;

import org.idoox.config.Configurable;
import org.idoox.wasp.WaspInternalException;
import org.idoox.wasp.interceptor.InterceptorChain;
import org.systinet.uddi.interceptor.RequestInterceptor;
import org.systinet.uddi.interceptor.StopProcessingException;
import java.lang.reflect.Method;

public class RequestCounterInterceptor implements RequestInterceptor {

    private long request = 0;
    private RequestCounterInterceptorConfig.Counter counter;

    /**
    * RequestCounterInterceptor config interface
    */
    interface RequestCounterInterceptorConfig {
        public Counter getCounter();
        public void setCounter(Counter counter);
        public Counter newCounter();
        interface Counter {
            public long getRequest();
            public void setRequest(long request);
        }
    }
    public void intercept(Method method,
                          Object[] args,
                          InterceptorChain chain,
                          int position)
        throws StopProcessingException, Exception {
        counter.setRequest(++request);
        System.out.println("request: " + request);
    }

    public void load(Configurable config)
        throws WaspInternalException {
        RequestCounterInterceptorConfig intinterceptorConfig = 
                          (RequestCounterInterceptorConfig) 
                           config.narrow(RequestCounterInterceptorConfig.class);
        if (intinterceptorConfig != null) {
            counter = intinterceptorConfig.getCounter();
            if (counter == null) {
                counter = intinterceptorConfig.newCounter();
                intinterceptorConfig.setCounter(counter);
            }
            try {
                request = counter.getRequest();
            } catch (Exception e) {
            counter.setRequest(0);
            }
        }
    }

    /**
    * Destroys the interceptor.
    */
    public void destroy() {
        // no destroy required
    }
}

Example 11. Request Counter Interceptor Configuration File

<?xml version="1.0" encoding="UTF-8"?>
<config name="myInterceptors">
    <UDDIInterceptorInstance className="interceptor.RequestCounterInterceptor"
        instancePerCall="false" name="RequestCounterInterceptorSampleInstance">
    </UDDIInterceptorInstance>
    <UDDIInterceptor fault="false"
        instanceName="RequestCounterInterceptorSampleInstance"
        interceptorChain="inquiry_v3" name="RequestCounter" request="true"
        response="false"/>
</config>