List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:pivotal.au.se.gemfirexdweb.controller.CreateSchemaController.java
@RequestMapping(value = "/createschema", method = RequestMethod.POST) public String createSchemaAction(@ModelAttribute("schemaAttribute") NewSchema schemaAttribute, 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 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 Schema"); model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key"))); String schema = schemaAttribute.getSchemaName(); logger.debug("New Schema name = " + schema); // perform some action here with what we have String submit = request.getParameter("pSubmit"); if (submit != null) { // build create HDFS Store SQL StringBuffer createSchema = new StringBuffer(); createSchema.append("CREATE SCHEMA "); if (!checkIfParameterEmpty(request, "authorizationSchema")) { createSchema.append("AUTHORIZATION " + schemaAttribute.getAuthorizationSchema() + " \n"); } else { createSchema.append(schema + " \n"); } if (!checkIfParameterEmpty(request, "serverGroups")) { createSchema.append("DEFAULT SERVER GROUPS (" + schemaAttribute.getServerGroups() + ") \n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating Schema as -> " + createSchema.toString()); result = GemFireXDWebDAOUtil.runCommand(createSchema.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); model.addAttribute("chosenSchema", schemaAttribute.getAuthorizationSchema()); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create Schema SQL as follows as -> " + createSchema.toString()); model.addAttribute("sql", createSchema.toString()); model.addAttribute("chosenSchema", schemaAttribute.getAuthorizationSchema()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, schemaAttribute.getSchemaName())); ServletOutputStream out = response.getOutputStream(); out.println(createSchema.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/create-schema.jsp return "create-schema"; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.RegistryService.java
@Override public void service(ServletConfig config, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String servicePath = request.getRequestURI(); if (request.getRequestURI().startsWith(request.getContextPath())) servicePath = request.getRequestURI().substring(request.getContextPath().length()); String[] cmd = servicePath.trim().split("/+"); if (cmd.length < 2) { emit404(request, response);/* ww w . j a v a 2 s. c om*/ return; } String action = cmd[2]; if (ACTION_ENGINE_REGISTRATION.equals(action)) { String eng_uri = request.getParameter("enguri"); String pilot_uri = request.getParameter("piloturi"); if (eng_uri == null || eng_uri.trim().isEmpty()) { response.getWriter().print("error"); LOG.info("Erroneous registration: engine='" + eng_uri + "', pilot='" + pilot_uri + "'"); } else { IZone assignedZone = null; Configuration conf = (Configuration) config.getServletContext().getAttribute("configuration"); for (IZone zone : conf.getZoneSet()) { if (zone.getZoneEngineUrl() != null && eng_uri.equals(zone.getZoneEngineUrl())) { assignedZone = zone; break; } } @SuppressWarnings("unchecked") Map<String, IRegistrationData> regdata = (Map<String, IRegistrationData>) config.getServletContext() .getAttribute("regdata"); if (pilot_uri == null || pilot_uri.trim().isEmpty()) { // No sensors available, which is OK. This is a central engine. LOG.info("Sucessful registration: central engine='" + eng_uri + "'"); regdata.put(eng_uri.trim(), new RegData(eng_uri, null, null, null, null, assignedZone)); @SuppressWarnings("unchecked") Set<String> centralEngines = (Set<String>) config.getServletContext() .getAttribute("centralEngines"); centralEngines.add(eng_uri.trim()); } else { LOG.info("Sucessful registration: engine='" + eng_uri + "', pilot='" + pilot_uri + "'"); LOG.info("Retrieving way-point list:"); List<IWayPoint> wayPointList = null; try { wayPointList = WayPointQueryService.getWayPointList(pilot_uri); for (IWayPoint p : wayPointList) LOG.info("Waypoint: " + p); } catch (ParseException e) { LOG.error("Error at retrieving way-point list", e); } LOG.info("Retrieving available sensors:"); SensorProxy sensorProxy = new SensorProxy(); sensorProxy.setPilotUrl(pilot_uri); Set<String> sensors = null; Map<String, String> pilotConfig = null; try { sensors = sensorProxy.getAvailableSensors(); for (String sensor : sensors) { LOG.info("Sensor: " + sensor); } pilotConfig = sensorProxy.getPilotConfig(); LOG.info("Pilot configuration: " + pilotConfig); } catch (ParseException e) { LOG.error("Error at retrieving available sensors", e); } regdata.put(eng_uri.trim(), new RegData(eng_uri, pilot_uri, wayPointList, sensors, pilotConfig, assignedZone)); } response.getWriter().print("ok"); File registryFile = (File) config.getServletContext().getAttribute("registryFile"); RegistryPersistence.storeRegistry(registryFile, regdata); } return; } else { LOG.error("Can not handle: " + servicePath); emit404(request, response); return; } }
From source file:com.camel.framework.tag.CssLinkTag.java
/** * ????Coogle Minify?,??/* w w w . j a v a2s.com*/ */ private void parse() { StringBuffer sb = new StringBuffer(); // jspJspWriter JspWriter out = this.pageContext.getOut(); // environmentConfig.xml?????value String resourcesUrl = null; if (null != ConfigParamMap.getConfigParamMap()) { ConfigParamMap.getValue(IEnvironmentConfigBasic.RESOURCES_URL); } // ?null??URL if (null == resourcesUrl) { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); resourcesUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); } /** * ?environmentConfig.xml?resources_merger * ?jscss?,Ygoogle minify N? */ String resourcesMerger = null; if (null != ConfigParamMap.getConfigParamMap()) { ConfigParamMap.getValue(IEnvironmentConfigBasic.RESOURCES_MERGER); } if (ITagBasic.USER_MINIFY_CODE.equals(resourcesMerger)) { // ?? Minify?link?? parseToMinifyStyle(sb, resourcesUrl, out); } else { // path????? // ??? Minify?script?? parseToConventionalStyle(sb, resourcesUrl, out); } }
From source file:com.glaf.core.util.RequestUtils.java
public static String getServiceUrl(HttpServletRequest request) { String scheme = request.getScheme(); String serviceUrl = scheme + "://" + request.getServerName(); if (request.getServerPort() != 80) { serviceUrl += ":" + request.getServerPort(); }/*w w w. j av a 2 s.c o m*/ if (!"/".equals(request.getContextPath())) { serviceUrl += request.getContextPath(); } return serviceUrl; }
From source file:com.pagecrumb.proxy.ProxyServlet.java
@SuppressWarnings("unchecked") protected void handleRequest(HttpServletRequest req, HttpServletResponse resp, boolean isPost) throws ServletException, IOException { log.info("contextPath=" + req.getContextPath()); // Setup the headless browser WebClient webClient = new WebClient(); webClient.setWebConnection(new UrlFetchWebConnection(webClient)); HttpParams httpParams = new BasicHttpParams(); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); // GAE constraint // Originally, the design was to use HttpClient to execute methods // Now, it uses WebClient ClientConnectionManager connectionManager = new GAEConnectionManager(); HttpClient httpclient = new DefaultHttpClient(connectionManager, httpParams); StringBuffer sb = new StringBuffer(); log.info(getClass().toString() + " " + "URI Component=" + req.getRequestURI()); log.info(getClass().toString() + " " + "URL Component=" + req.getRequestURL()); if (req.getQueryString() != null) { //sb.append("?" + req.getQueryString()); String s1 = Util.decodeURIComponent(req.getQueryString()); log.info(getClass().toString() + " " + "QueryString=" + req.getQueryString()); target = req.getQueryString();/*from ww w. jav a 2 s .c om*/ int port = req.getServerPort(); String domain = req.getServerName(); URL url = new URL(SCHEME, domain, port, target); /* HtmlPage page = webClient.getPage(target); //gae hack because its single threaded webClient.getJavaScriptEngine().pumpEventLoop(PUMP_TIME); pageString = page.asXml(); */ } sb.append(target); log.info(getClass().toString() + " " + "sb=" + sb.toString()); HttpRequestBase targetRequest = null; if (isPost) { HttpPost post = new HttpPost(sb.toString()); Enumeration<String> paramNames = req.getParameterNames(); String paramName = null; List<NameValuePair> params = new ArrayList<NameValuePair>(); while (paramNames.hasMoreElements()) { paramName = paramNames.nextElement(); params.add(new BasicNameValuePair(paramName, req.getParameterValues(paramName)[0])); } post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); targetRequest = post; } else { HttpGet get = new HttpGet(sb.toString()); targetRequest = get; } // log.info("Request Headers"); // Enumeration<String> headerNames = req.getHeaderNames(); // String headerName = null; // while(headerNames.hasMoreElements()){ // headerName = headerNames.nextElement(); // targetRequest.addHeader(headerName, req.getHeader(headerName)); // log.info(headerName + " : " + req.getHeader(headerName)); // } HttpResponse targetResponse = httpclient.execute(targetRequest); HttpEntity entity = targetResponse.getEntity(); // Send the Response InputStream input = entity.getContent(); OutputStream output = resp.getOutputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output)); String line = reader.readLine(); /* * To use the HttpClient instead the HtmlUnit's WebClient: */ while (line != null) { writer.write(line + "\n"); line = reader.readLine(); } // Scanner scanner = new Scanner(pageString); // while (scanner.hasNextLine()) { // String s = scanner.nextLine(); // writer.write(s + "\n"); // } if (webClient != null) { webClient.closeAllWindows(); } reader.close(); writer.close(); httpclient.getConnectionManager().shutdown(); }
From source file:cn.guoyukun.spring.web.interceptor.SetCommonDataInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (isExclude(request)) { return true; }/*from ww w. j av a 2 s . co m*/ if (request.getAttribute(Constants.CONTEXT_PATH) == null) { request.setAttribute(Constants.CONTEXT_PATH, request.getContextPath()); } if (request.getAttribute(Constants.CURRENT_URL) == null) { request.setAttribute(Constants.CURRENT_URL, extractCurrentURL(request, true)); } if (request.getAttribute(Constants.NO_QUERYSTRING_CURRENT_URL) == null) { request.setAttribute(Constants.NO_QUERYSTRING_CURRENT_URL, extractCurrentURL(request, false)); } if (request.getAttribute(Constants.BACK_URL) == null) { request.setAttribute(Constants.BACK_URL, extractBackURL(request)); } return true; }
From source file:com.test.springmvc.springmvcproject.BookDetailsController.java
@RequestMapping(value = "/{bookId}/get", method = RequestMethod.GET) public void getBook(HttpServletRequest request, HttpServletResponse response, @PathVariable Integer bookId, @ModelAttribute("bookModel") BookBean bean) { try {/*from w w w .j a va 2 s.c om*/ final BookBean found = searchService.findById(bookId); final String url_totale_to_book = request.getServletContext() .getRealPath(found.getEmplacement().replaceAll(request.getContextPath(), "")); try { InputStream stream = new FileInputStream(url_totale_to_book); System.out.println(stream.toString()); response.setHeader("Content-Disposition", "attachment;filename=" + found.getNomLivre()); IOUtils.copy(stream, response.getOutputStream()); } catch (FileNotFoundException e) { } catch (IOException e) { } } catch (NoDataFoundException e) { } }
From source file:com.eryansky.modules.disk.web.FileKindEditorController.java
private Map<String, Object> successResponse(HttpServletRequest request, String filename, String url) { Map<String, Object> map = Maps.newHashMap(); map.put("error", 0); map.put("url", request.getContextPath() + "/" + url); map.put("title", filename); return map;/* w w w .ja va2 s . c o m*/ }
From source file:org.tsm.concharto.web.discuss.DiscussController.java
@SuppressWarnings("unchecked") @Override// ww w . j ava 2s . c om protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors, Map controlModel) throws Exception { Long discussId = ServletRequestUtils.getLongParameter(request, PARAM_DISCUSSION_ID); if (discussId != null) { //Redirect Event event = eventDao.findByDiscussionId(discussId); String redirect = request.getContextPath() + '/' + getFormView() + ".htm?id=" + event.getId(); return new ModelAndView(new RedirectView(redirect, true)); } return new ModelAndView(getFormView(), errors.getModel()); }
From source file:pivotal.au.se.gemfirexdweb.controller.JMXController.java
@RequestMapping(value = "/jmxmbeans", method = RequestMethod.GET) public String showJMXMbeans(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 . ja 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; } } } UserPref userPref = (UserPref) session.getAttribute("prefs"); String jolokiaURL = userPref.getJolokiaURL(); String mbeanName = request.getParameter("mbeanName"); if (mbeanName != null) { logger.debug("Received request to show Mbean Attributes"); logger.debug("mbeanName = " + mbeanName); String refreshTime = request.getParameter("refreshTime"); if (refreshTime == null) { refreshTime = "none"; } logger.debug("refresh time : " + refreshTime); Map<String, Object> attributes = getMbeanAttributeValues(mbeanName, jolokiaURL); model.addAttribute("refreshTime", refreshTime); model.addAttribute("mbeanName", mbeanName); model.addAttribute("mbeanMap", attributes); model.addAttribute("records", attributes.size()); // This will resolve to /WEB-INF/jsp/viewmbean.jsp return "viewmbean"; } else { logger.debug("Received request to show JMX Mbeans for cluster"); logger.debug("jolokiaURL = " + jolokiaURL); List<String> mbeanNames = searchMbeans("", jolokiaURL); model.addAttribute("mbeanNames", mbeanNames); model.addAttribute("records", mbeanNames.size()); // This will resolve to /WEB-INF/jsp/showmbeans.jsp return "showmbeans"; } }