org.systinet.wasp.webservice
Interface Interceptors


public interface Interceptors

This interface represents the chain of the transport interceptors either for the service endpoint or for the client.

Interceptors are at the lowest level of message processing. They accept a transport messages as their input, can modify it and return a transport message as an output. This level has no notion about XML or higher level protocols, so it is able to, for example, convert non-XML protocols into XML protocols and vice versa. For instance, you can use interceptors for dumping messages into the console, computing message statistics (such as average message length), performing authentication, transforming the incoming message via XSLT etc.

In WSO2 SOA Enablement Server, all interceptors must implement the TransportInterceptor interface. The interceptor implementation can use CallContext (which can be obtained via Current.getCallContext()) for passing data to the service instance or from the client and vice versa.

The following code snippet shows how to insert a transport interceptor at the client-side:

  ServiceClient serviceClient = ServiceClient.create("http://localhost:6060/MyService", MyService.class);
  serviceClient.getInterceptors().insert(new MyInterceptor(), Interceptors.DIRECTION_INOUT);
 

And the following code snippet shows how to insert a transport interceptor at the server-side:

  ServiceEndpoint endpoint = Registry.publish("/MyService", new MyService());
  endpoint.getInterceptors().insert(new MyInterceptor(), Interceptors.DIRECTION_INOUT);
 

Since:
4.5
Component:
Core

Field Summary
static int DIRECTION_IN
          Constant value representing interceptor is used for incoming message.
static int DIRECTION_INOUT
          Constant value representing interceptor is used both for incoming and outgoing message.
static int DIRECTION_OUT
          Constant value representing interceptor is used for outgoing message.
static int POSITION_FIRST
          Constant value representing the first position in the chain.
static int POSITION_LAST
          Constant value representing the last position in the chain.
 
Method Summary
 Interceptor get(int position)
          Returns an interceptor at the specified position within the chain of transport interceptors.
 int getDirection(int position)
          Returns a communication direction of the interceptor residing at the specified position within the chain of the transport interceptors.
 void insert(Interceptor instance, int direction)
          Inserts an interceptor to the end of the chain of the transport interceptors.
 void insert(int position, Interceptor instance, int direction)
          Inserts an interceptor to the specified position in the chain of the transport interceptors.
 void remove(int position)
          Removes a interceptor at the specified position in the chain of the transport interceptors.
 boolean remove(Interceptor instance)
          Removes all occurrences of the given interceptor's instance from the chain of the transport interceptors.
 void setDirection(int position, int direction)
          Sets a communication direction of the interceptor residing at the specified position within the chain of the transport interceptors.
 int size()
          Returns the size (number of interceptors) of the chain of the transport interceptors.
 

Field Detail

DIRECTION_IN

public static final int DIRECTION_IN
Constant value representing interceptor is used for incoming message.

See Also:
Constant Field Values

DIRECTION_OUT

public static final int DIRECTION_OUT
Constant value representing interceptor is used for outgoing message.

See Also:
Constant Field Values

DIRECTION_INOUT

public static final int DIRECTION_INOUT
Constant value representing interceptor is used both for incoming and outgoing message. It is declared as DIRECTION_INOUT = DIRECTION_IN | DIRECTION_OUT.

See Also:
Constant Field Values

POSITION_FIRST

public static final int POSITION_FIRST
Constant value representing the first position in the chain.

See Also:
Constant Field Values

POSITION_LAST

public static final int POSITION_LAST
Constant value representing the last position in the chain.

See Also:
Constant Field Values
Method Detail

get

public Interceptor get(int position)
                throws java.lang.IndexOutOfBoundsException
Returns an interceptor at the specified position within the chain of transport interceptors.

Parameters:
position - interceptor's index within the chain
Returns:
reference to the interceptor at the specified position
Throws:
java.lang.IndexOutOfBoundsException - if position is if out of range (position < 0 || position => size())

getDirection

public int getDirection(int position)
                 throws java.lang.IndexOutOfBoundsException

Returns a communication direction of the interceptor residing at the specified position within the chain of the transport interceptors.

The direction is one of DIRECTION_IN, DIRECTION_OUT, DIRECTION_INOUT. These directions depend on which end of the service they are viewed from: a interceptor that is "in" according to ServiceEndpoint is "out" according to ServiceClient, and vice-versa.

Parameters:
position - specifies the interceptor's position within the chain
Returns:
status of the interceptor's direction
Throws:
java.lang.IndexOutOfBoundsException - if position is if out of range (position < 0 || position => size())

setDirection

public void setDirection(int position,
                         int direction)
                  throws java.lang.IndexOutOfBoundsException
Sets a communication direction of the interceptor residing at the specified position within the chain of the transport interceptors. The direction is be one of DIRECTION_IN, DIRECTION_OUT, DIRECTION_INOUT.

Parameters:
position - specifies the interceptor's position within the chain
direction - interceptor's direction (see DIRECTION_IN, DIRECTION_OUT, DIRECTION_INOUT)
Throws:
java.lang.IllegalArgumentException - when such direction does not exist
java.lang.IndexOutOfBoundsException - if position is if out of range (position < 0 || position => size())

insert

public void insert(int position,
                   Interceptor instance,
                   int direction)
            throws java.lang.IndexOutOfBoundsException
Inserts an interceptor to the specified position in the chain of the transport interceptors.

Parameters:
position - interceptor's index within the chain, constants POSITION_FIRST, POSITION_LAST can be used
instance - interceptor to be inserted
direction - interceptor's direction (see DIRECTION_IN, DIRECTION_OUT, DIRECTION_INOUT)
Throws:
java.lang.IllegalArgumentException - when such direction does not exist
java.lang.IndexOutOfBoundsException - if position is if out of range (position < 0 || position > size())

insert

public void insert(Interceptor instance,
                   int direction)
Inserts an interceptor to the end of the chain of the transport interceptors.

Parameters:
instance - interceptor to be inserted
direction - interceptor's direction (see DIRECTION_IN, DIRECTION_OUT, DIRECTION_INOUT)
Throws:
java.lang.IllegalArgumentException - when such direction does not exist

remove

public void remove(int position)
            throws java.lang.IndexOutOfBoundsException
Removes a interceptor at the specified position in the chain of the transport interceptors.

Parameters:
position - position in the interceptor chain
Throws:
java.lang.IndexOutOfBoundsException - if position is if out of range (position < 0 || position => size())

size

public int size()
Returns the size (number of interceptors) of the chain of the transport interceptors.

Returns:
number of interceptors within the chain

remove

public boolean remove(Interceptor instance)
Removes all occurrences of the given interceptor's instance from the chain of the transport interceptors.

Parameters:
instance - instance of the interceptor to be removed
Returns:
true if the transport interceptors chain contained the specified element