List of usage examples for org.springframework.core.io FileSystemResource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:org.dd4t.core.util.IOUtils.java
public static String convertFileToString(String filePath) { FileSystemResource resource = new FileSystemResource(filePath); File file = resource.getFile(); byte[] buffer = new byte[(int) file.length()]; try {// w w w. j ava2s . c o m resource.getInputStream().read(buffer); resource.getInputStream().close(); return new String(buffer); } catch (IOException e) { return null; } }
From source file:fi.helsinki.moodi.config.OodiConfig.java
private KeyStore oodiKeyStore(String keystoreLocation, char[] keystorePassword) throws Exception { KeyStore keyStore = KeyStore.getInstance("PKCS12"); FileSystemResource keystoreFile = new FileSystemResource(new File(keystoreLocation)); keyStore.load(keystoreFile.getInputStream(), keystorePassword); return keyStore; }
From source file:com.lm.lic.manager.controller.HandangoWithdrawLicHandler.java
@SuppressWarnings("unchecked") public boolean verifyHgoRequest(HttpServletRequest request) { boolean valid = false; com.hhc.client.CertificateReader reader = new com.hhc.client.CertificateReader(); java.security.PublicKey publicKey = null; try {/*from ww w .j a v a 2 s. c om*/ String pathToClassesDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); int index = pathToClassesDir.indexOf("/WEB-INF/"); String fullPath = pathToClassesDir.substring(0, index + "/WEB-INF/".length()) + "certificates/Handango.cert"; FileSystemResource fr = new FileSystemResource(fullPath); publicKey = reader.getPublicKey(fr.getInputStream()); } catch (IOException e) { e.printStackTrace(); return false; } catch (GeneralSecurityException e) { e.printStackTrace(); return false; } com.hhc.client.Authenticator authenticator = new com.hhc.client.Authenticator(publicKey); try { if (authenticator.verify(request.getParameterMap())) { valid = true; } else { valid = false; } } catch (AuthenticatorException e) { e.printStackTrace(); return false; } return valid; }
From source file:com.lm.lic.manager.controller.MobiHandWithdrawLicHandler.java
@SuppressWarnings("unchecked") public boolean verifyMobiHandRequest(HttpServletRequest request) { boolean valid = false; com.hhc.client.CertificateReader reader = new com.hhc.client.CertificateReader(); java.security.PublicKey publicKey = null; try {// w w w . ja va 2 s . com String pathToClassesDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); int index = pathToClassesDir.indexOf("/WEB-INF/"); String fullPath = pathToClassesDir.substring(0, index + "/WEB-INF/".length()) + "certificates/Handango.cert"; FileSystemResource fr = new FileSystemResource(fullPath); publicKey = reader.getPublicKey(fr.getInputStream()); } catch (IOException e) { e.printStackTrace(); return false; } catch (GeneralSecurityException e) { e.printStackTrace(); return false; } com.hhc.client.Authenticator authenticator = new com.hhc.client.Authenticator(publicKey); try { if (authenticator.verify(request.getParameterMap())) { valid = true; } else { valid = false; } } catch (AuthenticatorException e) { e.printStackTrace(); return false; } valid = true; return valid; }
From source file:com.lm.lic.manager.controller.YouparkWithdrawLicHandler.java
@SuppressWarnings("unchecked") public boolean verifyYouparkRequest(HttpServletRequest request) { boolean valid = false; com.hhc.client.CertificateReader reader = new com.hhc.client.CertificateReader(); java.security.PublicKey publicKey = null; try {/*w w w . ja va 2s. co m*/ String pathToClassesDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); int index = pathToClassesDir.indexOf("/WEB-INF/"); String fullPath = pathToClassesDir.substring(0, index + "/WEB-INF/".length()) + "certificates/Handango.cert"; FileSystemResource fr = new FileSystemResource(fullPath); publicKey = reader.getPublicKey(fr.getInputStream()); } catch (IOException e) { e.printStackTrace(); return false; } catch (GeneralSecurityException e) { e.printStackTrace(); return false; } com.hhc.client.Authenticator authenticator = new com.hhc.client.Authenticator(publicKey); try { if (authenticator.verify(request.getParameterMap())) { valid = true; } else { valid = false; } } catch (AuthenticatorException e) { e.printStackTrace(); return false; } valid = true; return valid; }
From source file:com.lm.lic.manager.controller.PocketGearWithdrawLicHandler.java
@SuppressWarnings("unchecked") public boolean verifyPocketGearRequest(HttpServletRequest request) { boolean valid = false; com.hhc.client.CertificateReader reader = new com.hhc.client.CertificateReader(); java.security.PublicKey publicKey = null; try {/*from w w w .ja v a2 s . c o m*/ String pathToClassesDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); int index = pathToClassesDir.indexOf("/WEB-INF/"); String fullPath = pathToClassesDir.substring(0, index + "/WEB-INF/".length()) + "certificates/Handango.cert"; FileSystemResource fr = new FileSystemResource(fullPath); publicKey = reader.getPublicKey(fr.getInputStream()); } catch (IOException e) { e.printStackTrace(); return false; } catch (GeneralSecurityException e) { e.printStackTrace(); return false; } com.hhc.client.Authenticator authenticator = new com.hhc.client.Authenticator(publicKey); try { if (authenticator.verify(request.getParameterMap())) { valid = true; } else { valid = false; } } catch (AuthenticatorException e) { e.printStackTrace(); return false; } valid = true; return valid; }
From source file:com.sivalabs.jcart.admin.web.controllers.ProductController.java
@GetMapping(value = "/products/images/{productId}") public void showProductImage(@PathVariable String productId, HttpServletRequest request, HttpServletResponse response) {/*from www .j av a 2 s . c o m*/ try { FileSystemResource file = new FileSystemResource(IMAGES_DIR + productId + ".jpg"); response.setContentType("image/jpg"); copy(file.getInputStream(), response.getOutputStream()); response.flushBuffer(); } catch (IOException e) { log.error(e.getMessage(), e); } }
From source file:coral.reef.web.ReefController.java
@RequestMapping(value = "/images/bg") public void bg(HttpServletResponse httpResponse) throws IOException { Resource res = appContext.getResource("classpath:CORAL_bg.png"); File f = res.getFile();// w w w .j a va 2 s. c om FileSystemResource fr = new FileSystemResource(f); String type = servletContext.getMimeType(f.getAbsolutePath()); httpResponse.setContentType(type); IOUtils.copy(fr.getInputStream(), httpResponse.getOutputStream()); }
From source file:coral.reef.web.ReefController.java
@RequestMapping(value = "/assets/**") public void icon(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException { String path = ((String) httpRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)); Resource res = appContext.getResource("classpath:" + path); File f = res.getFile();/*from w w w .j a va2 s .co m*/ FileSystemResource fr = new FileSystemResource(f); String type = servletContext.getMimeType(f.getAbsolutePath()); httpResponse.setContentType(type); IOUtils.copy(fr.getInputStream(), httpResponse.getOutputStream()); }
From source file:coral.reef.web.ReefToCoralController.java
@RequestMapping(value = "/{exp}/**") public void dispatchToExpHandler(@PathVariable("exp") String exp, HttpSession httpSession, HttpServletResponse httpResponse, HttpServletRequest httpRequest) throws IOException { httpResponse.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"); httpResponse.setHeader("Pragms", "no-cache"); httpResponse.setHeader("Expires", "0"); Integer id = (Integer) httpSession.getAttribute(REEF_ID); String sessionExp = (String) httpSession.getAttribute(REEF_EXP); String path = ((String) httpRequest.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .substring(exp.length() + 2); ReefHandler handler = service.handler(exp); if (path.startsWith(handler.startMarker())) { if (sessionExp != null || id != null) { // TODO remove old client (?) }/*from w w w . j a v a2 s. c o m*/ String query = httpRequest.getQueryString(); query = (query == null) ? "" : query; id = handler.addClient(null); String result = handler.process(id, path, query); result = service.replaceHost(exp, result); httpSession.setAttribute(REEF_ID, id); httpSession.setAttribute(REEF_EXP, exp); httpResponse.setContentType("text/html"); httpResponse.getWriter().println(result); } else if (path.startsWith(handler.refreshMarker())) { if (sessionExp != null || id != null) { // TODO remove old client (?) } String query = httpRequest.getQueryString(); query = (query == null) ? "" : query; id = Integer.parseInt(query.replaceAll("[^\\d]", "")); id = handler.addClient(id); String result = handler.process(id, "", "?refreshid=" + id); result = service.replaceHost(exp, result); httpSession.setAttribute(REEF_ID, id); httpSession.setAttribute(REEF_EXP, exp); httpResponse.setContentType("text/html"); httpResponse.getWriter().println(result); } else if (path.startsWith(handler.processMarker()) && sessionExp != null && sessionExp.equals(exp)) { /* * PROCESS */ String query = httpRequest.getQueryString(); query = (query == null) ? "" : query; String result = handler.process(id, path, query); result = service.replaceHost(exp, result); httpResponse.setContentType("text/html"); httpResponse.getWriter().println(result); } else if (path.startsWith(handler.serverMarker())) { /* * SERVER */ String result = handler.server(path.substring(handler.serverMarker().length() + 1), httpRequest.getParameterMap()); result = service.replaceHost(exp, result); httpResponse.setContentType("text/html"); httpResponse.getWriter().println(result); } else if (handler.getResMap().containsKey(path)) { /* * RESOURCE */ File f = handler.getResMap().get(path); FileSystemResource fr = new FileSystemResource(f); String type = servletContext.getMimeType(path); httpResponse.setContentType(type); IOUtils.copy(fr.getInputStream(), httpResponse.getOutputStream()); } else { // no match = no response => should propagate to next controller System.out.println(path + " - " + handler.getResMap()); } }