Tomcat 8.5.X: Migrate Valve javacode from Tomcat 7



我需要将我们的一个自定义 Valve 代码从 Tomcat 7 迁移到 Tomcat 8.5:

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import org.apache.catalina.Container;
import org.apache.catalina.Manager;
import org.apache.catalina.Session;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.valves.ValveBase;
public class SessionManagerValve extends ValveBase {
    @Override
    public void invoke(Request request, Response response) throws IOException, ServletException {
      // ...
    }
    public HttpSession findSession(String id, boolean updateLastAccessTime) {
        try {
            Container container = getContainer();
            // works with Tomcat 7.x, but not with Tomcat 8.5 anymore...
            Manager man = container.getManager();
            Session sess = man.findSession(id);
            return sess.getSession();
       } catch (Exception e) {
           return null;
       } 
    }
}

Container接口不再提供getManager()方法。根据Tomcat迁移指南,访问Manager已从Container转移到Context

任何人都可以给我一个提示,如何从ValveBase对象中访问Manager

提前感谢, 雷纳

编辑:上下文配置是 - 如答案中正确指出的那样 -

<Context path="" ...>
    <Valve className="SessionManagerValve" />
</Context>

假设您的Valve处于Context级别(必须为上面的代码工作(,那么您需要:

((Context) getContainer()).getManager();

相关内容

  • 没有找到相关文章

最新更新