if (cacheManager.containsKey(cacheKey, requestHash) &&
cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx) != null) {
// get the response from the cache and attach to the context and change the
// direction of the message
CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);
if (!cachedObj.isExpired() && cachedObj.getResponseEnvelope() != null) {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Cache-hit for message ID : " + synCtx.getMessageID());
}
// mark as a response and replace envelope from cache
synCtx.setResponse(true);
try {
SOAPEnvelope omSOAPEnv = SOAPMessageHelper.buildSOAPEnvelopeFromBytes(
cachedObj.getResponseEnvelope());
// todo: if there is a WSA messageID in the response, is that need to be unique on each and every resp
synCtx.setEnvelope(omSOAPEnv);
} catch (AxisFault axisFault) {
handleException("Error setting response envelope from cache : "
+ cacheKey, synCtx);
} catch (IOException ioe) {
handleException("Error setting response envelope from cache : "
+ cacheKey, ioe, synCtx);
} catch (SOAPException soape) {
handleException("Error setting response envelope from cache : "
+ cacheKey, soape, synCtx);
}
// take specified action on cache hit
if (onCacheHitSequence != null) {
// if there is an onCacheHit use that for the mediation
synLog.traceOrDebug("Delegating message to the onCachingHit "
+ "Anonymous sequence");
onCacheHitSequence.mediate(synCtx);
} else if (onCacheHitRef != null) {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Delegating message to the onCachingHit " +
"sequence : " + onCacheHitRef);
}
synCtx.getSequence(onCacheHitRef).mediate(synCtx);
} else {
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Request message " + synCtx.getMessageID() +
" was served from the cache : " + cacheKey);
}
// send the response back if there is not onCacheHit is specified
synCtx.setTo(null);
Axis2Sender.sendBack(synCtx);
}
// stop any following mediators from executing
return false;
} else {
// cache exists, but has expired...
cachedObj.expire();
cachedObj.setTimeout(timeout);
synLog.traceOrDebug("Existing cached response has expired. Reset cache element");
cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
// Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
Replicator.replicate(cfgCtx);