Skip to content

Instantly share code, notes, and snippets.

@lurodrig
Last active November 8, 2018 09: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 lurodrig/e1a20f480f3c4202c083a091ed68b0d7 to your computer and use it in GitHub Desktop.
Save lurodrig/e1a20f480f3c4202c083a091ed68b0d7 to your computer and use it in GitHub Desktop.
package cross.context.test.suite;
import java.io.IOException;
import java.util.Base64;
import java.util.UUID;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author lurodrig
*/
public class RedirectServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String original_request = request.getParameter("original_request");
if (original_request != null) {
Cookie cookie = new Cookie("SECRET_COOKIE", UUID.randomUUID().toString());
cookie.setPath("/");
response.addCookie(cookie);
response.sendRedirect(new String(Base64.getDecoder().decode(original_request)));
} else {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
}
// doGet & doPost....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment