List of usage examples for javax.servlet.http HttpServletRequest getLocalPort
public int getLocalPort();
From source file:org.telscenter.sail.webapp.presentation.web.controllers.teacher.RegisterTeacherController.java
/** * On submission of the signup form, a user is created and saved to the data * store.//from www . ja va2 s. c o m * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) */ @Override protected synchronized ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { String domain = "http://" + request.getServerName(); String domainWithPort = domain + ":" + request.getLocalPort(); String referrer = request.getHeader("referer"); String registerUrl = "/webapp/teacher/registerteacher.html"; String updateAccountInfoUrl = "/webapp/teacher/management/updatemyaccountinfo.html"; if (referrer.contains(domain + registerUrl) || referrer.contains(domainWithPort + registerUrl) || referrer.contains(domain + updateAccountInfoUrl) || referrer.contains(domainWithPort + updateAccountInfoUrl)) { TeacherAccountForm accountForm = (TeacherAccountForm) command; TeacherUserDetails userDetails = (TeacherUserDetails) accountForm.getUserDetails(); if (accountForm.isNewAccount()) { try { userDetails.setDisplayname(userDetails.getFirstname() + " " + userDetails.getLastname()); userDetails.setEmailValid(true); User createdUser = this.userService.createUser(userDetails); // send email to new teacher if email server is configured properly NewAccountEmailService newAccountEmailService = new NewAccountEmailService(createdUser, request.getLocale()); Thread thread = new Thread(newAccountEmailService); thread.start(); } catch (DuplicateUsernameException e) { errors.rejectValue("username", "error.duplicate-username", new Object[] { userDetails.getUsername() }, "Duplicate Username."); return showForm(request, response, errors); } } else { User user = userService.retrieveUserByUsername(userDetails.getUsername()); TeacherUserDetails teacherUserDetails = (TeacherUserDetails) user.getUserDetails(); teacherUserDetails.setCity(userDetails.getCity()); teacherUserDetails.setCountry(userDetails.getCountry()); teacherUserDetails.setCurriculumsubjects(userDetails.getCurriculumsubjects()); teacherUserDetails.setEmailAddress(userDetails.getEmailAddress()); teacherUserDetails.setSchoollevel(userDetails.getSchoollevel()); teacherUserDetails.setSchoolname(userDetails.getSchoolname()); teacherUserDetails.setState(userDetails.getState()); teacherUserDetails.setDisplayname(userDetails.getDisplayname()); teacherUserDetails.setEmailValid(true); userService.updateUser(user); // update user in session request.getSession().setAttribute(User.CURRENT_USER_SESSION_KEY, user); } ModelAndView modelAndView = new ModelAndView(getSuccessView()); modelAndView.addObject(USERNAME_KEY, userDetails.getUsername()); modelAndView.addObject(DISPLAYNAME_KEY, userDetails.getDisplayname()); return modelAndView; } else { response.sendError(HttpServletResponse.SC_FORBIDDEN); return null; } }
From source file:org.sipfoundry.voicemail.ManagementServlet.java
public void doIt(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SipxIvrConfiguration ivrConfig = (SipxIvrConfiguration) request .getAttribute(SipxIvrServletHandler.IVR_CONFIG_ATTR); String method = request.getMethod().toUpperCase(); String pathInfo = request.getPathInfo(); // this service can be accessed only internally if (ivrConfig.getHttpPort() != request.getLocalPort()) { response.sendError(403); // Send 403 Forbidden return;/*from ww w. ja va 2 s. com*/ } // make sure backup dir exists File backupDir = new File(ivrConfig.getBackupPath()); if (!backupDir.exists()) { backupDir.mkdir(); } if (pathInfo.endsWith("restore/log")) { if (method.equals(METHOD_GET)) { response.setContentType("text/plain"); OutputStream responseOutputStream = null; try { responseOutputStream = response.getOutputStream(); File log = new File(ivrConfig.getLogDirectory(), "sipx-restore.log"); if (log.exists()) { IOUtils.copy(new FileReader(log), responseOutputStream); } } catch (Exception e) { LOG.error("Failed to retrieve restore log" + e.getMessage()); response.sendError(500); } finally { IOUtils.closeQuietly(responseOutputStream); } } else { response.sendError(405); } } }
From source file:org.wise.portal.presentation.web.controllers.teacher.TeacherAccountController.java
/** * When the session is expired, send teacher back to form page. *//*w ww . ja v a2s .co m*/ @ExceptionHandler(HttpSessionRequiredException.class) public ModelAndView handleRegisterTeacherSessionExpired(HttpServletRequest request) { ModelAndView mav = new ModelAndView(); String domain = ControllerUtil.getBaseUrlString(request); String domainWithPort = domain + ":" + request.getLocalPort(); String referrer = request.getHeader("referer"); //get the context path e.g. /wise String contextPath = request.getContextPath(); String registerUrl = contextPath + "/teacher/join"; String updateAccountInfoUrl = contextPath + "/teacher/management/updatemyaccountinfo.html"; if (referrer != null && (referrer.contains(domain + registerUrl) || referrer.contains(domainWithPort + registerUrl))) { // if teacher was on register page, have them re-fill out the form. mav.setView(new RedirectView(registerUrl)); } else if (referrer != null && (referrer.contains(domain + updateAccountInfoUrl) || referrer.contains(domainWithPort + updateAccountInfoUrl))) { // if teacher was on update account page, redirect them back to home page mav.setView(new RedirectView(contextPath + "/index.html")); } else { // if teacher was on any other page, redirect them back to home page mav.setView(new RedirectView(contextPath + "/index.html")); } return mav; }
From source file:org.wise.portal.presentation.web.controllers.teacher.RegisterTeacherController.java
/** * On submission of the signup form, a user is created and saved to the data * store./* w ww . jav a 2 s .co m*/ * @param accountForm the model object that contains values for the page to use when rendering the view * @param bindingResult the object used for validation in which errors will be stored * @param request the http request object * @param model the object that contains values to be displayed on the page * @return the path of the view to display */ @RequestMapping(method = RequestMethod.POST) protected String onSubmit(@ModelAttribute("teacherAccountForm") TeacherAccountForm accountForm, BindingResult bindingResult, HttpServletRequest request, Model model) { String view = formView; String domain = ControllerUtil.getBaseUrlString(request); String domainWithPort = domain + ":" + request.getLocalPort(); String referrer = request.getHeader("referer"); //get the context path e.g. /wise String contextPath = request.getContextPath(); String registerUrl = contextPath + "/teacher/registerteacher.html"; String updateAccountInfoUrl = contextPath + "/teacher/management/updatemyaccountinfo.html"; if (referrer.contains(domain + registerUrl) || referrer.contains(domainWithPort + registerUrl) || referrer.contains(domain + updateAccountInfoUrl) || referrer.contains(domainWithPort + updateAccountInfoUrl)) { TeacherUserDetails userDetails = (TeacherUserDetails) accountForm.getUserDetails(); //set the sign up date userDetails.setSignupdate(Calendar.getInstance().getTime()); //validate the form teacherAccountFormValidator.validate(accountForm, bindingResult); if (bindingResult.hasErrors()) { //there were errors populateModel(model); view = formView; } else { //there were no errors if (accountForm.isNewAccount()) { try { userDetails.setDisplayname(userDetails.getFirstname() + " " + userDetails.getLastname()); userDetails.setEmailValid(true); User createdUser = this.userService.createUser(userDetails); // send email to new teacher if email server is configured properly NewAccountEmailService newAccountEmailService = new NewAccountEmailService(createdUser, request.getLocale()); Thread thread = new Thread(newAccountEmailService); thread.start(); } catch (DuplicateUsernameException e) { bindingResult.rejectValue("username", "error.duplicate-username", new Object[] { userDetails.getUsername() }, "Duplicate Username."); populateModel(model); view = formView; } } else { // we're updating an existing teacher's account User user = userService.retrieveUserByUsername(userDetails.getUsername()); TeacherUserDetails teacherUserDetails = (TeacherUserDetails) user.getUserDetails(); teacherUserDetails.setCity(userDetails.getCity()); teacherUserDetails.setCountry(userDetails.getCountry()); teacherUserDetails.setCurriculumsubjects(userDetails.getCurriculumsubjects()); teacherUserDetails.setEmailAddress(userDetails.getEmailAddress()); teacherUserDetails.setSchoollevel(userDetails.getSchoollevel()); teacherUserDetails.setSchoolname(userDetails.getSchoolname()); teacherUserDetails.setState(userDetails.getState()); teacherUserDetails.setDisplayname(userDetails.getDisplayname()); teacherUserDetails.setEmailValid(true); teacherUserDetails.setLanguage(userDetails.getLanguage()); String userLanguage = userDetails.getLanguage(); Locale locale = null; if (userLanguage.contains("_")) { String language = userLanguage.substring(0, userLanguage.indexOf("_")); String country = userLanguage.substring(userLanguage.indexOf("_") + 1); locale = new Locale(language, country); } else { locale = new Locale(userLanguage); } request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, locale); userService.updateUser(user); // update user in session request.getSession().setAttribute(User.CURRENT_USER_SESSION_KEY, user); } model.addAttribute(USERNAME_KEY, userDetails.getUsername()); model.addAttribute(DISPLAYNAME_KEY, userDetails.getDisplayname()); view = successView; } } else { //the request is not coming from a valid domain address so we will not allow it bindingResult.reject("Forbidden"); populateModel(model); view = formView; } return view; }
From source file:org.projectforge.web.imagecropper.ImageCropperPage.java
/** * See list of constants PARAM_* for supported parameters. * @param parameters//from ww w . ja va 2 s . c om */ public ImageCropperPage(final PageParameters parameters) { super(parameters); if (WicketUtils.contains(parameters, PARAM_SHOW_UPLOAD_BUTTON) == true) { setEnableWhiteBoardFilter(WicketUtils.getAsBoolean(parameters, PARAM_SHOW_UPLOAD_BUTTON)); } if (WicketUtils.contains(parameters, PARAM_ENABLE_WHITEBOARD_FILTER) == true) { setEnableWhiteBoardFilter(WicketUtils.getAsBoolean(parameters, PARAM_ENABLE_WHITEBOARD_FILTER)); } if (WicketUtils.contains(parameters, PARAM_LANGUAGE) == true) { setDefaultLanguage(WicketUtils.getAsString(parameters, PARAM_LANGUAGE)); } if (WicketUtils.contains(parameters, PARAM_RATIOLIST) == true) { setRatioList(WicketUtils.getAsString(parameters, PARAM_RATIOLIST)); } if (WicketUtils.contains(parameters, PARAM_DEFAULT_RATIO) == true) { setDefaultRatio(WicketUtils.getAsString(parameters, PARAM_DEFAULT_RATIO)); } if (WicketUtils.contains(parameters, PARAM_FILE_FORMAT) == true) { setFileFormat(WicketUtils.getAsString(parameters, PARAM_FILE_FORMAT)); } final ServletWebRequest req = (ServletWebRequest) this.getRequest(); final HttpServletRequest hreq = req.getContainerRequest(); String domain; if (StringUtils.isNotBlank(ConfigXml.getInstance().getDomain()) == true) { domain = ConfigXml.getInstance().getDomain(); } else { domain = hreq.getScheme() + "://" + hreq.getLocalName() + ":" + hreq.getLocalPort(); } final String url = domain + hreq.getContextPath() + "/secure/"; final StringBuffer buf = new StringBuffer(); appendVar(buf, "serverURL", url); // TODO: Wird wohl nicht mehr gebraucht. appendVar(buf, "uploadImageFileTemporaryServlet", url + "UploadImageFileTemporary"); appendVar(buf, "uploadImageFileTemporaryServletParams", "filedirectory=tempimages;filename=image"); appendVar(buf, "downloadImageFileServlet", url + "DownloadImageFile"); appendVar(buf, "downloadImageFileServletParams", "filedirectory=tempimages;filename=image"); appendVar(buf, "uploadImageFileServlet", url + "UploadImageFile"); appendVar(buf, "uploadImageFileServletParams", "filedirectory=images;filename=image;croppedname=cropped"); appendVar(buf, "upAndDownloadImageFileAsByteArrayServlet", url + "UpAndDownloadImageFileAsByteArray"); appendVar(buf, "upAndDownloadImageFileAsByteArrayServletParams", "filename=image;croppedname=cropped"); final HttpSession httpSession = hreq.getSession(); appendVar(buf, "sessionid", httpSession.getId()); appendVar(buf, "ratioList", ratioList); appendVar(buf, "defaultRatio", defaultRatio); appendVar(buf, "isUploadBtn", showUploadButton); appendVar(buf, "whiteBoardFilter", enableWhiteBoardFilter); appendVar(buf, "language", getDefaultLanguage()); appendVar(buf, "fileFormat", fileFormat); appendVar(buf, "flashFile", WicketUtils.getAbsoluteUrl("/imagecropper/MicromataImageCropper")); add(new Label("javaScriptVars", buf.toString()).setEscapeModelStrings(false)); }
From source file:siddur.solidtrust.image.ImageController.java
@RequestMapping(value = "/api/images1") public @ResponseBody Object findCarImages1(final @RequestParam("id") String id, HttpServletRequest request) { final int port = request.getLocalPort(); final String address = request.getLocalAddr(); String username = request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""; AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost());/* www . j av a2s . co m*/ ai.setUsername(username); ai.setService(Product.IMAGES.getId()); ai.setRequest(id); ImageProduct ip = null; try { ip = findImagesByLicensePlate(id, false); ai.setResponse(ip.getImage1()); } catch (Exception e) { } if (ip == null) { ai.setStatus(-1); free.save(ai); return "no data"; } free.save(ai); String portStr = port == 80 ? "" : ":" + port; String prex = "http://" + address + portStr + "/solidtrust/images/"; ImageProduct resp = new ImageProduct(); resp.setArrangement(ip.getArrangement()); resp.setBrand(ip.getBrand()); resp.setType(ip.getType()); resp.setBuildYear(ip.getBuildYear()); if (ip.getImage1() != null) { resp.setImage1(prex + ip.getImage1()); } if (ip.getImage2() != null) { resp.setImage2(prex + ip.getImage2()); } if (ip.getImage3() != null) { resp.setImage3(prex + ip.getImage3()); } if (ip.getImage4() != null) { resp.setImage4(prex + ip.getImage4()); } return resp; }
From source file:com.zimbra.cs.servlet.ZimbraServlet.java
protected boolean isRequestOnAllowedPort(HttpServletRequest request) { if (mAllowedPorts != null && mAllowedPorts.length > 0) { int incoming = request.getLocalPort(); for (int i = 0; i < mAllowedPorts.length; i++) { if (mAllowedPorts[i] == incoming) { return true; }//from ww w . jav a 2 s .com } return false; } return true; }
From source file:org.reallysqs.server.views.QueueListView.java
@SuppressWarnings("unchecked") @Override//ww w.j a va 2 s . c o m protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/xml"); Map<String, Queue> queues = (Map<String, Queue>) model.get("queues"); Collection<Queue> queueList = queues.values(); ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(prelude); for (Queue queue : queueList) { outputStream.print("<QueueUrl>"); outputStream.print("http://" + request.getLocalName() + ":" + request.getLocalPort() + request.getContextPath() + request.getServletPath() + "/queues/" + queue.getName()); outputStream.print("</QueueUrl>"); } outputStream.print(epilogue); }
From source file:com.vmware.appfactory.common.base.AbstractController.java
/** * Get a full server path url including current web app context. * e.g. http(s)://(hostname)(:optional_port)/(web_context)/ * * @param request - a HttpServletRequest. * @return a server path url/*from ww w . j a v a 2 s . co m*/ */ protected String getFullContextPath(HttpServletRequest request) { if (request == null) { throw new IllegalArgumentException("request must NOT be null!"); } int port = request.getLocalPort(); final StringBuilder url = new StringBuilder(); /* http(s)://hostname */ url.append(request.getScheme()).append("://").append(request.getServerName()); if (port != 80) { /* http(s)://hostname:xxxx */ url.append(":" + port); } /* http(s)://hostname(:xxxx)/web_context/ */ url.append(request.getContextPath()).append("/"); return url.toString(); }
From source file:org.cloudifysource.rest.command.CommandManager.java
/** * Constructor takes as input the entire commands URI, held in the request * and the root object from which to begin invocation. * @param request - the commands request * @param root - the root command's object */// w w w .j ava 2 s . c o m public CommandManager(HttpServletRequest request, Object root) { final String prefix = "/admin/"; String executionPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); if (executionPath.endsWith("/")) { executionPath = executionPath.substring(0, executionPath.length() - 1); } if (!executionPath.startsWith(prefix)) { throw new IllegalArgumentException("Bad request URL " + request.getRequestURL()); } String restUrl = "http://" + request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath(); this.commandURL = restUrl + executionPath; initilizeCommandList(executionPath.substring(prefix.length()), root); }