如何拦截自定义 HTTP 标头值并将其存储在 Wicket 的 WebSession 中?
我需要从每个请求中获取特定的自定义 HTTP 标头值并将其放入 WebSession 中,以便以后可以在任何网页上使用它。 (我相信 Wicket 的方法是使用一个扩展 WebSession 的自定义类,该类具有适当的访问器。)
我的问题是,我需要哪种过滤器(或其他机制)能够拦截标头和访问 WebSession 来存储值?
我尝试使用普通的 Java EE Filter 来执行此操作,使用
CustomSession session = (CustomSession) AuthenticatedWebSession.get();
But(也许并不奇怪),结果是:
java.lang.IllegalStateException:
you can only locate or create sessions in the context of a request cycle
我是否应该扩展 WicketFilter 并在那里执行它(我可以在那时访问会话吗?),或者是更复杂的事情必需的?
当然,如果我做的完全错误,请指出;我是威克特的新手。
I need to grab a certain custom HTTP header value from every request and put it in WebSession so that it will be available on any WebPage later on. (I believe the Wicket way to do this is to have a custom class extending WebSession that has appropriate accessors.)
My question is, what kind of Filter (or other mechanism) I need to be able to both intercept the header and access the WebSession for storing the value?
I tried to do this with a normal Java EE Filter, using
CustomSession session = (CustomSession) AuthenticatedWebSession.get();
But (perhaps not surprisingly), that yields:
java.lang.IllegalStateException:
you can only locate or create sessions in the context of a request cycle
Should I perhaps extend WicketFilter and do it there (can I access the session at that point?), or is something even more complicated required?
Of course, please point it out if I'm doing something completely wrong; I'm new to Wicket.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你需要实现一个自定义的 WebRequestCycle:
在你的 WebApplication 类中,你可以像这样注册自定义的 RequestCycle:
参考:
处理器
I'd guess you need to implement a custom WebRequestCycle:
And in your WebApplication class you register the custom RequestCycle like this:
Reference:
processor