gpt4 book ai didi

java - 从jetty 7迁移到jetty 8时如何调用.addfilter()?

转载 作者:行者123 更新时间:2023-12-01 09:36:25 24 4
gpt4 key购买 nike

我正在将 jetty 7 迁移到 jetty 8,
我收到此错误:

no suitable method found for addFilter(Class,String,int) servletContext.addFilter(JsonTokenFilter.class, "/*", FilterMapping.REQUEST);

我想做的是:

 // servlet context
ServletContextHandler servletContext = new ServletContextHandler( ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY);

// set session manager
SessionHandler sessionHandler = new GatewaySessionHandler(sessionManager);
servletContext.setSessionHandler(sessionHandler);
sessionHandler.addEventListener(new SessionListener());
sessionHandler.addEventListener(new CsrfGuardHttpSessionListener());
sessionManager.setSecureRequestOnly(Utilities.getConfigBoolean("fievel.jetty.secureCookies", true));
sessionManager.setHttpOnly(Utilities.getConfigBoolean( "fievel.jetty.httpCookies", true));
setSessionSettings();

// add json rpc signal if session token invalid
servletContext.addFilter(JsonTokenFilter.class, "/*", FilterMapping.REQUEST);

最后一行是给出错误的行。

如果我引用ServletContextHandler对于 8 号 jetty ,

addFilter(FilterHolder holder, String pathSpec, EnumSet<DispatcherType> dispatches) 

理想的是我应该编写的代码类型。

有人可以告诉我我哪里出错了吗?

最佳答案

我认为你应该写这样的东西:

servletContext.addFilter(JsonTokenFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

因为它需要一个 EnumSet 而不是 int

我已经尝试过 eclipse jetty tutorial 的教程

public static void main(String[] args) throws Exception
{
Server server = new Server(8080);

ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContext.setContextPath("/");
server.setHandler(servletContext);

servletContext.addServlet(new ServletHolder(new HelloServlet()),"/*");

servletContext.addFilter(TestFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

server.start();
server.join();
}

输出是:

2016-08-10 15:13:58.054:INFO:oejs.Server:jetty-8.1.19.v20160209
TestFilter Init
2016-08-10 15:13:58.186:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080
TestFilter doFilter running

所以过滤器确实以这种方式注册

关于java - 从jetty 7迁移到jetty 8时如何调用.addfilter()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38866160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com