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:org.chos.transaction.passport.LoginInterceptor.java

/**
 * (Javadoc)// www .  j ava2 s  .c  om
 *
 * @see org.springframework.web.servlet.HandlerInterceptor#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
 */
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj)
        throws Exception {
    String requestUrl = request.getRequestURI().replace(request.getContextPath(), "");
    System.out.println(requestUrl);
    Session session = httpContextSessionManager.getSession(request);
    if (session != null) {
        String redirect = request.getParameter("redirect");
        if (StringUtils.isBlank(redirect)) {
            redirect = redirectUrl;
        }
        response.sendRedirect(redirect);
    }
    return true;
}

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

@RequestMapping(value = "/gatewayreceivers", method = RequestMethod.POST)
public String performGatewayReceiversAction(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 ww w .j ava2 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;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<GatewayReceiver> gatewayreceivers = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the gateway recievers");

    GatewayReceiverDAO grDAO = GemFireXDWebDAOFactory.getGatewayRecieverDAO();

    if (request.getParameter("search") != null) {
        gatewayreceivers = grDAO.retrieveGatewayReceiverList((String) session.getAttribute("schema"),
                (String) request.getParameter("search"), (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_gatewayreceivers[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String id : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = grDAO.generateDDL(id, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = grDAO.simplegatewayReceiverCommand(id, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "GatewayReceiverDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        gatewayreceivers = grDAO.retrieveGatewayReceiverList((String) session.getAttribute("schema"), null,
                (String) session.getAttribute("user_key"));
    }

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

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

    if (gatewayreceivers.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("gatewayreceivers", gatewayreceivers);
    } 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 > gatewayreceivers.size()) {
                endAtIndex = gatewayreceivers.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

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

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

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

}

From source file:com.centurylink.mdw.hub.servlet.RestServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    CodeTimer timer = new CodeTimer("RestServlet.doGet()", true);

    if (request.getPathInfo() == null) {
        // redirect to html documentation
        response.sendRedirect(ApplicationContext.getMdwHubUrl() + "/doc/webServices.html");
        return;//  w  ww .  j  a  v  a 2 s. co  m
    } else if (request.getPathInfo().startsWith("/SOAP")) {
        // forward to SOAP servlet
        RequestDispatcher requestDispatcher = request.getRequestDispatcher(request.getPathInfo());
        requestDispatcher.forward(request, response);
        return;
    } else if (ApplicationContext.isDevelopment() && isFromLocalhost(request)) {
        // this is only allowed from localhost and in dev
        if ("/System/exit".equals(request.getPathInfo())) {
            response.setStatus(200);
            new Thread(new Runnable() {
                public void run() {
                    System.exit(0);
                }
            }).start();
            return;
        }
    }

    Map<String, String> metaInfo = buildMetaInfo(request);
    try {
        String responseString = handleRequest(request, response, metaInfo);

        String downloadFormat = metaInfo.get(Listener.METAINFO_DOWNLOAD_FORMAT);
        if (downloadFormat != null) {
            response.setContentType(Listener.CONTENT_TYPE_DOWNLOAD);
            String fileName = request.getPathInfo().substring(1).replace('/', '-') + "." + downloadFormat;
            response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
            if (downloadFormat.equals(Listener.DOWNLOAD_FORMAT_JSON)
                    || downloadFormat.equals(Listener.DOWNLOAD_FORMAT_XML)
                    || downloadFormat.equals(Listener.DOWNLOAD_FORMAT_TEXT)) {
                response.getOutputStream().write(responseString.getBytes());
            } else if (downloadFormat.equals(Listener.DOWNLOAD_FORMAT_FILE)) {
                String f = metaInfo.get(Listener.METAINFO_DOWNLOAD_FILE);
                if (f == null)
                    throw new ServiceException(ServiceException.INTERNAL_ERROR, "Missing meta");
                File file = new File(f);
                if (!file.isFile())
                    throw new ServiceException(ServiceException.NOT_FOUND,
                            "File not found: " + file.getAbsolutePath());
                int max = PropertyManager.getIntegerProperty(PropertyNames.MAX_DOWNLOAD_BYTES, 104857600);
                if (file.length() > max)
                    throw new ServiceException(ServiceException.NOT_ALLOWED,
                            file.getAbsolutePath() + " exceeds max download size (" + max + "b )");
                response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");
                try (InputStream in = new FileInputStream(file)) {
                    int read = 0;
                    byte[] bytes = new byte[8192];
                    while ((read = in.read(bytes)) != -1)
                        response.getOutputStream().write(bytes, 0, read);
                }
            } else {
                // for binary content string response will have been Base64 encoded
                response.getOutputStream().write(Base64.decodeBase64(responseString.getBytes()));
            }
        } else {
            if ("/System/sysInfo".equals(request.getPathInfo())
                    && "application/json".equals(metaInfo.get(Listener.METAINFO_CONTENT_TYPE))) {
                responseString = WebAppContext.addContextInfo(responseString, request);
            }
            response.getOutputStream().write(responseString.getBytes());
        }
    } catch (ServiceException ex) {
        logger.severeException(ex.getMessage(), ex);
        response.setStatus(ex.getCode());
        response.getWriter().println(createErrorResponseMessage(request, metaInfo, ex));
    } finally {
        timer.stopAndLogTiming("");
    }
}

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

@RequestMapping(value = "/diskstores", method = RequestMethod.POST)
public String performDiskStoreAction(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   www  .  j  a  va 2s. 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;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<DiskStore> dsks = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the disk stores");

    DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO();

    if (request.getParameter("search") != null) {
        dsks = dsDAO.retrieveDiskStoreList("", (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_ds[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String table : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = dsDAO.generateDDL(table, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = dsDAO.simplediskStoreCommand(table, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "DiskStoreDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        dsks = dsDAO.retrieveDiskStoreList("", null, (String) session.getAttribute("user_key"));
    }

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

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

    if (dsks.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("diskstores", dsks);
    } 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 > dsks.size()) {
                endAtIndex = dsks.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();

        }

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

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

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

}

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

@RequestMapping(value = "/hdfsstores", method = RequestMethod.POST)
public String performHdfsStoreAction(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 {//  www .j a  v  a  2  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;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<HdfsStore> hdfsStores = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the hdfs stores");

    HdfsStoreDAO hdfsDAO = GemFireXDWebDAOFactory.getHdfsStoreDAO();

    if (request.getParameter("search") != null) {
        hdfsStores = hdfsDAO.retrieveHdfsStoreList("", (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_hdfs[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String table : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = hdfsDAO.generateDDL(table, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = hdfsDAO.simplehdfsStoreCommand(table, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "HDFSStoreDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        hdfsStores = hdfsDAO.retrieveHdfsStoreList("", null, (String) session.getAttribute("user_key"));
    }

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

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

    if (hdfsStores.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("hdfsstores", hdfsStores);
    } 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 > hdfsStores.size()) {
                endAtIndex = hdfsStores.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();

        }

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

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

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

}

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

@RequestMapping(value = "/asyncevent", method = RequestMethod.POST)
public String performAsyncAction(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 w w .  ja 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;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<Asyncevent> asyncevents = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the async events");

    AsynceventDAO asyncDAO = GemFireXDWebDAOFactory.getAsynceventDAO();

    if (request.getParameter("search") != null) {
        asyncevents = asyncDAO.retrieveAsynceventList((String) session.getAttribute("schema"),
                (String) request.getParameter("search"), (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_async[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String asyncName : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = asyncDAO.generateDDL(asyncName, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = asyncDAO.simpleasynceventCommand(asyncName, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "AsyncEventListenerDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        asyncevents = asyncDAO.retrieveAsynceventList((String) session.getAttribute("schema"), null,
                (String) session.getAttribute("user_key"));
    }

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

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

    if (asyncevents.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("asyncevents", asyncevents);
    } 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 > asyncevents.size()) {
                endAtIndex = asyncevents.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

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

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

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

From source file:es.uma.inftel.blog.bean.PostBean.java

@PostConstruct
public void inicializar() {
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    String idParam = externalContext.getRequestParameterMap().get("id");
    if (idParam == null || idParam.equals("")) {
        return;//from  w  w w . j a v  a  2s .c  o  m
    }
    idp = Long.valueOf(idParam);
    post = postFacade.findPostById(idp);
    if (post == null) {
        try {
            HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
            response.sendRedirect("index.jsf");
        } catch (IOException ex) {
            Logger.getLogger(PostBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        autorPost = post.getUsuarioId();
        titulo = post.getTitulo();
        texto = post.getTexto();
        parrafosPost = Arrays.asList(post.getTexto().split("\\n"));
        fechaCreacion = post.getFechaCreacion();
        fechaModificacion = post.getFechaModificacion();
        listaEtiquetas = post.getEtiquetaCollection();
        etiqueta = getEtiquetas();
        listaComentarios = new ArrayList<>(post.getComentarioCollection());
        Collections.sort(listaComentarios);
        imagenes = post.getImagenCollection();
        mapa = mapaFacade.findMapaPost(idp);
        if (mapa != null) {
            longitud = mapa.getLongitud().toString();
            latitud = mapa.getLatitud().toString();
        }
    }

}

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

@RequestMapping(value = "/createprocedure", method = RequestMethod.POST)
public String createProcedureAction(@ModelAttribute("procedureAttribute") NewProcedure procedureAttribute,
        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   ww  w . j  a  va  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 create Procedure");

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

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

    logger.debug("New Procedure schema name = " + schema);
    logger.debug("New Procedure name = " + procedureAttribute.getProcedureName());

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

    if (submit != null) {
        if (submit.equalsIgnoreCase("Parameter(s)")) {
            int cols = Integer.parseInt(request.getParameter("numParams"));
            int numParams = Integer.parseInt((String) session.getAttribute("numParams"));

            numParams = numParams + cols;

            session.setAttribute("numParams", "" + numParams);
            model.addAttribute("numParams", numParams);
        } else {
            // build create HDFS Store SQL
            StringBuffer createProcedure = new StringBuffer();

            createProcedure
                    .append("CREATE PROCEDURE " + schema + "." + procedureAttribute.getProcedureName() + " \n");

            String[] parameterTypes = request.getParameterValues("parameter_type[]");
            String[] parameterNames = request.getParameterValues("parameter_name[]");
            String[] dataTypes = request.getParameterValues("data_type[]");
            String[] columnPrecision = request.getParameterValues("column_precision[]");

            logger.debug("parameterTypes = " + Arrays.toString(parameterTypes));
            logger.debug("parameterNames = " + Arrays.toString(parameterNames));
            logger.debug("dataTypes = " + Arrays.toString(dataTypes));
            logger.debug("columnPrecision = " + Arrays.toString(columnPrecision));

            int i = 0;

            int size = 0;

            if (parameterNames != null) {
                size = parameterNames.length;

                for (String parameterName : parameterNames) {
                    if (i == 0) {
                        createProcedure.append("(");
                    }

                    createProcedure.append(parameterTypes[i] + " " + parameterName + " " + dataTypes[i]);
                    if (columnPrecision[i].length() != 0) {
                        createProcedure.append("(" + columnPrecision[i] + ")");
                    }

                    i++;
                    if (i < size) {
                        createProcedure.append(", \n");
                    }
                }

                if (i >= 1) {
                    createProcedure.append(") \n");
                }
            }

            if (!checkIfParameterEmpty(request, "language")) {
                createProcedure.append("LANGUAGE " + procedureAttribute.getLanguage() + " \n");
            }

            if (!checkIfParameterEmpty(request, "parameterStyle")) {
                createProcedure.append("PARAMETER STYLE " + procedureAttribute.getParameterStyle() + " \n");
            }

            if (!checkIfParameterEmpty(request, "sqlAccess")) {
                createProcedure.append(procedureAttribute.getSqlAccess() + " \n");
            }

            if (!checkIfParameterEmpty(request, "dynamicResultsets")) {
                createProcedure
                        .append("DYNAMIC RESULT SETS " + procedureAttribute.getDynamicResultsets() + " \n");
            }

            createProcedure.append("EXTERNAL NAME '" + procedureAttribute.getExternalName() + "'\n");

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

                logger.debug("Creating Procedure as -> " + createProcedure.toString());

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

                model.addAttribute("result", result);

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

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

    }

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

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

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String username = request.getParameter("username");
    boolean confirm = StringUtils.equals(request.getParameter("confirm"), "true");

    User user = userService.getUser(username);

    String currentUser = (String) request.getSession().getAttribute("username");

    if (user != null && !StringUtils.equals(currentUser, username)) {
        if (confirm) {
            userService.removeUser(user);

            response.sendRedirect("/");
        } else {// w ww  .  j  av a2 s  .c o m
            request.setAttribute("user", username);

            RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/remove.jsp");
            rd.include(request, response);
        }
    } else {
        response.sendRedirect("/");
    }
}

From source file:coyote.commons.web.AuthFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;

    String uri = req.getRequestURI();
    LOG.debug("Requested Resource:" + uri);

    HttpServletResponse res = (HttpServletResponse) response;

    if (uriIsProtected(uri)) {
        Login login = WebApp.getLogin(req);
        if (login == null) {
            LOG.warn("Must be logged in to access " + uri);
            // set the original request URI in the session so login script can redirect
            req.getSession().setAttribute(WebApp.SESSION_TARGET_URI_KEY, uri);
            res.sendRedirect("login");
        } else {//  ww  w. j a v  a  2s.  c o m
            // TODO: Check if login has access to the URI target
        } // login check
    } else {
        // Not a protected URI, pass the request along the filter chain
        try {
            chain.doFilter(request, response);
        } catch (Exception e) {
            LOG.warn("Exception sending request down the chain", e);
        }
    } // if protected URI

}