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.
Could you guys help me!
Here is some sample code:
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) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With