本文介绍了Jersey:将值从ContainerRequestFilter传递到端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jersey 2.9,我创建了一个过滤器,它将获取一个加密的标头值,并对其进行解密,然后将其传递给被调用的端点。我不知道如何做到这一点,我一直在网上搜索,但没有真正找到我想做的具体例子。调用过滤器,我只是将值从它传递到端点时出现问题。
I am using Jersey 2.9 and I have created a filter which will take an encrypted header value, and decipher it and then pass it along to the endpoint which was called on. I have no idea of how to do this, and I have been searching on the internet but not really found a concrete example of what I want to do. The filter is called, I just have issues passing a value from it to the endpoint.
你能帮助我吗?
以下是一些示例代码:
public class MyFilter implements ContainerRequestFilter
{
@Override
public void filter(ContainerRequestContext requestContext) throws WebApplicationException {
String EncryptedString = requestContext.getHeaderString("Authentication");
/* Doing some methods to remove encryption */
/* Get a string which I want to pass to the endpoint which was called on, in this example: localhost:4883/rest/test */
}
}
@Path("rest")
public class restTest
{
@Path("test")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String Testing(){
/* Process the value from the MyFilter */
}
}
推荐答案
您可以轻松修改标题或添加另一个标题:
You can easily modify the header or add another one:
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
requestContext.getHeaders().add("X-Authentication-decrypted", decryptedValue);
}
此值可以在资源方法中注入:
This value can be injected in your resource-method:
@GET
@Produces(MediaType.APPLICATION_JSON)
public String Testing(@HeaderParam("X-Authentication-decrypted") String auth) {
}
这篇关于Jersey:将值从ContainerRequestFilter传递到端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!