private static void printError(String message) {
Broker.printerr(" "+message);
}
public boolean filter(Request request, Response response) throws FilterException {
ID sessionID = null;
String cookie = request.getHeader(HTTP.HEADER_COOKIE);
StringTokenizer st = new StringTokenizer(cookie, ";");
while ( st.hasMoreTokens() ) {
String token = st.nextToken();
int idx = token.indexOf('=');
if ( idx != -1 ) {
String key = token.substring(0, idx).trim();
if ( key.equals(COOKIE_NAME) ) {
String value = token.substring(idx + 1).trim();
sessionID = new ID(value);
}
}
}
BrokerContext brokerContext = Broker.getInstance().getBrokerContext();
ID instanceID = brokerContext.getId();
SessionContext context = getClosestContext(instanceID);
boolean setCookie = sessionID == null || context.expires;
if ( sessionID == null )
sessionID = new ID();
if ( setCookie ) {
StringBuffer sb = new StringBuffer();
sb.append(COOKIE_NAME);
sb.append('=');