List of usage examples for javax.servlet ServletContext getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:org.jbpm.formbuilder.server.RESTFormService.java
@POST @Path("/template/file/{action}") public void processFormTemplate(@PathParam("action") String action, @Context ServletContext context, @Context HttpServletRequest request, @Context HttpServletResponse response) { try {/*from w w w . j a v a2 s . c o m*/ request.setAttribute("org.jbpm.formbuilder.server.REST.processFormTemplate.action", action); if (ServletFileUpload.isMultipartContent(request)) { //read multipart request and populate request accordingly for display int maxMemorySize = 240000; File tmpDirectory = new File(System.getProperty("java.io.tmpdir")); DiskFileItemFactory factory = new DiskFileItemFactory(maxMemorySize, tmpDirectory); ServletFileUpload upload = new ServletFileUpload(factory); List<?> files = upload.parseRequest(request); for (Object obj : files) { FileItem item = (FileItem) obj; request.setAttribute(item.getFieldName(), item.getString()); } } String queryString = request.getQueryString(); if (queryString == null) { queryString = "?"; } if (!queryString.startsWith("?")) { queryString = "?" + queryString; } context.getRequestDispatcher("/fbapi/mockProcess.jsp" + queryString).forward(request, response); } catch (Exception e) { error("Couldn't process form template", e); } }
From source file:com.openkm.servlet.admin.DatabaseQueryServlet.java
/** * Import into database/*ww w. ja va2s. c o m*/ */ private void executeUpdate(Session session, byte[] data, ServletContext sc, HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException { log.debug("executeUpdate({}, {}, {})", new Object[] { session, request, response }); List<DbQueryGlobalResult> globalResults = new ArrayList<DbQueryGlobalResult>(); WorkerUpdate worker = new WorkerUpdate(); worker.setData(data); session.doWork(worker); DbQueryGlobalResult gr = new DbQueryGlobalResult(); gr.setColumns(null); gr.setResults(null); gr.setSql(null); gr.setRows(worker.getRows()); gr.setErrors(worker.getErrors()); globalResults.add(gr); sc.setAttribute("qs", null); sc.setAttribute("type", null); sc.setAttribute("showSql", null); sc.setAttribute("globalResults", globalResults); sc.getRequestDispatcher("/admin/database_query.jsp").forward(request, response); log.debug("executeUpdate: void"); }
From source file:it.classhidra.core.controller.bsController.java
public static void service_Redirect(String redirectURI, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) { try {/*from w w w .j a v a 2 s . co m*/ String id_rtype = (String) request.getAttribute(CONST_ID_REQUEST_TYPE); if (id_rtype == null) id_rtype = CONST_REQUEST_TYPE_FORWARD; if (id_rtype.equals(CONST_REQUEST_TYPE_FORWARD)) { if (!response.isCommitted()) servletContext.getRequestDispatcher(redirectURI).forward(request, response); else servletContext.getRequestDispatcher(redirectURI).include(request, response); } else { servletContext.getRequestDispatcher(redirectURI).include(request, response); } } catch (Exception ex) { writeLog(request, "Controller generic redirect error. Session timeout."); } }
From source file:org.telscenter.sail.webapp.presentation.web.controllers.BridgeController.java
private ModelAndView handleGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String type = request.getParameter("type"); ServletContext servletContext2 = this.getServletContext(); ServletContext vlewrappercontext = servletContext2.getContext("/vlewrapper"); User user = ControllerUtil.getSignedInUser(); CredentialManager.setRequestCredentials(request, user); //get the run id String runIdString = request.getParameter("runId"); Long runId = null;//ww w . j a v a 2 s. c o m if (runIdString != null) { runId = Long.parseLong(runIdString); } Run run = null; try { if (runId != null) { //get the run object run = runService.retrieveById(runId); } } catch (ObjectNotFoundException e1) { e1.printStackTrace(); } if (type == null) { // get student data RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/getdata.html"); requestDispatcher.forward(request, response); } else if (type.equals("brainstorm")) { RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/getdata.html"); requestDispatcher.forward(request, response); } else if (type.equals("flag") || type.equals("annotation")) { // get flags /* * set the user info JSONObjects into the request so the vlewrapper servlet * has access to the teacher and classmate info */ setUserInfos(run, request); RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/annotations.html"); requestDispatcher.forward(request, response); } else if (type.equals("journal")) { RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/journaldata.html"); requestDispatcher.forward(request, response); } else if (type.equals("peerreview")) { //get the period id String periodString = request.getParameter("periodId"); Long period = null; if (periodString != null) { period = Long.parseLong(periodString); } try { /* * set the number of students in the class period for when we need * to calculate peer review opening */ Set<Workgroup> classmateWorkgroups = runService.getWorkgroups(runId, period); request.setAttribute("numWorkgroups", classmateWorkgroups.size()); } catch (ObjectNotFoundException e) { e.printStackTrace(); } RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/peerreview.html"); requestDispatcher.forward(request, response); } else if (type.equals("xlsexport")) { //set the user info into the request object setUserInfos(run, request); //set the project path into the request object setProjectPath(run, request); RequestDispatcher requestDispatcher = vlewrappercontext.getRequestDispatcher("/getxls.html"); requestDispatcher.forward(request, response); } else if (type.equals("ideaBasket")) { handleIdeaBasket(request, response); } else if (type.equals("studentAssetManager")) { handleStudentAssetManager(request, response); } else if (type.equals("viewStudentAssets")) { handleViewStudentAssets(request, response); } else if (type.equals("xmppAuthenticate")) { // check if this portal is xmpp enabled first String isXMPPEnabled = portalProperties.getProperty("isXMPPEnabled"); if (isXMPPEnabled != null && Boolean.valueOf(isXMPPEnabled)) { handleWISEXMPPAuthenticate(request, response); } } return null; }
From source file:it.classhidra.core.controller.bsController.java
public static void service_ErrorRedirect(String id_action, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) { String redirectURI = ""; try {/*from w w w . java2 s.co m*/ if (getAction_config() == null || getAction_config().getError() == null || getAction_config().getError().equals("")) redirectURI = "/error.jsp"; else redirectURI = getAction_config().getError(); if (!response.isCommitted()) servletContext.getRequestDispatcher(redirectURI).forward(request, response); else servletContext.getRequestDispatcher(redirectURI).include(request, response); } catch (Exception ex) { writeLog(request, "Controller generic redirect error. Action: [" + id_action + "] URI: [" + redirectURI + "]"); } }
From source file:com.openkm.servlet.PasswordResetServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String username = WebUtils.getString(request, "username"); ServletContext sc = getServletContext(); User usr = null;/*from w w w .ja va2s . c o m*/ if (Config.USER_PASSWORD_RESET) { try { usr = AuthDAO.findUserByPk(username); } catch (DatabaseException e) { log.error(getServletName() + " User '" + username + "' not found"); } if (usr != null) { try { String password = RandomStringUtils.randomAlphanumeric(8); AuthDAO.updateUserPassword(username, password); MailUtils.sendMessage(usr.getEmail(), usr.getEmail(), "Password reset", "Your new password is: " + password + "<br/>" + "To change it log in and then go to 'Tools' > 'Preferences' > 'User Configuration'."); sc.setAttribute("resetOk", usr.getEmail()); response.sendRedirect("password_reset.jsp"); } catch (MessagingException e) { log.error(e.getMessage(), e); sc.setAttribute("resetFailed", "Failed to send the new password by email"); response.sendRedirect("password_reset.jsp"); } catch (DatabaseException e) { log.error(e.getMessage(), e); sc.setAttribute("resetFailed", "Failed reset the user password"); response.sendRedirect("password_reset.jsp"); } } else { sc.setAttribute("resetFailed", "Invalid user name provided"); sc.getRequestDispatcher("/password_reset.jsp").forward(request, response); } } else { sc.getRequestDispatcher("/login.jsp").forward(request, response); } }
From source file:it.classhidra.core.controller.bsController.java
public static void service_AuthRedirect(String id_action, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) { String redirectURI = ""; try {/*from w w w. j a v a2 s . c om*/ if (getAction_config() == null || getAction_config().getAuth_error() == null || getAction_config().getAuth_error().equals("")) { redirectURI = ""; } else redirectURI = getAction_config().getAuth_error(); if (!response.isCommitted()) servletContext.getRequestDispatcher(redirectURI).forward(request, response); else servletContext.getRequestDispatcher(redirectURI).include(request, response); } catch (Exception ex) { writeLog(request, "Controller authentication error. Action: [" + id_action + "] URI: [" + redirectURI + "]"); } }
From source file:br.bireme.web.AuthenticationServlet.java
/** * Processes requests for both HTTP// w w w . j a va 2 s.c om * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding(CODEC); final String username = request.getParameter("email"); final String password = request.getParameter("password"); final String lang = request.getParameter("lang"); final ServletContext context = getServletContext(); final HttpSession session = request.getSession(); final ResourceBundle messages = Tools.getMessages(lang); boolean isAccountsWorking = true; RequestDispatcher dispatcher; session.removeAttribute("collCenter"); session.removeAttribute("user"); if (isAccountsWorking) { if ((username == null) || (username.isEmpty()) || (password == null) || (password.isEmpty())) { response.sendRedirect( "index.jsp?lang=" + lang + "&errMsg=" + messages.getString("login_is_required")); return; } try { final Authentication auth = new Authentication(context.getInitParameter("accounts_host")); final JSONObject user = auth.getUser(username, password); Set<String> centerIds = auth.getCenterIds(user); //if (auth.isAuthenticated(user) && (centerIds != null)) { if (auth.isAuthenticated(user)) { if (centerIds == null) { centerIds = new HashSet<String>(); } centerIds.add(auth.getColCenter(user)); // cc may not belong to a net (it not appear in centerIds) session.setAttribute("user", username); // Login user. session.setAttribute("centerIds", centerIds); dispatcher = context.getRequestDispatcher("/CenterFilterServlet?lang=" + lang); } else { session.removeAttribute("user"); session.removeAttribute("centerIds"); dispatcher = context.getRequestDispatcher( "/index.jsp?lang=" + lang + "&errMsg=" + messages.getString("authentication_failed")); } dispatcher.forward(request, response); } catch (Exception ex) { dispatcher = context.getRequestDispatcher("/index.jsp?lang=" + lang + "&errMsg=" + messages.getString("exception_found") + "<br/><br/>" + ex.getMessage()); dispatcher.forward(request, response); } } else { final Set<String> ccs = new HashSet<String>(); ccs.add("PE1.1"); ccs.add("BR1.1"); dispatcher = context.getRequestDispatcher("/CenterFilterServlet?lang=" + lang); session.setAttribute("user", username); // Login user. session.setAttribute("centerIds", ccs); dispatcher.forward(request, response); } }
From source file:com.openkm.servlet.admin.DbRepositoryViewServlet.java
private void list(String uuid, String path, HttpServletRequest request, HttpServletResponse response) throws RepositoryException, PathNotFoundException, DatabaseException, ServletException, IOException, ParseException {//from w w w . j a v a2 s .c om log.debug("list({}, {})", new Object[] { request, response }); String stats = WebUtils.getString(request, "stats"); ContentInfo ci = null; if (uuid == null || uuid.isEmpty()) { path = "/" + Repository.ROOT; uuid = NodeBaseDAO.getInstance().getUuidFromPath(path); } // Respository stats calculation if (!stats.equals("")) { if (stats.equals("0")) { request.getSession().removeAttribute("stats"); } else { request.getSession().setAttribute("stats", true); } } /* * if (request.getSession().getAttribute("stats") != null && node.isNodeType(Folder.TYPE)) { * try { * ci = OKMFolder.getInstance().getContentInfo(null, path); * } catch (AccessDeniedException e) { * log.warn(e.getMessage(), e); * } catch (com.openkm.core.RepositoryException e) { * log.warn(e.getMessage(), e); * } catch (PathNotFoundException e) { * log.warn(e.getMessage(), e); * } catch (DatabaseException e) { * log.warn(e.getMessage(), e); * } * } */ // Activity log UserActivity.log(PrincipalUtils.getUser(), "ADMIN_REPOSITORY_LIST", uuid, path, null); ServletContext sc = getServletContext(); if (!Config.ROOT_NODE_UUID.equals(uuid)) { NodeBase node = NodeBaseDAO.getInstance().findByPk(uuid); sc.setAttribute("node", node); sc.setAttribute("nodeType", getNodeType(node)); sc.setAttribute("properties", getProperties(uuid)); sc.setAttribute("contentInfo", ci); sc.setAttribute("depth", PathUtils.getDepth(path)); if (node instanceof NodeDocument) { sc.setAttribute("locked", ((NodeDocument) node).isLocked()); sc.setAttribute("history", NodeDocumentVersionDAO.getInstance().findByParent(uuid)); sc.setAttribute("text", ((NodeDocument) node).getText()); sc.setAttribute("textExtracted", ((NodeDocument) node).isTextExtracted()); sc.setAttribute("mimeType", ((NodeDocument) node).getMimeType()); } } else { sc.setAttribute("depth", 0); } sc.setAttribute("breadcrumb", createBreadcrumb(path)); sc.setAttribute("children", getChildren(uuid)); sc.getRequestDispatcher("/admin/db_repository_list.jsp").forward(request, response); log.debug("list: void"); }
From source file:com.openkm.servlet.admin.DatabaseQueryServlet.java
/** * Execute Hibernate query/*from w ww . j a v a2s.com*/ */ private void executeHibernate(Session session, String qs, boolean showSql, ServletContext sc, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, HibernateException, DatabaseException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { StringTokenizer st = new StringTokenizer(qs, "\n\r"); List<DbQueryGlobalResult> globalResults = new ArrayList<DbQueryGlobalResult>(); // For each query line while (st.hasMoreTokens()) { String tk = st.nextToken().trim(); if (tk.toUpperCase().startsWith("--") || tk.equals("") || tk.equals("\r")) { // Is a comment, so ignore it } else { if (tk.endsWith(";")) { tk = tk.substring(0, tk.length() - 1); } globalResults.add(executeHQL(session, tk, showSql, null)); } } sc.setAttribute("exception", null); sc.setAttribute("showSql", showSql); sc.setAttribute("globalResults", globalResults); sc.getRequestDispatcher("/admin/database_query.jsp").forward(request, response); }