1. 개요
Tomcat 8.5.31에 적용된 Bug 62297에 대한 내용이다. 8.5.30과 비교하여 살펴보자.
2. 소스 코드
2-1. 추가 import 클래스
import org.apache.catalina.Context; import org.apache.catalina.Host;
2-2. 추가 멤버 변수
private boolean isHostAware = true; private boolean isContextAware = true;
2-3. 추가 메소드
2-3-1. getter/setter
public boolean isHostAware() { return isHostAware; } public void setHostAware(boolean isHostAware) { this.isHostAware = isHostAware; } public boolean isContextAware() { return isContextAware; } public void setContextAware(boolean isContextAware) { this.isContextAware = isContextAware; }
2-3-2. getClientIdentifier(Host host, Context context, String clientIp)
private String getClientIdentifier(Host host, Context context, String clientIp) { StringBuilder result = new StringBuilder(clientIp); if (isHostAware) { result.append('-').append(host.getName()); } if (isContextAware) { result.append(context.getName()); } return result.toString(); }
2-4. invoke 메소드 코드 변경
2-4-1. clientIdentifier
우선 clientIdentifier 라는 변수가 추가되었다.
String clientIdentifier = getClientIdentifier(request.getHost(), request.getContext(), clientIp);
이 값은 valueUnbound 메소드에도 적용되어 있음.
2-4-2. log
그리고 디버그 로그에 해당 변수를 기록하는 부분이 추가되었다.
* 변경전
if (log.isDebugEnabled()) { log.debug(request.hashCode() + ": ClientIp=" + clientIp + ", RequestedSessionId=" + request.getRequestedSessionId()); }
* 변경후
if (log.isDebugEnabled()) { log.debug(request.hashCode() + ": ClientIdentifier=" + clientIdentifier + ", RequestedSessionId=" + request.getRequestedSessionId()); }
2-4-3. sessionId
bot일 때 세션 ID 설정 부분이 변경되었다.
* 변경전
if (isBot) { sessionId = clientIpSessionId.get(clientIp); if (sessionId != null) { request.setRequestedSessionId(sessionId); if (log.isDebugEnabled()) { log.debug(request.hashCode() + ": SessionID=" + sessionId); } } }
* 변경후
if (isBot) { sessionId = clientIdSessionId.get(clientIdentifier); if (sessionId != null) { request.setRequestedSessionId(sessionId); if (log.isDebugEnabled()) { log.debug(request.hashCode() + ": SessionID=" + sessionId); } } }
그 외에 곳곳에 clientIdentifier 변수가 쓰인다.