List of usage examples for javax.servlet.http HttpSession getServletContext
public ServletContext getServletContext();
From source file:org.wso2.carbon.ui.AbstractCarbonUIAuthenticator.java
/** * /*from www. jav a2s. com*/ * @param request * @return */ private String getBackendUrl(HttpServletRequest request) { HttpSession session = request.getSession(); ServletContext servletContext = session.getServletContext(); String backendServerURL = request.getParameter("backendURL"); if (backendServerURL == null) { backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession()); } if (backendServerURL != null) { session.setAttribute(CarbonConstants.SERVER_URL, backendServerURL); } return backendServerURL; }
From source file:com.osc.edu.chapter4.customers.CustomersController.java
@RequestMapping("/updateCustomers") public String updateCustomers(@RequestParam(value = "imgFile", required = false) MultipartFile imgFile, @ModelAttribute @Valid CustomersDto customers, BindingResult results, SessionStatus status, HttpSession session) { if (results.hasErrors()) { logger.debug("results : [{}]", results); return "customers/form"; }/*from www .j a v a2 s.com*/ try { if (imgFile != null && !imgFile.getOriginalFilename().equals("")) { String fileName = imgFile.getOriginalFilename(); String destDir = session.getServletContext().getRealPath("/upload"); File dirPath = new File(destDir); if (!dirPath.exists()) { boolean created = dirPath.mkdirs(); if (!created) { throw new Exception("Fail to create a directory for movie image. [" + destDir + "]"); } } IOUtils.copy(imgFile.getInputStream(), new FileOutputStream(new File(destDir, fileName))); logger.debug("Upload file({}) saved to [{}].", fileName, destDir); } customersService.updateCustomers(customers); status.setComplete(); } catch (Exception e) { logger.debug("Exception has occurred. ", e); } return "redirect:/customers/getCustomersList.do"; }
From source file:com.wyp.module.controller.LicenseController.java
@RequestMapping("generatelicense") public void generatelicense(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws UnsupportedEncodingException, IOException { Properties properties = new Properties(); String responseJson = ""; try {/*from www.j a v a 2s . c o m*/ properties.load( session.getServletContext().getResourceAsStream("/WEB-INF/classes/citrixInfo.properties")); } catch (IOException e) { responseJson = "?citrixInfo.properties"; repsonseJsonResult(response, responseJson, "json"); return; } initProperties(properties); String address = map.get("address"); String version = map.get("version"); String oemKey = map.get("oem_key"); String secret = map.get("secret"); String sockets = map.get("sockets"); String editon = map.get("editon"); if (null == address || "".equals(address.trim())) { responseJson = "citrix webservice?"; repsonseJsonResult(response, responseJson, "json"); return; } if (null == version || "".equals(version.trim())) { responseJson = "version"; repsonseJsonResult(response, responseJson, "json"); return; } if (null == oemKey || "".equals(oemKey.trim())) { responseJson = "oem_key"; repsonseJsonResult(response, responseJson, "json"); return; } if (null == secret || "".equals(secret.trim())) { responseJson = "secret"; repsonseJsonResult(response, responseJson, "json"); return; } if (null == sockets || "".equals(sockets.trim())) { responseJson = "sockets"; repsonseJsonResult(response, responseJson, "json"); return; } if (null == editon || "".equals(editon.trim())) { responseJson = "editon"; repsonseJsonResult(response, responseJson, "json"); return; } License license = new License(); license.setName("inspur"); license.setAddress1(""); license.setAddress2("?"); license.setCity(""); license.setState("inspur"); license.setPostalcode(""); license.setCompany(""); license.setCountry(""); license.setEditon(sockets);// premiumpremium-trial license.setSockets(editon); license.setRequestUUID(UUID.randomUUID().toString()); String requestJson = assembRequestJson(license); // ?license String licenses = getCitrixLicense(requestJson); if ("".equals(licenses)) { responseJson = "?license"; repsonseJsonResult(response, responseJson, "json"); return; } if (licenses.equals("")) { getCitrixLicense(requestJson); } repsonseJsonResult(response, licenses, "text"); }
From source file:org.wso2.carbon.ui.AbstractCarbonUIAuthenticator.java
/** * /*from w w w . j a v a2 s . c om*/ * @param backendServerURL * @param session * @return * @throws AxisFault */ private LoggedUserInfoAdminStub getLoggedUserInfoAdminStub(String backendServerURL, HttpSession session) throws AxisFault { ServletContext servletContext = session.getServletContext(); ConfigurationContext configContext = (ConfigurationContext) servletContext .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); if (configContext == null) { String msg = "Configuration context is null."; log.error(msg); throw new AxisFault(msg); } return new LoggedUserInfoAdminStub(configContext, backendServerURL + "LoggedUserInfoAdmin"); }
From source file:com.osc.edu.chapter4.customers.CustomersController.java
@RequestMapping("/insertCustomers") public String insertCustomers(@RequestParam(value = "imgFile", required = false) MultipartFile imgFile, @ModelAttribute @Valid CustomersDto customers, BindingResult results, SessionStatus status, HttpSession session) { if (results.hasErrors()) { logger.debug("results : [{}]", results); return "customers/form"; }// www . j ava 2 s. c om try { if (imgFile != null && !imgFile.getOriginalFilename().equals("")) { String fileName = imgFile.getOriginalFilename(); String destDir = session.getServletContext().getRealPath("/upload"); File dirPath = new File(destDir); if (!dirPath.exists()) { boolean created = dirPath.mkdirs(); if (!created) { throw new Exception("Fail to create a directory for movie image. [" + destDir + "]"); } } IOUtils.copy(imgFile.getInputStream(), new FileOutputStream(new File(destDir, fileName))); logger.debug("Upload file({}) saved to [{}].", fileName, destDir); } customersService.insertCustomers(customers); status.setComplete(); } catch (Exception e) { logger.debug("Exception has occurred. ", e); } return "redirect:/customers/getCustomersList.do"; }
From source file:com.microsoft.aad.adal4jsample.AadController.java
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) public String getDirectoryObjects(ModelMap model, HttpServletRequest httpRequest) { HttpSession session = httpRequest.getSession(); AuthenticationResult result = (AuthenticationResult) session .getAttribute(AuthHelper.PRINCIPAL_SESSION_NAME); if (result == null) { model.addAttribute("error", new Exception("AuthenticationResult not found in session.")); return "/error"; } else {/*from www .j a va 2 s.c om*/ String data; try { data = this.getUsernamesFromGraph(result.getAccessToken(), session.getServletContext().getInitParameter("tenant")); model.addAttribute("users", data); } catch (Exception e) { model.addAttribute("error", e); return "/error"; } } return "/secure/aad"; }
From source file:org.opencron.server.controller.TerminalController.java
@RequestMapping("/upload") public void upload(HttpSession httpSession, HttpServletResponse response, String token, @RequestParam(value = "file", required = false) MultipartFile[] file, String path) { TerminalClient terminalClient = TerminalSession.get(token); boolean success = true; if (terminalClient != null) { for (MultipartFile ifile : file) { String tmpPath = httpSession.getServletContext().getRealPath("/") + "upload" + File.separator; File tempFile = new File(tmpPath, ifile.getOriginalFilename()); try { ifile.transferTo(tempFile); if (CommonUtils.isEmpty(path)) { path = "."; } else if (path.endsWith("/")) { path = path.substring(0, path.lastIndexOf("/")); }//from ww w . ja v a2s. co m terminalClient.upload(tempFile.getAbsolutePath(), path + "/" + ifile.getOriginalFilename(), ifile.getSize()); tempFile.delete(); } catch (Exception e) { success = false; } } } WebUtils.writeJson(response, success ? "true" : "false"); }
From source file:com.osc.edu.chapter4.employees.EmployeesController.java
@RequestMapping("/insertEmployees") public String insertEmployees(@RequestParam(value = "imgFile", required = false) MultipartFile imgFile, @ModelAttribute @Valid EmployeesDto employees, BindingResult results, SessionStatus status, HttpSession session) { if (results.hasErrors()) { logger.debug("results : [{}]", results); return "employees/form"; }/* w w w .j av a2s .com*/ try { if (imgFile != null && !imgFile.getOriginalFilename().equals("")) { String fileName = imgFile.getOriginalFilename(); String destDir = session.getServletContext().getRealPath("/upload"); File dirPath = new File(destDir); if (!dirPath.exists()) { boolean created = dirPath.mkdirs(); if (!created) { throw new Exception("Fail to create a directory for movie image. [" + destDir + "]"); } } IOUtils.copy(imgFile.getInputStream(), new FileOutputStream(new File(destDir, fileName))); logger.debug("Upload file({}) saved to [{}].", fileName, destDir); } employeesService.insertEmployees(employees); status.setComplete(); } catch (Exception e) { logger.debug("Exception has occurred. ", e); } return "redirect:/employees/getEmployeesList.do"; }
From source file:com.osc.edu.chapter4.employees.EmployeesController.java
@RequestMapping("/updateEmployees") public String updateEmployees(@RequestParam(value = "imgFile", required = false) MultipartFile imgFile, @ModelAttribute @Valid EmployeesDto employees, BindingResult results, SessionStatus status, HttpSession session) { if (results.hasErrors()) { logger.debug("results : [{}]", results); return "employees/form"; }/*from ww w . j a v a 2s . com*/ try { if (imgFile != null && !imgFile.getOriginalFilename().equals("")) { String fileName = imgFile.getOriginalFilename(); String destDir = session.getServletContext().getRealPath("/upload"); File dirPath = new File(destDir); if (!dirPath.exists()) { boolean created = dirPath.mkdirs(); if (!created) { throw new Exception("Fail to create a directory for movie image. [" + destDir + "]"); } } IOUtils.copy(imgFile.getInputStream(), new FileOutputStream(new File(destDir, fileName))); logger.debug("Upload file({}) saved to [{}].", fileName, destDir); } employeesService.updateEmployees(employees); status.setComplete(); } catch (Exception e) { logger.debug("Exception has occurred. ", e); } return "redirect:/employees/getEmployeesList.do"; }
From source file:org.apache.geode.modules.session.TestSessionsBase.java
/** * Test for issue #46 lastAccessedTime is not updated at the start of the request, but only at the * end.// w ww. j av a 2 s . c o m */ @Test public void testLastAccessedTime() throws Exception { Callback c = new Callback() { @Override public void call(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); // Hack to expose the session to our test context session.getServletContext().setAttribute("session", session); session.setAttribute("lastAccessTime", session.getLastAccessedTime()); try { Thread.sleep(100); } catch (InterruptedException ex) { } session.setAttribute("somethingElse", 1); request.getSession(); response.getWriter().write("done"); } }; servlet.getServletContext().setAttribute("callback", c); WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest(String.format("http://localhost:%d/test", port)); // Execute the callback req.setParameter("cmd", QueryCommand.CALLBACK.name()); req.setParameter("param", "callback"); WebResponse response = wc.getResponse(req); HttpSession session = (HttpSession) servlet.getServletContext().getAttribute("session"); Long lastAccess = (Long) session.getAttribute("lastAccessTime"); assertTrue("Last access time not set correctly: " + lastAccess.longValue() + " not <= " + session.getLastAccessedTime(), lastAccess.longValue() <= session.getLastAccessedTime()); }