Hi,
an interceptor is a singleton and therefore has only one instance. If
you need a per exchange lifecycle you can simulate this by using a
Map. The following example shows an interceptor that uses a thread-
safe map to save session data:
public class SessionDataInterceptor extends AbstractInterceptor {
private static Log log =
LogFactory.getLog(SessionDataInterceptor.class
.getName());
private Map<Exchange, Integer> sessions = new
ConcurrentHashMap<Exchange, Integer>();
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
sessions.put(exc, new Random().nextInt());
return Outcome.CONTINUE;
}
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
int session = sessions.get(exc);
log.info("session: " + session);
sessions.remove(session);
return Outcome.CONTINUE;
}
}
Alternatively you can store per exchange data in the exchange itself
using the following methods:
exc.setProperty(key, value)
exc.getProperty(key)
Please tell me if that solves your problem. If not can you describe
your scenario in more detail?
Kind Regards
Shaan