Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created July 9, 2014 15:37
Show Gist options
  • Save lucascs/ee52689f39f734167ce1 to your computer and use it in GitHub Desktop.
Save lucascs/ee52689f39f734167ce1 to your computer and use it in GitHub Desktop.
@Specializes
@RequestScoped
public class CidLogicResult extends DefaultLogicResult {
private MutableRequest request;
public CidLogicResult(...., MutableRequest request) {
super(....);
this.request = request;
}
@Override
public <T> T redirectTo(final Class<T> type) {
logger.debug("redirecting to class {}", type.getSimpleName());
return proxifier.proxify(type, new MethodInvocation<T>() {
@Override
public Object intercept(T proxy, Method method, Object[] args, SuperMethod superMethod) {
checkArgument(acceptsHttpGet(method), "Your logic method must accept HTTP GET method if you want to redirect to it");
try {
String url = router.urlFor(type, method, args);
String path = request.getContextPath() + url;
if (request.getParameter("cid") != null) {
path = path + "?cid=" + request.getParameter("cid");
}
includeParametersInFlash(type, method, args);
logger.debug("redirecting to {}", path);
response.sendRedirect(path);
return null;
} catch (IOException e) {
throw new ProxyInvocationException(e);
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment