Created
March 15, 2016 18:55
-
-
Save abhirockzz/984123afa25973cafcff to your computer and use it in GitHub Desktop.
Sharing contextual data b/w Request and Response filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Priority(Priorities.AUTHENTICATION) | |
public class ReqFilter_1 implements ContainerRequestFilter { | |
@Override | |
public void filter(ContainerRequestContext cReqCtx) throws IOException { | |
cReqCtx.setProperty("random-token", "token-007"); //generated and used internally | |
} | |
} | |
public class ResponseFilter implements ContainerResponseFilter { | |
@Override | |
public void filter(ContainerRequestContext cReqCtx, ContainerResponseContext cRespCtx) throws IOException { | |
String responseToken = (String) cReqCtx.getProperty("random-token"); //get the property | |
if(responseToken!=null){ | |
cRespCtx.getHeaders.put("random-token-header" , responseToken); //set it to HTTP response header | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment