List of usage examples for javax.servlet.http HttpServletRequest getServletContext
public ServletContext getServletContext();
From source file:com.opendesign.utils.CmnUtil.java
/** * ? ?/*from w ww . j a v a 2 s .c om*/ * * @param request * @return */ public static String getFileUploadDir(HttpServletRequest request, String subDomain) { // String realBasePath = request.getServletContext().getRealPath("/resources/km_upload"); String fileUploadDir = realBasePath + File.separator + subDomain; return fileUploadDir; }
From source file:com.opendesign.utils.CmnUtil.java
/** * ? database? path//from ww w . jav a 2 s . com * * @param request * @param file * @return * @throws IOException */ public static String getFileUploadDbPath(HttpServletRequest request, File file) throws IOException { String realRootPath = request.getServletContext().getRealPath("/"); String dbPath = file.getCanonicalPath().replace(realRootPath, "/"); dbPath = dbPath.replaceAll("\\\\", "/"); dbPath = dbPath.replaceAll("//", "/"); return dbPath; }
From source file:com.opendesign.utils.CmnUtil.java
/** * database path path /*from w ww . j a v a 2s .com*/ * * @param request * @param dbPath * @return * @throws IOException */ public static String getRealPathFromDbPath(HttpServletRequest request, String dbPath) throws IOException { String result = ""; String realRootPath = request.getServletContext().getRealPath("/"); result = realRootPath + dbPath; result = result.replaceAll("//", "/"); return result; }
From source file:org.keycloak.example.oauth.ProductDatabaseClient.java
public static List<String> getProducts(HttpServletRequest request, String accessToken) throws Failure { KeycloakSecurityContext session = (KeycloakSecurityContext) request .getAttribute(KeycloakSecurityContext.class.getName()); // The ServletOAuthClient is obtained by getting a context attribute // that is set in the Bootstrap context listener in this project. // You really should come up with a better way to initialize // and obtain the ServletOAuthClient. I actually suggest downloading the ServletOAuthClient code // and take a look how it works. You can also take a look at third-party-cdi example ServletOAuthClient oAuthClient = (ServletOAuthClient) request.getServletContext() .getAttribute(ServletOAuthClient.class.getName()); HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(UriUtils.getOrigin(request.getRequestURL().toString()) + "/database/products"); get.addHeader("Authorization", "Bearer " + accessToken); try {/*from w w w . jav a2 s .c o m*/ HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != 200) { throw new Failure(response.getStatusLine().getStatusCode()); } HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); try { return JsonSerialization.readValue(is, TypedList.class); } finally { is.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:fiftyone.mobile.detection.webapp.JavascriptProvider.java
static void sendCoreJavaScript(HttpServletRequest request, HttpServletResponse response) throws IOException { StringBuilder javascript = new StringBuilder("// Copyright 51 Degrees Mobile Experts Limited\r\n"); String fodIo = ImageOptimizer.getJavascript(request); if (fodIo != null) { javascript.append(fodIo);//from w w w .j a v a 2s . c o m } String fodBw = Bandwidth.getJavascript(request); if (fodBw != null) { javascript.append(fodBw); } String fodPo = ProfileOverride.getJavascript(request); if (fodPo != null) { javascript.append(fodPo); } sendJavaScript(request, response, WebProvider.getActiveProvider(request.getServletContext()).dataSet, javascript); }
From source file:servlet.UploadFile.java
public static Map upload(HttpServletRequest request) { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); Map map = new HashMap(); try {//from w ww . j a v a 2 s . co m // Parse the request List items = upload.parseRequest(request); Iterator iterator = items.iterator(); while (iterator.hasNext()) { FileItem item = (FileItem) iterator.next(); if (!item.isFormField()) { String fileName = item.getName(); String root = request.getServletContext().getRealPath("/"); String dir = root.replaceAll("\\\\build", "") + "/images/movie"; File folder = new File(dir); if (!folder.exists()) { folder.mkdir(); } String path = null; if (fileName != null) { path = folder + File.separator + fileName; } else { path = folder + File.separator + "default.png"; } File uploadedFile = new File(path); if (!uploadedFile.exists()) { item.write(uploadedFile); } map.put("imgPath", path); } else { map.put(item.getFieldName(), item.getString()); } } return map; } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:com.app.framework.web.mvc.ActionMap.java
public static ActionMap Init(ServletRequest request, ServletResponse response) throws IOException { ActionMap actMap = null;//from w ww . ja v a 2 s . c o m HttpServletRequest req = ((HttpServletRequest) request); String s1 = req.getContextPath(); String s2 = req.getRequestURI(); String s3 = req.getRequestURL().toString(); String fullUrl = getFullURL(req).toLowerCase(); if (fullUrl.contains(".css") || fullUrl.contains(".js") || fullUrl.contains(".html") || fullUrl.contains(".jpg") || fullUrl.contains(".png") || fullUrl.contains(".gif") || fullUrl.contains(".icon")) { return null; } Gson g = new Gson(); String requestedResource = s2.replace(s1 + "/", ""); String[] urlParts = requestedResource.split("/"); if (urlParts != null && urlParts.length >= 2) { String controller = urlParts[0]; String action = urlParts[1]; String jsonFilePath = req.getServletContext().getRealPath("/WEB-INF/action-map.json"); String json = FileUtils.readFileToString(new File(jsonFilePath), "utf-8"); Type listType = new TypeToken<Map<String, ControllerInfo>>() { }.getType(); Map<String, ControllerInfo> map = g.fromJson(json, listType); String method = req.getMethod(); if (map.containsKey(controller)) { actMap = new ActionMap(); ControllerInfo cInfo = map.get(controller); ActionInfo mInfo = cInfo.getActions().get(action).get(method); actMap.setController(cInfo.getControllerClassName()); actMap.setAction(mInfo.getMethodName()); actMap.setModel(mInfo.getModelClassName()); } } return actMap; }
From source file:org.apache.jena.fuseki.servlets.Dispatcher.java
/** * Handle an HTTP request if it is sent to a registered dataset. * * Fuseki uses dynamic dispatch, the set of registered datasets can change while * the server is running, so dispatch is driven off Fuseki system registries. * * If the request URL matches a registered dataset, process the request, and send * the response.//from w ww. j a va 2 s .co m * * This function is called by {@link FusekiFilter#doFilter}. * * @param request * HttpServletRequest * @param response * HttpServletResponse * @return Returns {@code true} if the request has been handled, else false (no * response sent). */ public static boolean dispatch(HttpServletRequest request, HttpServletResponse response) { // Path component of the URI, without context path String uri = ActionLib.actionURI(request); String datasetUri = ActionLib.mapActionRequestToDataset(uri); if (LogDispatch) { LOG.info("Filter: Request URI = " + request.getRequestURI()); LOG.info("Filter: Action URI = " + uri); LOG.info("Filter: Dataset URI = " + datasetUri); } if (datasetUri == null) return false; DataAccessPointRegistry registry = DataAccessPointRegistry.get(request.getServletContext()); if (!registry.isRegistered(datasetUri)) { if (LogDispatch) LOG.debug("No dispatch for '" + datasetUri + "'"); return false; } DataAccessPoint dap = registry.get(datasetUri); process(dap, request, response); return true; }
From source file:com.intouch.processor.RequestProcessor.java
public JSONObject processRequest(HttpServletRequest request) throws Exception { InputStream inputStream = request.getServletContext() .getResourceAsStream("/WEB-INF/resourse/properties/prop.properties"); Properties properties = new Properties(); properties.load(inputStream);/* www.j a v a 2s . c o m*/ Class cls = Class.forName(properties.getProperty(request.getParameter("method"))); Processor processor = (Processor) cls.newInstance(); inputStream.close(); return processor.processRequest(request.getParameterMap()); }
From source file:com.prefabsoft.osgi.virgo.snap.contact.ContactController.java
@RequestMapping("/form") public ModelAndView cat(HttpServletRequest request) throws IOException { URL host = request.getServletContext().getResource("host:/WEB-INF/sample.properties"); Properties host_props = new Properties(); if (host != null) { host_props.load(host.openStream()); }//from w ww . j a v a2s . co m URL snap = request.getServletContext().getResource("/WEB-INF/sample.properties"); Properties snap_props = new Properties(); if (snap != null) { snap_props.load(snap.openStream()); } return new ModelAndView("index").addObject("host", host_props.getProperty("some.property")) .addObject("snap", snap_props.getProperty("some.property")); }