如何将数据从Filter传递到Jersey中的端点 [英] How can you pass data from a Filter to the endpoint in Jersey

查看:103
本文介绍了如何将数据从Filter传递到Jersey中的端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以在不使用ThreadLocal或HttpSession的情况下将一些数据从javax.servlet.Filter传递到Jersey端点吗?

Can you pass some data from a javax.servlet.Filter to a Jersey endpoint without using ThreadLocal or HttpSession?

因为第一个问题是为什么呢?你想这样做吗?:大多是好奇的。在实践中,我认为我可以使用它将身份验证期间生成的一些数据传递给端点。不使用ThreadLocal消除了在链中使用它的诱惑(希望没有必要解释为什么那是邪恶的)并且不使用HttpSession更多的是一个怪癖:)

And because the first question will be "why do you want to do this?": mostly curious. In practice I think I could use this to pass some data generated during authentication to the endpoint. Not using ThreadLocal eliminates the temptation to use that down the chain (hope there's no need to explain why that's evil) and not using HttpSession is more of a quirk :)

推荐答案

尝试使用 @Context 进行注入。我不确定你会收到什么对象(在某处我看到 WebServiceContext ,这是jax-ws),但它应该包含 HttpServletRequest 。这样您就可以在过滤器中设置请求属性,并在其余服务中读取它们

Try injecting with @Context. I'm not sure what object you will receive though (somewhere I saw WebServiceContext, which is jax-ws), but it should contain the HttpServletRequest. so you will be a able to set request attributes in the filter and read them in the rest service

这篇关于如何将数据从Filter传递到Jersey中的端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆