Skip to content

Instantly share code, notes, and snippets.

@inancsevinc
Created April 12, 2012 13:24
Show Gist options
  • Save inancsevinc/2367188 to your computer and use it in GitHub Desktop.
Save inancsevinc/2367188 to your computer and use it in GitHub Desktop.
JAX-RS client filter responsible for adding cookies(retrieved from springcontextholder) to the outgoing request
private ClientFilter cookieFilter = new ClientFilter() {
@Override
public ClientResponse handle(ClientRequest cr)
throws ClientHandlerException {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
Cookie[] cookies = request.getCookies();
StringBuilder strBuilder = new StringBuilder();
if (cookies != null) {
for (Cookie cookie : cookies) {
strBuilder.append(cookie.getName()).append("=")
.append(cookie.getValue()).append(";");
}
}
cr.getHeaders().add("Cookie", strBuilder.toString());
return getNext().handle(cr);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment