Example usage for javax.servlet.http HttpServletResponse sendRedirect

List of usage examples for javax.servlet.http HttpServletResponse sendRedirect

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse sendRedirect.

Prototype

public void sendRedirect(String location) throws IOException;

Source Link

Document

Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.

Usage

From source file:pivotal.au.se.gemfirexdweb.controller.AddListenerController.java

@RequestMapping(value = "/addlistener", method = RequestMethod.POST)
public String createListenerAction(@ModelAttribute("listenerAttribute") AddListener listenerAttribute,
        Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session)
        throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*w  ww.ja  v a  2  s  .  co  m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for add listener");

    logger.debug("Listener ID = " + listenerAttribute.getId());

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer addListener = new StringBuffer();

        addListener.append("CALL SYS.ADD_LISTENER ('" + listenerAttribute.getId() + "', \n");
        addListener.append("'" + listenerAttribute.getSchemaName() + "', \n");
        addListener.append("'" + listenerAttribute.getTableName() + "', \n");
        addListener.append("'" + listenerAttribute.getFunctionName() + "', \n");

        if (!checkIfParameterEmpty(request, "initString")) {
            addListener.append("'" + listenerAttribute.getInitString() + "', \n");
        } else {
            addListener.append("'', \n");
        }

        if (!checkIfParameterEmpty(request, "serverGroups")) {
            addListener.append("'" + listenerAttribute.getServerGroups() + "')");
        } else {
            addListener.append("''), \n");
        }

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating Listener as -> " + addListener.toString());

            result = GemFireXDWebDAOUtil.runStoredCommand(addListener.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);
            model.addAttribute("tableName", listenerAttribute.getTableName());

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create Listener SQL as follows as -> " + addListener.toString());
            model.addAttribute("sql", addListener.toString());
            model.addAttribute("tableName", listenerAttribute.getTableName());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, listenerAttribute.getId()));

            ServletOutputStream out = response.getOutputStream();
            out.println(addListener.toString());
            out.close();
            return null;
        }

    }

    // This will resolve to /WEB-INF/jsp/addlistener.jsp
    return "addlistener";
}

From source file:io.muic.ooc.webapp.servlet.AddServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*w w w .  j av a 2  s  .  c o  m*/
        boolean authorized = securityService.isAuthorized(request);
        if (authorized) {
            // do MVC in here
            RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/add.jsp");
            rd.include(request, response);
        } else {
            response.sendRedirect("/login");
        }
    } catch (Exception e) {

    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateProcedureController.java

@RequestMapping(value = "/createprocedure", method = RequestMethod.GET)
public String createProcedure(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/* ww  w.j  a v  a 2s.  com*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to create a new Procedure");

    session.setAttribute("numParams", "0");
    model.addAttribute("numParams", "0");
    model.addAttribute("procedureAttribute", new NewProcedure());

    // This will resolve to /WEB-INF/jsp/create-procedure.jsp
    return "create-procedure";
}

From source file:pivotal.au.se.gemfirexdweb.controller.JarController.java

@RequestMapping(value = "/jars", method = RequestMethod.GET)
public String showJars(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/gemfirexdweb/login");
        return null;
    } else {/*from   w w  w . ja  va2  s.c  o  m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to show jars");

    int startAtIndex = 0, endAtIndex = 0;
    String schema = null;

    JarDAO jarDAO = GemFireXDWebDAOFactory.getJarStoreDAO();
    Result result = new Result();

    String jarAction = request.getParameter("jarAction");

    if (jarAction != null) {
        logger.debug("jarAction = " + jarAction);
        result = null;
        result = jarDAO.simpleJarCommand((String) request.getParameter("schemaName"),
                (String) request.getParameter("alias"), jarAction, (String) session.getAttribute("user_key"));

        model.addAttribute("result", result);

    }

    List<Jar> jars = jarDAO.retrieveJarList("", null, (String) session.getAttribute("user_key"));

    model.addAttribute("records", jars.size());
    model.addAttribute("estimatedrecords", jars.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (jars.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("jars", jars);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > jars.size()) {
                endAtIndex = jars.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = jars.subList(startAtIndex, endAtIndex);
        model.addAttribute("jars", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/jars.jsp
    return "jars";
}

From source file:fr.scc.elo.controller.PlayerController.java

@GET
@Produces({ MediaType.TEXT_HTML })
@Path("/create/{name}")
public void createPlayer(@Context HttpServletRequest http, @Context HttpServletResponse redirect,
        @PathParam("name") String name) throws IOException {

    if (connectionService.acceptIPDelete(http.getRemoteAddr())) {
        eloService.createPlayer(name);//from w  w w . j a va2 s. co  m
    }
    redirect.sendRedirect("/rest/v1/player/showall/html");
}

From source file:org.mitre.account_chooser.AccountChooserController.java

/**
 * Handles form submits/* w  ww  . j  av a  2s  .co  m*/
 * 
 * @param redirectUri
 *            A redirection URI where the response will be sent.
 * @param alias
 *            The OIDC alias selected.
 * @param response
 *            Provide the HTTP-specific functionality for sending a
 *            response. In this case a redirect to redirect the End-User
 *            back to the OpenID Connect Client.
 * @throws IOException
 *             If an output exception occurs in sending the redirect.
 */
@RequestMapping(value = "/cancel")
public void processCancel(@RequestParam("redirect_uri") String redirectUri,
        @RequestParam("issuer") String issuer, @RequestParam("client_id") String clientId,
        HttpServletResponse response) throws IOException {

    // Handle Cancel

    Map<String, String> urlVariables = new HashMap<String, String>();
    urlVariables.put("error", "end_user_cancelled");
    urlVariables.put("error_description", "The end-user refused to select an Account.");

    response.sendRedirect(AccountChooserController.buildURL(redirectUri, urlVariables));

}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateFunctionController.java

@RequestMapping(value = "/createfunction", method = RequestMethod.GET)
public String createFunction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from   w  w  w.  j  a  v a2  s  .  co  m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to create a new Function");

    session.setAttribute("numParams", "0");
    model.addAttribute("numParams", "0");
    model.addAttribute("functionAttribute", new NewFunction());

    // This will resolve to /WEB-INF/jsp/create-function.jsp
    return "create-function";
}

From source file:eu.morfeoproject.fast.catalogue.services.GenericServlet.java

protected void redirectToFormat(HttpServletRequest request, HttpServletResponse response, String format)
        throws IOException {
    String extension = MediaType.getExtension(format);
    extension = extension == null ? MediaType.getExtension(MediaType.APPLICATION_JSON) : extension;
    String url = request.getRequestURL().toString();
    url = (url.charAt(url.length() - 1) == '/') ? url.concat(extension) : url.concat("/" + extension);
    response.sendRedirect(url);
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateSynonymController.java

@RequestMapping(value = "/createsynonym", method = RequestMethod.POST)
public String createSynonymAction(@ModelAttribute("synonymAttribute") NewSynonym synonymAttribute, Model model,
        HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {// ww w  .  j  a  v  a  2 s.  c om
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create synonym");

    String schema = synonymAttribute.getSchemaName().trim();

    if (schema.length() == 0) {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("New synonym name = " + synonymAttribute.getSynonymName());

    TableDAO tableDAO = GemFireXDWebDAOFactory.getTableDAO();
    ViewDAO viewDAO = GemFireXDWebDAOFactory.getViewDAO();

    List<View> views = viewDAO.retrieveViewList((String) session.getAttribute("schema"), null,
            (String) session.getAttribute("user_key"));

    model.addAttribute("views", views);

    List<Table> tbls = tableDAO.retrieveTableList((String) session.getAttribute("schema"), null,
            (String) session.getAttribute("user_key"), "ORDINARY");

    model.addAttribute("tables", tbls);

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer createSynonym = new StringBuffer();

        createSynonym.append("CREATE SYNONYM " + schema + "." + synonymAttribute.getSynonymName() + " \n");
        createSynonym.append("FOR " + synonymAttribute.getObjectName() + " \n");

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating synonym as -> " + createSynonym.toString());

            result = GemFireXDWebDAOUtil.runCommand(createSynonym.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create UDT (Type) SQL as follows as -> " + createSynonym.toString());
            model.addAttribute("sql", createSynonym.toString());
            model.addAttribute("objectName", request.getParameter("objectName"));
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, synonymAttribute.getSynonymName()));

            ServletOutputStream out = response.getOutputStream();
            out.println(createSynonym.toString());
            out.close();
            return null;
        }

    }

    // This will resolve to /WEB-INF/jsp/create-synonym.jsp
    return "create-synonym";
}

From source file:com.palantir.stash.disapprove.servlet.DisapprovalServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    final String user = authenticateUser(req, res);
    if (user == null) {
        // not logged in, redirect
        res.sendRedirect(lup.getLoginUri(getUri(req)).toASCIIString());
        return;/*from w  ww. j a  v a 2 s  .c o  m*/
    }

    final String URL_FORMAT = "BASE_URL/REPO_ID";
    final String pathInfo = req.getPathInfo();
    final String[] parts = pathInfo.split("/");

    if (parts.length != 5) {
        throw new IllegalArgumentException("The format of the URL is " + URL_FORMAT);
    }

    final Integer repoId;
    final Long prId;
    try {
        repoId = Integer.valueOf(parts[3]);
        prId = Long.valueOf(parts[4]);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The format of the URL is " + URL_FORMAT, e);
    }

    final PullRequest pr = pullRequestService.getById(repoId, prId);
    if (pr == null) {
        throw new IllegalArgumentException("No PR found for repo id " + repoId + " pr id " + prId.toString());
    }

    PullRequestDisapproval prd;
    DisapprovalConfiguration dc;
    try {
        prd = pm.getPullRequestDisapproval(pr);
        dc = pm.getDisapprovalConfiguration(pr.getToRef().getRepository());
    } catch (SQLException e) {
        throw new ServletException(e);
    }

    try {
        Writer w = res.getWriter();
        //res.setContentType("text/html;charset=UTF-8");
        res.setContentType("application/json;charset=UTF-8");
        w.append(new JSONObject(ImmutableMap.of("disapproval", prd.isDisapproved(), "disapprovedBy",
                prd.getDisapprovedBy(), "enabledForRepo", dc.isEnabled())).toString());
    } finally {
        res.getWriter().close();
    }
}