List of usage examples for java.util.concurrent ConcurrentHashMap keySet
KeySetView keySet
To view the source code for java.util.concurrent ConcurrentHashMap keySet.
Click Source Link
From source file:com.web.server.WarDeployer.java
/** * This method deploys the war in exploded form and configures it. * @param file//from ww w . ja v a 2s .c o m * @param customClassLoader * @param warDirectoryPath */ public void extractWar(File file, WebClassLoader customClassLoader) { StringBuffer classPath = new StringBuffer(); int numBytes; try { ConcurrentHashMap jspMap = new ConcurrentHashMap(); ZipFile zip = new ZipFile(file); ZipEntry ze = null; //String fileName=file.getName(); String directoryName = file.getName(); directoryName = directoryName.substring(0, directoryName.indexOf('.')); try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); //logger.info("file://"+warDirectoryPath+"/WEB-INF/classes/"); new WebServer().addURL(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/"), customClassLoader); //new WebServer().addURL(new URL("file://"+warDirectoryPath+"/"),customClassLoader); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String fileDirectory; Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ze = entries.nextElement(); // //System.out.println("Unzipping " + ze.getName()); String filePath = scanDirectory + "/" + directoryName + "/" + ze.getName(); if (!ze.isDirectory()) { fileDirectory = filePath.substring(0, filePath.lastIndexOf('/')); } else { fileDirectory = filePath; } // //System.out.println(fileDirectory); createDirectory(fileDirectory); if (!ze.isDirectory()) { FileOutputStream fout = new FileOutputStream(filePath); byte[] inputbyt = new byte[8192]; InputStream istream = zip.getInputStream(ze); while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) { fout.write(inputbyt, 0, numBytes); } fout.close(); istream.close(); if (ze.getName().endsWith(".jsp")) { jspMap.put(ze.getName(), filePath); } else if (ze.getName().endsWith(".jar")) { new WebServer().addURL( new URL("file:///" + scanDirectory + "/" + directoryName + "/" + ze.getName()), customClassLoader); classPath.append(filePath); classPath.append(";"); } } } zip.close(); Set jsps = jspMap.keySet(); Iterator jspIterator = jsps.iterator(); classPath.append(scanDirectory + "/" + directoryName + "/WEB-INF/classes/;"); ArrayList<String> jspFiles = new ArrayList(); //System.out.println(classPath.toString()); if (jspIterator.hasNext()) new WebServer().addURL(new URL("file:" + scanDirectory + "/temp/" + directoryName + "/"), customClassLoader); while (jspIterator.hasNext()) { String filepackageInternal = (String) jspIterator.next(); String filepackageInternalTmp = filepackageInternal; if (filepackageInternal.lastIndexOf('/') == -1) { filepackageInternal = ""; } else { filepackageInternal = filepackageInternal.substring(0, filepackageInternal.lastIndexOf('/')) .replace("/", "."); filepackageInternal = "." + filepackageInternal; } createDirectory(scanDirectory + "/temp/" + directoryName); File jspFile = new File((String) jspMap.get(filepackageInternalTmp)); String fName = jspFile.getName(); String fileNameWithoutExtension = fName.substring(0, fName.lastIndexOf(".jsp")) + "_jsp"; //String fileCreated=new JspCompiler().compileJsp((String) jspMap.get(filepackageInternalTmp), scanDirectory+"/temp/"+fileName, "com.web.server"+filepackageInternal,classPath.toString()); synchronized (customClassLoader) { String fileNameInWar = filepackageInternalTmp; jspFiles.add(fileNameInWar.replace("/", "\\")); if (fileNameInWar.contains("/") || fileNameInWar.contains("\\")) { customClassLoader.addURL("/" + fileNameInWar.replace("\\", "/"), "com.web.server" + filepackageInternal + "." + fileNameWithoutExtension); } else { customClassLoader.addURL("/" + fileNameInWar, "com.web.server" + filepackageInternal + "." + fileNameWithoutExtension); } } } if (jspFiles.size() > 0) { ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(customClassLoader); try { JspC jspc = new JspC(); jspc.setUriroot(scanDirectory + "/" + directoryName + "/"); jspc.setAddWebXmlMappings(false); jspc.setCompile(true); jspc.setOutputDir(scanDirectory + "/temp/" + directoryName + "/"); jspc.setPackage("com.web.server"); StringBuffer buffer = new StringBuffer(); for (String jspFile : jspFiles) { buffer.append(","); buffer.append(jspFile); } String jsp = buffer.toString(); jsp = jsp.substring(1, jsp.length()); System.out.println(jsp); jspc.setJspFiles(jsp); jspc.execute(); } catch (Throwable je) { je.printStackTrace(); } finally { Thread.currentThread().setContextClassLoader(oldCL); } Thread.currentThread().setContextClassLoader(customClassLoader); } try { new ExecutorServicesConstruct().getExecutorServices(serverdigester, executorServiceMap, new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "executorservices.xml"), customClassLoader); } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); } try { new MessagingClassConstruct().getMessagingClass(messagedigester, new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "messagingclass.xml"), customClassLoader, messagingClassMap); } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); } webxmldigester.setNamespaceAware(true); webxmldigester.setValidating(true); //digester.setRules(null); FileInputStream webxml = new FileInputStream( scanDirectory + "/" + directoryName + "/WEB-INF/" + "web.xml"); InputSource is = new InputSource(webxml); try { System.out.println("SCHEMA"); synchronized (webxmldigester) { //webxmldigester.set("config/web-app_2_4.xsd"); WebAppConfig webappConfig = (WebAppConfig) webxmldigester.parse(is); servletMapping.put(scanDirectory + "/" + directoryName.replace("\\", "/"), webappConfig); } webxml.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //ClassLoaderUtil.closeClassLoader(customClassLoader); } catch (FileNotFoundException e) { // TODO Auto-generated catch block //e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); } catch (Exception ex) { } }
From source file:com.web.server.WebServer.java
/** * This method forms the http response//from w w w .j a va 2 s. com * @param responseCode * @param httpHeader * @param content * @return */ private byte[] formHttpResponseHeader(int responseCode, HttpHeaderServer httpHeader, byte[] content, ConcurrentHashMap<String, HttpCookie> httpCookies) { StringBuffer buffer = new StringBuffer(); String colon = ": "; String crlf = "\r\n"; if (responseCode == 200) { buffer.append("HTTP/1.1 200 OK"); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.DATE); buffer.append(colon); buffer.append(httpHeader.getDate()); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.SERVER); buffer.append(colon); buffer.append(httpHeader.getServer()); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.CONTENT_TYPE); buffer.append(colon); buffer.append(httpHeader.getContentType()); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.CONTENT_LENGTH); buffer.append(colon); buffer.append(httpHeader.getContentLength()); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.LAST_MODIFIED); buffer.append(colon); buffer.append(httpHeader.getLastModified()); if (httpCookies != null) { Iterator<String> cookieNames = httpCookies.keySet().iterator(); HttpCookie httpCookie; for (; cookieNames.hasNext();) { String cookieName = cookieNames.next(); httpCookie = (HttpCookie) httpCookies.get(cookieName); buffer.append(crlf); buffer.append(HttpHeaderServerParamNames.SETCOOKIE); buffer.append(colon); buffer.append(httpCookie.getKey()); buffer.append("="); buffer.append(httpCookie.getValue()); if (httpCookie.getExpires() != null) { buffer.append("; "); buffer.append(HttpHeaderServerParamNames.SETCOOKIEEXPIRES); buffer.append("="); buffer.append(httpCookie.getExpires()); } } } } else if (responseCode == 404) { buffer.append("HTTP/1.1 404 Not Found"); } buffer.append(crlf); buffer.append(crlf); byte[] byt1 = buffer.toString().getBytes(); byte[] byt2 = new byte[byt1.length + content.length + crlf.length() * 2]; /////System.out.println("Header="+new String(byt1)); for (int count = 0; count < byt1.length; count++) { byt2[count] = byt1[count]; } for (int count = 0; count < content.length; count++) { byt2[count + byt1.length] = content[count]; } for (int count = 0; count < crlf.length() * 2; count++) { byt2[count + byt1.length + content.length] = (byte) crlf.charAt(count % 2); } ////System.out.println("Header with content="+new String(byt2)); /*try { buffer.append(new String(content, "UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ return byt2; }
From source file:com.web.server.SARDeployer.java
/** * This method is the implementation of the SAR deployer */// w w w .ja v a 2 s .c o m public void run() { String filePath; FileInfo fileinfoTmp; ConcurrentHashMap filePrevMap = new ConcurrentHashMap(); ConcurrentHashMap fileCurrMap = new ConcurrentHashMap(); ; FileInfo filePrevLastModified; FileInfo fileCurrLastModified; DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/sar-config.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); sardigester = serverdigesterLoader.newDigester(); while (true) { try { File file = new File(deployDirectory); File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) continue; //Long lastModified=(Long) fileMap.get(files[i].getName()); if (files[i].getName().toLowerCase().endsWith(".sar")) { filePath = files[i].getAbsolutePath(); //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".sar")); File sarDirectory = new File(filePath + "sar"); fileinfoTmp = new FileInfo(); fileinfoTmp.setFile(files[i]); fileinfoTmp.setLastModified(files[i].lastModified()); if (!sarDirectory.exists() || fileCurrMap.get(files[i].getName()) == null && filePrevMap.get(files[i].getName()) == null) { if (sarDirectory.exists()) { deleteDir(sarDirectory); } try { extractSar(files[i], sarDirectory.getAbsolutePath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("War Deployed Successfully in path: "+filePath); numberOfSarDeployed++; logger.info(files[i] + " Deployed"); sarsDeployed.add(files[i].getName()); filePrevMap.put(files[i].getName(), fileinfoTmp); } fileCurrMap.put(files[i].getName(), fileinfoTmp); } /*if(lastModified==null||lastModified!=files[i].lastModified()){ fileMap.put(files[i].getName(),files[i].lastModified()); }*/ } Set keyset = fileCurrMap.keySet(); Iterator ite = keyset.iterator(); String fileName; while (ite.hasNext()) { fileName = (String) ite.next(); //logger.info("fileName"+fileName); filePrevLastModified = (FileInfo) filePrevMap.get(fileName); fileCurrLastModified = (FileInfo) fileCurrMap.get(fileName); if (filePrevLastModified != null) //logger.info("lastmodified="+filePrevLastModified.getLastModified()); //System.out.println("prevmodified"+fileCurrLastModified.getLastModified()+""+filePrevLastModified.getLastModified()); if (fileCurrLastModified != null) { //System.out.println("prevmodified"+fileCurrLastModified.getLastModified()); } if (filePrevLastModified == null || filePrevLastModified.getLastModified() != fileCurrLastModified.getLastModified()) { filePath = fileCurrLastModified.getFile().getAbsolutePath(); //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".sar")); File sarDirectory = new File(filePath + "sar"); //logger.info("WARDIRECTORY="+warDirectory.getAbsolutePath()); if (sarDirectory.exists() && sarDirectory.isDirectory()) { deleteDir(sarDirectory); sarsDeployed.remove(fileName); numberOfSarDeployed--; } try { extractSar(fileCurrLastModified.getFile(), sarDirectory.getAbsolutePath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("War Deployed Successfully in path: "+fileCurrLastModified.getFile().getAbsolutePath()); numberOfSarDeployed++; sarsDeployed.add(fileName); logger.info(filePath + ".sar Deployed"); } } keyset = filePrevMap.keySet(); ite = keyset.iterator(); while (ite.hasNext()) { fileName = (String) ite.next(); filePrevLastModified = (FileInfo) filePrevMap.get(fileName); fileCurrLastModified = (FileInfo) fileCurrMap.get(fileName); if (fileCurrLastModified == null) { filePath = filePrevLastModified.getFile().getAbsolutePath(); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".sar")); logger.info("filePath" + filePath); File deleteDirectory = new File(filePath + "sar"); deleteDir(deleteDirectory); numberOfSarDeployed--; sarsDeployed.remove(fileName); logger.info(filePath + ".sar Undeployed"); } } filePrevMap.keySet().removeAll(filePrevMap.keySet()); filePrevMap.putAll(fileCurrMap); fileCurrMap.keySet().removeAll(fileCurrMap.keySet()); //System.out.println("filePrevMap="+filePrevMap); //System.out.println("fileCurrMap="+fileCurrMap); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); System.out.println("Sar Deployed"); } } }
From source file:com.web.server.WarDeployer.java
/** * This method is the implementation of the war deployer which frequently scans the deploy * directory and if there is a change in war redeploys and configures the map *//* w w w .j a v a 2s. c o m*/ public void run() { File file; ConcurrentHashMap filePrevMap = new ConcurrentHashMap(); ConcurrentHashMap fileCurrMap = new ConcurrentHashMap(); ; FileInfo filePrevLastModified; FileInfo fileCurrLastModified; String filePath; FileInfo fileinfoTmp; URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); warsDeployed = new CopyOnWriteArrayList(); //System.out.println("URLS="+urls[0]); WebClassLoader customClassLoader; while (true) { file = new File(scanDirectory); File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) continue; //Long lastModified=(Long) fileMap.get(files[i].getName()); if (files[i].getName().endsWith(".war")) { filePath = files[i].getAbsolutePath(); //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war")); File warDirectory = new File(filePath); fileinfoTmp = new FileInfo(); fileinfoTmp.setFile(files[i]); fileinfoTmp.setLastModified(files[i].lastModified()); if (!warDirectory.exists() || fileCurrMap.get(files[i].getName()) == null && filePrevMap.get(files[i].getName()) == null) { if (warDirectory.exists()) { deleteDir(warDirectory); } customClassLoader = new WebClassLoader(urls); synchronized (urlClassLoaderMap) { logger.info("WARDIRECTORY=" + warDirectory.getAbsolutePath()); urlClassLoaderMap.put(warDirectory.getAbsolutePath().replace("\\", "/"), customClassLoader); } extractWar(files[i], customClassLoader); //System.out.println("War Deployed Successfully in path: "+filePath); AddUrlToClassLoader(warDirectory, customClassLoader); numberOfWarDeployed++; logger.info(files[i] + " Deployed"); warsDeployed.add(files[i].getName()); filePrevMap.put(files[i].getName(), fileinfoTmp); } fileCurrMap.put(files[i].getName(), fileinfoTmp); } /*if(lastModified==null||lastModified!=files[i].lastModified()){ fileMap.put(files[i].getName(),files[i].lastModified()); }*/ } Set keyset = fileCurrMap.keySet(); Iterator ite = keyset.iterator(); String fileName; while (ite.hasNext()) { fileName = (String) ite.next(); //logger.info("fileName"+fileName); filePrevLastModified = (FileInfo) filePrevMap.get(fileName); fileCurrLastModified = (FileInfo) fileCurrMap.get(fileName); if (filePrevLastModified != null) //logger.info("lastmodified="+filePrevLastModified.getLastModified()); //System.out.println("prevmodified"+fileCurrLastModified.getLastModified()+""+filePrevLastModified.getLastModified()); if (fileCurrLastModified != null) { //System.out.println("prevmodified"+fileCurrLastModified.getLastModified()); } if (filePrevLastModified == null || filePrevLastModified.getLastModified() != fileCurrLastModified.getLastModified()) { filePath = fileCurrLastModified.getFile().getAbsolutePath(); //logger.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war")); File warDirectory = new File(filePath); //logger.info("WARDIRECTORY="+warDirectory.getAbsolutePath()); if (warDirectory.exists()) { WebClassLoader webClassLoader = (WebClassLoader) urlClassLoaderMap .get(warDirectory.getAbsolutePath().replace("\\", "/")); synchronized (executorServiceMap) { try { new ExecutorServicesConstruct().removeExecutorServices(executorServiceMap, new File(warDirectory.getAbsolutePath().replace("\\", "/") + "/WEB-INF/" + "executorservices.xml"), webClassLoader); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("executorServiceMap"+executorServiceMap); } synchronized (messagingClassMap) { try { new MessagingClassConstruct().removeMessagingClass(messagedigester, new File(warDirectory.getAbsolutePath().replace("\\", "/") + "/WEB-INF/" + "messagingclass.xml"), messagingClassMap); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("executorServiceMap" + executorServiceMap); } ClassLoaderUtil.cleanupJarFileFactory(ClassLoaderUtil.closeClassLoader(webClassLoader)); try { webClassLoader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.info("ServletMapping" + servletMapping); logger.info("warDirectory=" + warDirectory.getAbsolutePath().replace("\\", "/")); urlClassLoaderMap.remove(warDirectory.getAbsolutePath().replace("\\", "/")); WebAppConfig webAppConfig = (WebAppConfig) servletMapping .remove(warDirectory.getAbsolutePath().replace("\\", "/")); System.gc(); deleteDir(warDirectory); warsDeployed.remove(fileName); removeServletFromSessionObject(webAppConfig, warDirectory.getAbsolutePath().replace("\\", "/")); numberOfWarDeployed--; } customClassLoader = new WebClassLoader(urls); logger.info(customClassLoader); urlClassLoaderMap.put(warDirectory.getAbsolutePath().replace("\\", "/"), customClassLoader); extractWar(fileCurrLastModified.getFile(), customClassLoader); //System.out.println("War Deployed Successfully in path: "+fileCurrLastModified.getFile().getAbsolutePath()); AddUrlToClassLoader(warDirectory, customClassLoader); numberOfWarDeployed++; warsDeployed.add(fileName); logger.info(filePath + ".war Deployed"); } } keyset = filePrevMap.keySet(); ite = keyset.iterator(); while (ite.hasNext()) { fileName = (String) ite.next(); filePrevLastModified = (FileInfo) filePrevMap.get(fileName); fileCurrLastModified = (FileInfo) fileCurrMap.get(fileName); if (fileCurrLastModified == null) { filePath = filePrevLastModified.getFile().getAbsolutePath(); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war")); logger.info("filePath" + filePath); File deleteDirectory = new File(filePath); logger.info("Delete Directory" + deleteDirectory.getAbsolutePath().replace("\\", "/")); WebClassLoader webClassLoader = (WebClassLoader) urlClassLoaderMap .get(deleteDirectory.getAbsolutePath().replace("\\", "/")); ; synchronized (executorServiceMap) { try { new ExecutorServicesConstruct().removeExecutorServices(executorServiceMap, new File(deleteDirectory.getAbsolutePath().replace("\\", "/") + "/WEB-INF/" + "executorservices.xml"), webClassLoader); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("executorServiceMap"+executorServiceMap); } synchronized (messagingClassMap) { try { new MessagingClassConstruct().removeMessagingClass(messagedigester, new File(deleteDirectory.getAbsolutePath().replace("\\", "/") + "/WEB-INF/" + "messagingclass.xml"), messagingClassMap); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("executorServiceMap"+executorServiceMap); } WebAppConfig webAppConfig = (WebAppConfig) servletMapping .remove(deleteDirectory.getAbsolutePath().replace("\\", "/")); ClassLoaderUtil.cleanupJarFileFactory(ClassLoaderUtil.closeClassLoader(webClassLoader)); urlClassLoaderMap.remove(deleteDirectory.getAbsolutePath().replace("\\", "/")); logger.info("ServletMapping" + servletMapping); logger.info("warDirectory=" + deleteDirectory.getAbsolutePath().replace("\\", "/")); try { logger.info(webClassLoader); logger.info("CLASSLOADER IS CLOSED"); webClassLoader.close(); } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); } System.gc(); deleteDir(deleteDirectory); numberOfWarDeployed--; warsDeployed.remove(fileName); try { removeServletFromSessionObject(webAppConfig, deleteDirectory.getAbsolutePath().replace("\\", "/")); } catch (Exception ex) { ex.printStackTrace(); } logger.info(filePath + ".war Undeployed"); } } filePrevMap.keySet().removeAll(filePrevMap.keySet()); filePrevMap.putAll(fileCurrMap); fileCurrMap.keySet().removeAll(fileCurrMap.keySet()); //System.out.println("filePrevMap="+filePrevMap); //System.out.println("fileCurrMap="+fileCurrMap); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.app.server.WarDeployer.java
/** * This method deploys the war in exploded form and configures it. * /*from ww w. j a v a 2 s . c o m*/ * @param file * @param customClassLoader * @param warDirectoryPath */ public void extractWar(File file, ClassLoader classLoader) { StringBuffer classPath = new StringBuffer(); int numBytes; WebClassLoader customClassLoader = null; CopyOnWriteArrayList<URL> jarUrls = new CopyOnWriteArrayList<URL>(); try { ConcurrentHashMap jspMap = new ConcurrentHashMap(); ZipFile zip = new ZipFile(file); ZipEntry ze = null; // String fileName=file.getName(); String directoryName = file.getName(); directoryName = directoryName.substring(0, directoryName.indexOf('.')); try { /*ClassLoader classLoader = Thread.currentThread() .getContextClassLoader();*/ // log.info("file://"+warDirectoryPath+"/WEB-INF/classes/"); jarUrls.add(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/")); // new WebServer().addURL(new // URL("file://"+warDirectoryPath+"/"),customClassLoader); } catch (Exception e) { log.error("syntax of the URL is incorrect", e); //e1.printStackTrace(); } String fileDirectory; Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ze = entries.nextElement(); // //log.info("Unzipping " + ze.getName()); String filePath = scanDirectory + "/" + directoryName + "/" + ze.getName(); if (!ze.isDirectory()) { fileDirectory = filePath.substring(0, filePath.lastIndexOf('/')); } else { fileDirectory = filePath; } // //log.info(fileDirectory); createDirectory(fileDirectory); if (!ze.isDirectory()) { FileOutputStream fout = new FileOutputStream(filePath); byte[] inputbyt = new byte[8192]; InputStream istream = zip.getInputStream(ze); while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) { fout.write(inputbyt, 0, numBytes); } fout.close(); istream.close(); if (ze.getName().endsWith(".jsp")) { jspMap.put(ze.getName(), filePath); } else if (ze.getName().endsWith(".jar")) { jarUrls.add(new URL("file:///" + scanDirectory + "/" + directoryName + "/" + ze.getName())); classPath.append(filePath); classPath.append(";"); } } } zip.close(); Set jsps = jspMap.keySet(); Iterator jspIterator = jsps.iterator(); classPath.append(scanDirectory + "/" + directoryName + "/WEB-INF/classes;"); jarUrls.add(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/;")); ArrayList<String> jspFiles = new ArrayList(); // log.info(classPath.toString()); if (jspIterator.hasNext()) { jarUrls.add(new URL("file:" + scanDirectory + "/temp/" + directoryName + "/")); customClassLoader = new WebClassLoader(jarUrls.toArray(new URL[jarUrls.size()]), classLoader); while (jspIterator.hasNext()) { String filepackageInternal = (String) jspIterator.next(); String filepackageInternalTmp = filepackageInternal; if (filepackageInternal.lastIndexOf('/') == -1) { filepackageInternal = ""; } else { filepackageInternal = filepackageInternal.substring(0, filepackageInternal.lastIndexOf('/')) .replace("/", "."); filepackageInternal = "." + filepackageInternal; } createDirectory(scanDirectory + "/temp/" + directoryName); File jspFile = new File((String) jspMap.get(filepackageInternalTmp)); String fName = jspFile.getName(); String fileNameWithoutExtension = fName.substring(0, fName.lastIndexOf(".jsp")) + "_jsp"; // String fileCreated=new JspCompiler().compileJsp((String) // jspMap.get(filepackageInternalTmp), // scanDirectory+"/temp/"+fileName, // "com.app.server"+filepackageInternal,classPath.toString()); synchronized (customClassLoader) { String fileNameInWar = filepackageInternalTmp; jspFiles.add(fileNameInWar.replace("/", "\\")); if (fileNameInWar.contains("/") || fileNameInWar.contains("\\")) { customClassLoader.addURL("/" + fileNameInWar.replace("\\", "/"), "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "." + fileNameWithoutExtension); } else { customClassLoader.addURL("/" + fileNameInWar, "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "." + fileNameWithoutExtension); } } } } else { customClassLoader = new WebClassLoader(jarUrls.toArray(new URL[jarUrls.size()]), classLoader); } String filePath = file.getAbsolutePath(); // log.info("filePath"+filePath); filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war")); urlClassLoaderMap.put(filePath.replace("\\", "/"), customClassLoader); if (jspFiles.size() > 0) { ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); //Thread.currentThread().setContextClassLoader(customClassLoader); String classPathBefore = ""; try { JspCompiler jspc = new JspCompiler(); jspc.setUriroot(scanDirectory + "/" + directoryName); jspc.setAddWebXmlMappings(false); jspc.setListErrors(false); jspc.setCompile(true); jspc.setOutputDir(scanDirectory + "/temp/" + directoryName + "/"); jspc.setPackage("com.app.server"); StringBuffer buffer = new StringBuffer(); for (String jspFile : jspFiles) { buffer.append(","); buffer.append(jspFile); } String jsp = buffer.toString(); jsp = jsp.substring(1, jsp.length()); //log.info(jsp); classPathBefore = System.getProperty("java.class.path"); System.setProperty("java.class.path", System.getProperty("java.class.path") + ";" + classPath.toString().replace("/", "\\")); //jspc.setClassPath(System.getProperty("java.class.path")+";"+classPath.toString().replace("/", "\\")); jspc.setJspFiles(jsp); jspc.initCL(customClassLoader); jspc.execute(); //jspc.closeClassLoader(); //jspc.closeClassLoader(); } catch (Throwable je) { log.error("Error in compiling the jsp page", je); //je.printStackTrace(); } finally { System.setProperty("java.class.path", classPathBefore); //Thread.currentThread().setContextClassLoader(oldCL); } //Thread.currentThread().setContextClassLoader(customClassLoader); } try { File execxml = new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "executorservices.xml"); if (execxml.exists()) { new ExecutorServicesConstruct().getExecutorServices(serverdigester, executorServiceMap, execxml, customClassLoader); } } catch (Exception e) { log.error("error in getting executor services ", e); // e.printStackTrace(); } try { File messagingxml = new File( scanDirectory + "/" + directoryName + "/WEB-INF/" + "messagingclass.xml"); if (messagingxml.exists()) { new MessagingClassConstruct().getMessagingClass(messagedigester, messagingxml, customClassLoader, messagingClassMap); } } catch (Exception e) { log.error("Error in getting the messaging classes ", e); // e.printStackTrace(); } webxmldigester.setNamespaceAware(true); webxmldigester.setValidating(true); // digester.setRules(null); FileInputStream webxml = new FileInputStream( scanDirectory + "/" + directoryName + "/WEB-INF/" + "web.xml"); InputSource is = new InputSource(webxml); try { //log.info("SCHEMA"); synchronized (webxmldigester) { // webxmldigester.set("config/web-app_2_4.xsd"); WebAppConfig webappConfig = (WebAppConfig) webxmldigester.parse(is); servletMapping.put(scanDirectory + "/" + directoryName.replace("\\", "/"), webappConfig); } webxml.close(); } catch (Exception e) { log.error("Error in pasrsing the web.xml", e); //e.printStackTrace(); } //customClassLoader.close(); // ClassLoaderUtil.closeClassLoader(customClassLoader); } catch (Exception ex) { log.error("Error in Deploying war " + file.getAbsolutePath(), ex); } }
From source file:com.app.server.WarDeployer.java
public void extractWar(FileObject fileObject, WebClassLoader customClassLoader, StandardFileSystemManager fsManager) { int numBytes; try {/*from ww w .j ava 2 s .com*/ String directoryName = fileObject.getName().getBaseName(); fileObject = fsManager.resolveFile("jar:" + fileObject.toString() + "!/"); StringBuffer classPath = new StringBuffer(); ConcurrentHashMap<String, String> jspMap = new ConcurrentHashMap<String, String>(); ArrayList<String> libs = new ArrayList<String>(); // String fileName=file.getName(); directoryName = directoryName.substring(0, directoryName.indexOf('.')); /*try { ((VFSClassLoader)customClassLoader.getParent()). // log.info("file://"+warDirectoryPath+"/WEB-INF/classes/"); customClassLoader.addURL(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/") ); // new WebServer().addURL(new // URL("file://"+warDirectoryPath+"/"),customClassLoader); } catch (Exception e) { log.error("syntax of the URL is incorrect", e); //e1.printStackTrace(); }*/ Vector<URL> libVec = unpack(fileObject, new File(scanDirectory + "/" + directoryName), fsManager, jspMap); //FileObject[] libraries=((VFSClassLoader)customClassLoader.getParent()).getFileObjects(); libVec.add(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/")); //URL[] liburl=new URL[libraries.length]; for (URL lib : libVec) { customClassLoader.addURL(lib); } //WebClassLoader web=new WebClassLoader(libVec.toArray(new URL[libVec.size()]),getClass().getClassLoader()); System.out.println(jspMap); System.out.println(libs); /*customClassLoader.addURL(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/") );*/ /*String fileDirectory; Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ze = entries.nextElement(); // //log.info("Unzipping " + ze.getName()); String filePath = scanDirectory + "/" + directoryName + "/" + ze.getName(); if (!ze.isDirectory()) { fileDirectory = filePath.substring(0, filePath.lastIndexOf('/')); } else { fileDirectory = filePath; } // //log.info(fileDirectory); createDirectory(fileDirectory); if (!ze.isDirectory()) { FileOutputStream fout = new FileOutputStream(filePath); byte[] inputbyt = new byte[8192]; InputStream istream = zip.getInputStream(ze); while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) { fout.write(inputbyt, 0, numBytes); } fout.close(); istream.close(); if (ze.getName().endsWith(".jsp")) { jspMap.put(ze.getName(), filePath); } else if (ze.getName().endsWith(".jar")) { customClassLoader.addURL(new URL("file:///" + scanDirectory + "/" + directoryName + "/" + ze.getName())); classPath.append(filePath); classPath.append(";"); } } } zip.close();*/ Set jsps = jspMap.keySet(); Iterator jspIterator = jsps.iterator(); /*classPath.append(scanDirectory + "/" + directoryName + "/WEB-INF/classes/;");*/ ArrayList<String> jspFiles = new ArrayList(); // log.info(classPath.toString()); if (jspIterator.hasNext()) { /*customClassLoader=new WebClassLoader(new URL[]{new URL("file:" + scanDirectory + "/temp/" + directoryName + "/")},customClassLoader);*/ customClassLoader.addURL(new URL("file:" + scanDirectory + "/temp/" + directoryName + "/")); urlClassLoaderMap.put(serverConfig.getDeploydirectory() + "/" + directoryName, customClassLoader); } else { urlClassLoaderMap.put(serverConfig.getDeploydirectory() + "/" + directoryName, customClassLoader); } while (jspIterator.hasNext()) { String filepackageInternal = (String) jspIterator.next(); String filepackageInternalTmp = filepackageInternal; if (filepackageInternal.lastIndexOf('/') == -1) { filepackageInternal = ""; } else { filepackageInternal = filepackageInternal.substring(0, filepackageInternal.lastIndexOf('/')) .replace("/", "."); filepackageInternal = "." + filepackageInternal; } createDirectory(scanDirectory + "/temp/" + directoryName); File jspFile = new File((String) jspMap.get(filepackageInternalTmp)); String fName = jspFile.getName(); String fileNameWithoutExtension = fName.substring(0, fName.lastIndexOf(".jsp")) + "_jsp"; // String fileCreated=new JspCompiler().compileJsp((String) // jspMap.get(filepackageInternalTmp), // scanDirectory+"/temp/"+fileName, // "com.app.server"+filepackageInternal,classPath.toString()); synchronized (customClassLoader) { String fileNameInWar = filepackageInternalTmp; jspFiles.add(fileNameInWar.replace("/", "\\")); if (fileNameInWar.contains("/") || fileNameInWar.contains("\\")) { customClassLoader.addURL("/" + fileNameInWar.replace("\\", "/"), "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "." + fileNameWithoutExtension); } else { customClassLoader.addURL("/" + fileNameInWar, "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "." + fileNameWithoutExtension); } } } if (jspFiles.size() > 0) { ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); //Thread.currentThread().setContextClassLoader(customClassLoader); JspCompiler jspc = null; try { jspc = new JspCompiler(); jspc.setUriroot(scanDirectory + "/" + directoryName); jspc.setAddWebXmlMappings(false); jspc.setCompile(true); //jspc.setClassPath("d:/deploy/StrutsProj/WEB-INF/classes/"); jspc.setOutputDir(scanDirectory + "/temp/" + directoryName + "/"); jspc.setPackage("com.app.server"); StringBuffer buffer = new StringBuffer(); for (String jspFile : jspFiles) { buffer.append(","); buffer.append(jspFile); } String jsp = buffer.toString(); jsp = jsp.substring(1, jsp.length()); //log.info(jsp); jspc.setJspFiles(jsp); //jspc.init(); jspc.initCL(customClassLoader); jspc.execute(); //jspc.closeClassLoader(); } catch (Throwable je) { log.error("Error in compiling the jsp page", je); //je.printStackTrace(); } finally { //jspc.closeClassLoader(); //Thread.currentThread().setContextClassLoader(oldCL); } //Thread.currentThread().setContextClassLoader(customClassLoader); } //System.out.println(customClassLoader.loadClass("org.apache.struts.action.ActionForm")); try { File execxml = new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "executorservices.xml"); if (execxml.exists()) { new ExecutorServicesConstruct().getExecutorServices(serverdigester, executorServiceMap, execxml, customClassLoader); } } catch (Exception e) { log.error("error in getting executor services ", e); // e.printStackTrace(); } try { File messagingxml = new File( scanDirectory + "/" + directoryName + "/WEB-INF/" + "messagingclass.xml"); if (messagingxml.exists()) { new MessagingClassConstruct().getMessagingClass(messagedigester, messagingxml, customClassLoader, messagingClassMap); } } catch (Exception e) { log.error("Error in getting the messaging classes ", e); // e.printStackTrace(); } webxmldigester.setNamespaceAware(true); webxmldigester.setValidating(true); // digester.setRules(null); FileInputStream webxml = new FileInputStream( scanDirectory + "/" + directoryName + "/WEB-INF/" + "web.xml"); InputSource is = new InputSource(webxml); try { //log.info("SCHEMA"); synchronized (webxmldigester) { // webxmldigester.set("config/web-app_2_4.xsd"); WebAppConfig webappConfig = (WebAppConfig) webxmldigester.parse(is); servletMapping.put(scanDirectory + "/" + directoryName.replace("\\", "/"), webappConfig); } webxml.close(); } catch (Exception e) { log.error("Error in pasrsing the web.xml", e); //e.printStackTrace(); } // ClassLoaderUtil.closeClassLoader(customClassLoader); } catch (Exception ex) { log.error("Error in Deploying war " + fileObject.getName().getURI(), ex); } }
From source file:diffhunter.Indexer.java
public void Make_Index(Database hashdb, String file_name, String read_gene_location) throws FileNotFoundException, IOException { Set_Parameters();//from w ww . ja va 2 s . c o m //System.out.print("Sasa"); ConcurrentHashMap<String, Map<Integer, Integer>> dic_gene_loc_count = new ConcurrentHashMap<>(); ArrayList<String> lines_from_bed_file = new ArrayList<>(); BufferedReader br = new BufferedReader(new FileReader(file_name)); String line = br.readLine(); List<String> toks = Arrays.asList(line.split("\t")); lines_from_bed_file.add(line); String last_Seen_chromosome = toks.get(0).replace("chr", ""); line = br.readLine(); lines_from_bed_file.add(line); toks = Arrays.asList(line.split("\t")); String new_chromosome = toks.get(0).replace("chr", ""); while (((line = br.readLine()) != null) || lines_from_bed_file.size() > 0) { if (line != null) { toks = Arrays.asList(line.split("\t")); new_chromosome = toks.get(0).replace("chr", ""); } // process the line. if (line == null || !new_chromosome.equals(last_Seen_chromosome)) { System.out.println("Processing chromosome" + "\t" + last_Seen_chromosome); last_Seen_chromosome = new_chromosome; lines_from_bed_file.parallelStream().forEach(content -> { List<String> inner_toks = Arrays.asList(content.split("\t")); //WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING WARNINNG WARNING WARNING //STRAND column count should be changed. String strand = inner_toks.get(5); String chromosome_ = inner_toks.get(0).replace("chr", ""); if (!dic_Loc_gene.get(strand).containsKey(chromosome_)) { return; } Integer start_loc = Integer.parseInt(inner_toks.get(1)); Integer end_loc = Integer.parseInt(inner_toks.get(2)); List<Interval<String>> res__ = dic_Loc_gene.get(strand).get(chromosome_).getIntervals(start_loc, end_loc); //IntervalTree<String> pot_gene_name=new IntervalTree<>(res__); // for (int z = 0; z < pot_gene_name.Intervals.Count; z++) //{ for (int z = 0; z < res__.size(); z++) { dic_gene_loc_count.putIfAbsent(res__.get(z).getData(), new HashMap<>()); String gene_symbol = res__.get(z).getData(); Integer temp_gene_start_loc = dic_genes.get(gene_symbol).start_loc; Integer temp_gene_end_loc = dic_genes.get(gene_symbol).end_loc; if (start_loc < temp_gene_start_loc) { start_loc = temp_gene_start_loc; } if (end_loc > temp_gene_end_loc) { end_loc = temp_gene_end_loc; } synchronized (dic_synchrinzer_genes.get(gene_symbol)) { for (int k = start_loc; k <= end_loc; k++) { Integer value_inside = 0; value_inside = dic_gene_loc_count.get(gene_symbol).get(k); dic_gene_loc_count.get(gene_symbol).put(k, value_inside == null ? 1 : (value_inside + 1)); } } } }); /* List<string> keys_ = dic_gene_loc_count.Keys.ToList(); List<string> alt_keys = new List<string>();// dic_gene_loc_count.Keys.ToList(); for (int i = 0; i < keys_.Count; i++) { Dictionary<int, int> dicccc_ = new Dictionary<int, int>(); dic_gene_loc_count[keys_[i]] = new Dictionary<int, int>(dic_gene_loc_count[keys_[i]].Where(x => x.Value >= 2).ToDictionary(x => x.Key, x => x.Value)); if (dic_gene_loc_count[keys_[i]].Count == 0) { dic_gene_loc_count.TryRemove(keys_[i], out dicccc_); continue; } hashdb.Put(Get_BDB(keys_[i]), Get_BDB_Dictionary(dic_gene_loc_count[keys_[i]])); alt_keys.Add(keys_[i]); dic_gene_loc_count.TryRemove(keys_[i], out dicccc_); }*/ ArrayList<String> keys_ = new ArrayList<>(dic_gene_loc_count.keySet()); ArrayList<String> alt_keys = new ArrayList<>(); for (int i = 0; i < keys_.size(); i++) { //LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>(dic_gene_loc_count.get(keys_.get(i))); LinkedHashMap<Integer, Integer> tmep_map = new LinkedHashMap<>(); /*tmep_map = */ dic_gene_loc_count.get(keys_.get(i)).entrySet().stream().filter(p -> p.getValue() >= 2) .sorted(Comparator.comparing(E -> E.getKey())) .forEach((entry) -> tmep_map.put(entry.getKey(), entry.getValue()));//.collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue())); if (tmep_map.isEmpty()) { dic_gene_loc_count.remove(keys_.get(i)); continue; } //Map<Integer, Integer> tmep_map1 = new LinkedHashMap<>(); //tmep_map1=sortByKey(tmep_map); //tmep_map.entrySet().stream().sorted(Comparator.comparing(E -> E.getKey())).forEach((entry) -> tmep_map1.put(entry.getKey(), entry.getValue())); //BerkeleyDB_Box box=new BerkeleyDB_Box(); hashdb.put(null, BerkeleyDB_Box.Get_BDB(keys_.get(i)), BerkeleyDB_Box.Get_BDB_Dictionary(tmep_map)); alt_keys.add(keys_.get(i)); dic_gene_loc_count.remove(keys_.get(i)); //dic_gene_loc_count.put(keys_.get(i),tmep_map); } hashdb.sync(); int a = 1111; /* hashdb.Sync(); File.AppendAllLines("InputDB\\" + Path.GetFileNameWithoutExtension(file_name) + "_genes.txt", alt_keys); //total_lines_processed_till_now += lines_from_bed_file.Count; //worker.ReportProgress(total_lines_processed_till_now / count_); lines_from_bed_file.Clear(); if (!reader.EndOfStream) { lines_from_bed_file.Add(_line_); } last_Seen_chromosome = new_choromosome;*/ lines_from_bed_file.clear(); if (line != null) { lines_from_bed_file.add(line); } Path p = Paths.get(file_name); file_name = p.getFileName().toString(); BufferedWriter output = new BufferedWriter(new FileWriter((Paths .get(read_gene_location, FilenameUtils.removeExtension(file_name) + ".txt").toString()), true)); for (String alt_key : alt_keys) { output.append(alt_key); output.newLine(); } output.close(); /*if (((line = br.readLine()) != null)) { lines_from_bed_file.add(line); toks=Arrays.asList(line.split("\t")); new_chromosome=toks.get(0).replace("chr", ""); }*/ //last_Seen_chromosome=new_chromosome; } else if (new_chromosome.equals(last_Seen_chromosome)) { lines_from_bed_file.add(line); } } br.close(); hashdb.sync(); hashdb.close(); }