List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:it.cilea.osd.jdyna.web.controller.SimpleDynaController.java
protected Integer extractEntityId(HttpServletRequest request) { String path = request.getPathInfo().substring(1); // remove first / String[] splitted = path.split("/"); request.setAttribute("authority", splitted[1]); Integer id = getRealPersistentIdentifier(splitted[1]); request.setAttribute("entityID", id); return id;//from w ww. j a va 2s . c o m }
From source file:edu.isi.karma.webserver.ExtractSpatialInformationFromWikimapiaServiceHandler.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("Request URL: " + request.getRequestURI()); logger.debug("Request Path Info: " + request.getPathInfo()); logger.debug("Request Param: " + request.getQueryString()); String jsonOutput = null;//from w w w . j a va 2s . co m String lon_min = request.getParameter("lon_min"); String lat_min = request.getParameter("lat_min"); String lon_max = request.getParameter("lon_max"); String lat_max = request.getParameter("lat_max"); //String type = request.getParameter("type"); String url = "&lon_min=" + lon_min + "&lat_min=" + lat_min + "&lon_max=" + lon_max + "&lat_max=" + lat_max; try { System.out.println("Please Wait for extracting information from Web Site..."); outputToOSM(url); System.out.println("You have got the OSM File at location: /tmp/GET_WIKIMAPIA.xml ..."); } catch (SQLException e) { e.printStackTrace(); } System.out.println("Opening PostGis Connection..."); openConnection(); System.out.println("Creating the CSV file from OSM file..."); CreateWikimapiaInformation cwi = new CreateWikimapiaInformation(this.connection, this.osmFile_path); System.out.println("Extracting the Street Information from OSM file..."); jsonOutput = cwi.createWikiMapiaTable(); System.out.println("You have created the CSV file for STREETS at location:/tmp/buildings_geo.csv"); /*Close connection*/ this.closeConnection(this.connection); /*Output the JSON content to Web Page*/ response.setCharacterEncoding("UTF8"); PrintWriter pw = response.getWriter(); response.setContentType(MimeType.APPLICATION_JSON); pw.write(jsonOutput); return; }
From source file:com.jjtree.servelet.Paragraphs.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/* w w w .j av a 2 s . co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); String pathInfo = request.getPathInfo(); String[] path = pathInfo.split("/"); int singleParagraphID = Integer.parseInt(path[1]); try { // Register JDBC driver Class.forName(JConstant.JDBC_DRIVER); // Open a connection conn = DriverManager.getConnection(JConstant.DB_URL, JConstant.USER, JConstant.PASSWORD); // Execute SQL query stmt = conn.createStatement(); String sql; sql = "SELECT * FROM JParagraph WHERE paragraphID = " + singleParagraphID; ResultSet rs = stmt.executeQuery(sql); // Extract data from result set while (rs.next()) { //Retrieve by column name int paragraphID = rs.getInt("paragraphID"); int articleID = rs.getInt("articleID"); int position = rs.getInt("position"); String type = rs.getString("type"); String content = rs.getString("content"); JSONObject paragraph = new JSONObject(); paragraph.put("paragraphID", paragraphID); paragraph.put("articleID", articleID); paragraph.put("position", position); paragraph.put("type", type); paragraph.put("content", content); PrintWriter writer = response.getWriter(); writer.print(paragraph); writer.flush(); } // Clean-up environment rs.close(); stmt.close(); conn.close(); } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { //finally block used to close resources try { if (stmt != null) { stmt.close(); } } catch (SQLException se2) { } // nothing we can do try { if (conn != null) { conn.close(); } } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try }
From source file:io.apiman.gateway.platforms.servlet.GatewayServlet.java
/** * Returns the path to the resource./*from www . j a v a 2 s . c o m*/ * @param request */ protected String getDestination(HttpServletRequest request) { String path = request.getPathInfo(); return path; }
From source file:nl.npcf.eav.web.EAVController.java
private String getFirstPathNode(String skip, HttpServletRequest request) { int length = skip.length(); String pathInfo = request.getPathInfo(); String path = pathInfo.substring(length); if (path.startsWith(EAVStore.PATH_SEPARATOR)) { path = path.substring(1);//w w w . ja v a2 s . c o m } int slash = path.indexOf(EAVStore.PATH_SEPARATOR); if (slash >= 0) { path = path.substring(0, slash); } return path; }
From source file:edu.harvard.i2b2.fhirserver.ws.FileServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get requested file by path info. String requestedFile = request.getPathInfo(); if (requestedFile.equals("/")) requestedFile = "/index.html"; logger.trace("Got request:" + requestedFile); logger.trace("basePath:" + this.basePath); logger.trace("ffp:" + basePath + requestedFile); // Check if file is actually supplied to the request URI. //if (requestedFile == null) { // Do your thing if the file is not supplied to the request URI. // Throw an exception, or send 404, or show default/warning page, or just ignore it. // response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404. //return;//from w ww.j a v a 2 s.com //} // Decode the file name (might contain spaces and on) and prepare file object. URL url = new URL(basePath + requestedFile); logger.trace("url:" + url); File file = FileUtils.toFile(url); logger.trace("searching for file:" + file.getAbsolutePath()); // Check if file actually exists in filesystem. if (!file.exists()) { // Do your thing if the file appears to be non-existing. // Throw an exception, or send 404, or show default/warning page, or just ignore it. response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404. return; } // Get content type by filename. String contentType = getServletContext().getMimeType(file.getName()); // If content type is unknown, then set the default value. // For all content types, see: http://www.w3schools.com/media/media_mimeref.asp // To add new content types, add new mime-mapping entry in web.xml. if (contentType == null) { contentType = "application/text"; } // Init servlet response. response.reset(); response.setBufferSize(DEFAULT_BUFFER_SIZE); response.setContentType(contentType); response.setHeader("Content-Length", String.valueOf(file.length())); // response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\""); // Prepare streams. BufferedInputStream input = null; BufferedOutputStream output = null; try { // Open streams. input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE); output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE); // Write file contents to response. byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } } finally { // Gently close streams. close(output); close(input); } }
From source file:com.liferay.portal.servlet.ImageServlet.java
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { String path = req.getPathInfo(); // The image id may be passed in as image_id, img_id, or i_id String imageId = ParamUtil.getString(req, "image_id"); if (Validator.isNull(imageId)) { imageId = ParamUtil.getString(req, "img_id"); if (Validator.isNull(imageId)) { imageId = ParamUtil.getString(req, "i_id"); }/*from w ww. j ava 2s . c o m*/ } // Company Logo if (path.startsWith("/company_logo")) { if (ParamUtil.get(req, "png", false)) { imageId += ".png"; res.setContentType("image/png"); } else if (ParamUtil.get(req, "wbmp", false)) { imageId += ".wbmp"; res.setContentType("image/vnd.wap.wbmp"); } } // Image Gallery if (path.startsWith("/image_gallery")) { if (!imageId.equals(StringPool.BLANK) && !imageId.startsWith(_companyId + ".image_gallery.")) { imageId = _companyId + ".image_gallery." + imageId; if (ParamUtil.get(req, "small", false)) { imageId += ".small"; } else { imageId += ".large"; } } } // Journal Article if (path.startsWith("/journal/article")) { if (!imageId.equals(StringPool.BLANK) && !imageId.startsWith(_companyId + ".journal.article.")) { imageId = _companyId + ".journal.article." + imageId; String version = req.getParameter("version"); if (Validator.isNotNull(version)) { imageId += "." + version; } } } // Journal Template if (path.startsWith("/journal/template")) { if (!imageId.equals(StringPool.BLANK) && !imageId.startsWith(_companyId + ".journal.template.")) { imageId = _companyId + ".journal.template." + imageId; imageId += ".small"; } } // Shopping Item else if (path.startsWith("/shopping/item")) { if (!imageId.equals(StringPool.BLANK) && !imageId.startsWith(_companyId + ".shopping.item.")) { imageId = _companyId + ".shopping.item." + imageId; if (ParamUtil.get(req, "small", false)) { imageId += ".small"; } else if (ParamUtil.get(req, "medium", false)) { imageId += ".medium"; } else { imageId += ".large"; } } } Image image = ImageLocalUtil.get(imageId); if (Validator.isNull(imageId)) { _log.error("Image id should never be null or empty, path is " + req.getPathInfo()); } if (image == null) { _log.error("Image should never be null"); } else { if (Validator.isNotNull(image.getType())) { res.setContentType("image/" + image.getType()); } /*res.setHeader( "Cache-control", "max-age=" + Long.toString(Time.WEEK));*/ try { if (!res.isCommitted()) { ServletOutputStream out = res.getOutputStream(); out.write(image.getTextObj()); out.flush(); } } catch (Exception e) { Logger.error(this, e.getMessage(), e); } } }
From source file:dk.dma.msinm.user.security.SecurityConf.java
/** * Returns the request specifies the JWT authentication endpoint * @return the request specifies the JWT authentication endpoint *///from w w w . jav a 2s . c o m public boolean isJwtAuthEndpoint(HttpServletRequest request) { String uri = request.getServletPath() + StringUtils.defaultString(request.getPathInfo()); return supportsJwtAuth() && jwtAuthEndpoint != null && jwtAuthEndpoint.equals(uri); }
From source file:dk.dma.msinm.user.security.SecurityConf.java
/** * Returns the list of configured resource endpoints that matches the request * @param request the request/*from ww w .j ava2s.c o m*/ * @return the list of configured resource endpoints that matches the request */ private List<CheckedResource> getMatchingResources(HttpServletRequest request) { String uri = request.getServletPath() + StringUtils.defaultString(request.getPathInfo()); return checkedResources.stream().filter(r -> r.pattern.matcher(uri).matches()).collect(Collectors.toList()); }
From source file:com.jaspersoft.jasperserver.rest.services.RESTRole.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { try {/* w w w . j ava 2s.c om*/ String searchCriteria = restUtils.extractResourceName(SERVICE_NAME, req.getPathInfo()); WSRole role = restUtils.unmarshal(WSRole.class, req.getInputStream()); role = restUtils.populateServiceObject(role); updateRole(role, restUtils.getWSRoleSearchCriteria(searchCriteria)); restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, ""); } catch (IOException e) { throw new ServiceException(e.getLocalizedMessage()); } catch (JAXBException e) { throw new ServiceException(e.getLocalizedMessage()); } }