A PhaseInterceptorChain orders Interceptors according to the phase they
participate in and also according to the before & after properties on an
Interceptor.
A List of phases is supplied to the PhaseInterceptorChain in the constructor.
This class is typically instantiated from the PhaseChainCache class in this
package. Interceptors that are added to the chain are ordered by phase.
Within a phase, interceptors can order themselves. Each PhaseInterceptor
has an ID. PhaseInterceptors can supply a Collection of IDs which they
should run before or after, supplying fine grained ordering.
| Method from org.apache.cxf.phase.PhaseInterceptorChain Detail: |
public synchronized void abort() {
this.state = InterceptorChain.State.ABORTED;
}
|
public void add(Collection newhandlers) {
add(newhandlers, false);
}
|
public void add(Interceptor i) {
add(i, false);
}
|
public void add(Collection newhandlers,
boolean force) {
if (newhandlers == null) {
return;
}
for (Interceptor handler : newhandlers) {
add(handler, force);
}
}
|
public void add(Interceptor i,
boolean force) {
PhaseInterceptor pi = (PhaseInterceptor)i;
String phaseName = pi.getPhase();
Integer phase = nameMap.get(phaseName);
if (phase == null) {
LOG.fine("Skipping interceptor " + i.getClass().getName()
+ ((phaseName == null) ? ": Phase declaration is missing."
: ": Phase " + phaseName + " specified does not exist."));
} else {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Adding interceptor " + i + " to phase " + phaseName);
}
insertInterceptor(phase, pi, force);
}
}
|
public PhaseInterceptorChain cloneChain() {
return new PhaseInterceptorChain(this);
}
|
public synchronized boolean doIntercept(Message message) {
updateIterator();
pausedMessage = message;
while (state == State.EXECUTING && iterator.hasNext()) {
try {
Interceptor currentInterceptor = iterator.next();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Invoking handleMessage on interceptor " + currentInterceptor);
}
//System.out.println("-----------" + currentInterceptor);
currentInterceptor.handleMessage(message);
} catch (RuntimeException ex) {
if (!faultOccurred) {
faultOccurred = true;
FaultMode mode = message.get(FaultMode.class);
if (mode == FaultMode.CHECKED_APPLICATION_FAULT) {
if (LOG.isLoggable(Level.FINE)) {
LogUtils.log(LOG, Level.FINE,
"Application has thrown exception, unwinding now", ex);
} else if (LOG.isLoggable(Level.INFO)) {
Throwable t = ex;
if (ex instanceof Fault
&& ex.getCause() != null) {
t = ex.getCause();
}
LogUtils.log(LOG, Level.INFO,
"Application has thrown exception, unwinding now: "
+ t.getClass().getName()
+ ": " + ex.getMessage());
}
} else if (LOG.isLoggable(Level.INFO)) {
if (mode == FaultMode.UNCHECKED_APPLICATION_FAULT) {
LogUtils.log(LOG, Level.INFO,
"Application has thrown exception, unwinding now", ex);
} else {
LogUtils.log(LOG, Level.INFO,
"Interceptor has thrown exception, unwinding now", ex);
}
}
message.setContent(Exception.class, ex);
if (message.getExchange() != null) {
message.getExchange().put(Exception.class, ex);
}
unwind(message);
if (faultObserver != null) {
faultObserver.onMessage(message);
}
}
state = State.ABORTED;
}
}
if (state == State.EXECUTING) {
state = State.COMPLETE;
}
return state == State.COMPLETE;
}
Intercept a message, invoking each phase's handlers in turn. |
public synchronized boolean doInterceptStartingAfter(Message message,
String startingAfterInterceptorID) {
updateIterator();
while (state == State.EXECUTING && iterator.hasNext()) {
PhaseInterceptor currentInterceptor = (PhaseInterceptor)iterator.next();
if (currentInterceptor.getId().equals(startingAfterInterceptorID)) {
break;
}
}
return doIntercept(message);
}
Intercept a message, invoking each phase's handlers in turn,
starting after the specified interceptor. |
public synchronized boolean doInterceptStartingAt(Message message,
String startingAtInterceptorID) {
updateIterator();
while (state == State.EXECUTING && iterator.hasNext()) {
PhaseInterceptor currentInterceptor = (PhaseInterceptor)iterator.next();
if (currentInterceptor.getId().equals(startingAtInterceptorID)) {
iterator.previous();
break;
}
}
return doIntercept(message);
}
Intercept a message, invoking each phase's handlers in turn,
starting at the specified interceptor. |
public MessageObserver getFaultObserver() {
return faultObserver;
}
|
public ListIterator getIterator() {
return new PhaseInterceptorIterator(heads);
}
|
public Iterator iterator() {
return getIterator();
}
|
public synchronized void pause() {
state = State.PAUSED;
}
|
public void remove(Interceptor i) {
PhaseInterceptorIterator it = new PhaseInterceptorIterator(heads);
while (it.hasNext()) {
InterceptorHolder holder = it.nextInterceptorHolder();
if (holder.interceptor == i) {
remove(holder);
return;
}
}
}
|
public synchronized void reset() {
updateIterator();
if (state == State.COMPLETE) {
state = State.EXECUTING;
iterator.reset();
} else {
iterator.reset();
}
}
|
public synchronized void resume() {
if (state == State.PAUSED) {
state = State.EXECUTING;
doIntercept(pausedMessage);
}
}
|
public void setFaultObserver(MessageObserver faultObserver) {
this.faultObserver = faultObserver;
}
|
public String toString() {
return toString("");
}
|