in wilma-extras/shortCircuit/src/main/java/com/epam/wilma/extras/shortcircuit/ShortCircuitInterceptorCore.java [161:201]
void preserveResponse(String shortCircuitHashCode, WilmaHttpResponse wilmaHttpResponse, ParameterList parameterList) {
long timeout;
if (shortCircuitMap.containsKey(shortCircuitHashCode)) { //only if this needs to be handled
//do we have the response already, or we need to catch it right now?
ShortCircuitResponseInformation shortCircuitResponseInformation = shortCircuitMap.get(shortCircuitHashCode);
if (shortCircuitResponseInformation == null) {
//we need to store the response now
//but first check if response code is 200, and content type is text based
String contentType = wilmaHttpResponse.getHeader("Content-Type");
if (wilmaHttpResponse.getStatusCode() == HttpServletResponse.SC_OK && contentType != null && allowedContentType(contentType)) {
String timeoutParameterName = "timeout";
if (parameterList != null && parameterList.get(timeoutParameterName) != null) {
timeout = Long.valueOf(parameterList.get(timeoutParameterName))
+ Calendar.getInstance().getTimeInMillis();
} else {
timeout = Long.MAX_VALUE; //forever
}
shortCircuitResponseInformation = new ShortCircuitResponseInformation(wilmaHttpResponse, timeout, shortCircuitHashCode);
shortCircuitMap.put(shortCircuitHashCode, shortCircuitResponseInformation);
//CHECKSTYLE OFF - we must use "new String" here
String decodedEntryKey = new String(Base64.decodeBase64(shortCircuitHashCode)); //make it human readable
//CHECKSTYLE ON
logger.info("ShortCircuit: Message captured for hashcode: {}", decodedEntryKey);
} else {
//we cannot store it, so it is better to remove it from the shortCircuit map
shortCircuitMap.remove(shortCircuitHashCode);
}
} else { //we have response
//take care about timeout
timeout = Calendar.getInstance().getTimeInMillis();
if (timeout > shortCircuitResponseInformation.getTimeout()) {
shortCircuitMap.remove(shortCircuitHashCode);
//CHECKSTYLE OFF - we must use "new String" here
String decodedEntryKey = new String(Base64.decodeBase64(shortCircuitHashCode)); //make it human readable
//CHECKSTYLE ON
logger.info("ShortCircuit: Timeout has happened for hashcode: {}", decodedEntryKey);
}
}
}
}