Kan*_*ler 3 java rest servlets jersey
我使用的是Jersey 2.9,我创建了一个过滤器,它将获取一个加密的标头值,并对其进行解密,然后将其传递给被调用的端点.我不知道如何做到这一点,我一直在互联网上搜索,但没有真正找到我想做的具体例子.调用过滤器,我只是将值从它传递到端点时出现问题.
你们能帮帮我吧!
以下是一些示例代码:
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 */
}
}
Run Code Online (Sandbox Code Playgroud)
您可以轻松修改标题或添加另一个标题:
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
requestContext.getHeaders().add("X-Authentication-decrypted", decryptedValue);
}
Run Code Online (Sandbox Code Playgroud)
可以在资源方法中注入此值:
@GET
@Produces(MediaType.APPLICATION_JSON)
public String Testing(@HeaderParam("X-Authentication-decrypted") String auth) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2215 次 |
| 最近记录: |