Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created August 15, 2012 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascs/3360420 to your computer and use it in GitHub Desktop.
Save lucascs/3360420 to your computer and use it in GitHub Desktop.
Forcing commit on redirects
@Intercepts
public class RedirectCommitInterceptor implements Interceptor {
private Session session;
private MutableResponse response;
public RedirectCommitInterceptor(Session session, MutableResponse response) {
this.session = session;
this.response = response;
}
public boolean accept(ResourceMethod method) {
return true;
}
public void intercept(ResourceMethod method, Object instance, InterceptorStack stack) {
response.addRedirectListener(new RedirectListener() {
@Override
public void beforeRedirect() {
session.getTransaction().commit();
}
});
stack.next(method, instance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment