package jp.troter.servlet.httpsession.spi.impl;

import java.util.UUID;

import org.apache.commons.codec.digest.DigestUtils;

import jp.troter.servlet.httpsession.UserHttpSessionHttpServletRequestWrapper;
import jp.troter.servlet.httpsession.spi.SessionIdGenerator;

public class DefaultSessionIdGenerator extends SessionIdGenerator{

    @Override
    public String generateSessionId(UserHttpSessionHttpServletRequestWrapper request) {
        return generateSessionId(request, -1);
    }

    @Override
    public String generateSessionId(UserHttpSessionHttpServletRequestWrapper request, int retry) {
        String seed = String.format("%s:%s:%s:%s:%s",
                getUUIDString(), getHostName(), getThreadIdString(), request.getRemoteAddr(), String.valueOf(retry));
        return DigestUtils.sha512Hex(seed);
    }

    protected String getUUIDString() {
        return UUID.randomUUID().toString();
    }

    protected String getHostName() {
        String hostname = "";
        try {
            hostname = java.net.InetAddress.getLocalHost().getHostName();
        } catch (java.net.UnknownHostException e) {
            // TODO logging
            hostname = "";
        }
        return hostname;
    }

    protected long getThreadId() {
        return Thread.currentThread().getId();
    }

    protected String getThreadIdString() {
        return Long.valueOf(getThreadId()).toString();
    }
}

@@ -70,61 +70,8 @@
 D;%0A%0A
-import org.apache.commons.codec.digest.DigestUtils;%0A%0A
 impo
@@ -211,74 +211,275 @@
 r;%0A%0A
-public class DefaultSessionIdGenerator extends SessionIdGenerator%7B
+import org.apache.commons.codec.digest.DigestUtils;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Apublic class DefaultSessionIdGenerator extends SessionIdGenerator%7B%0A%0A    private static Logger log = LoggerFactory.getLogger(DefaultSessionIdGenerator.class);
 %0A%0A  
@@ -1282,49 +1282,50 @@
     
-// TODO logging%0A           
+log.warn(%22Can not get local
  host
+ 
 name
- = %22%22
+%22, e)
 ;%0A  

add log