📄 rewriterprocessor.java
字号:
//put the argument specifying the file (the 2nd one) to null ServiceLog serviceLog=new ServiceLog(proc,userUploadDirectory.concat(logServiceFile)); serviceLog.start(); } catch(IOException ioe){ ioe.printStackTrace(); } } //If the service is targeted for SLEE /*else if(serviceType.equalsIgnoreCase("SLEE")){ logger.info("deploying on SLEE"); //TODO: Rebundle the jar //deploy the service on SLEE String rmiSSL= "file:"+File.separatorChar+ webServerPath+File.separatorChar+"lib"+ File.separatorChar+"rmissl.rmi-adaptor.properties"; String sleeService= "file:/"+ "usr/local/rhino/examples/sip/jars/"+fileName; System.out.println("RMISSL: "+rmiSSL); System.out.println("SLEESERVICE: "+sleeService); Project project=new Project(); Target target=new Target(); target.setProject(project); RMIAdaptorAntTask remoteSLEEDeploymentTask=new RMIAdaptorAntTask(); remoteSLEEDeploymentTask.setProject(project); remoteSLEEDeploymentTask.setRmissl(rmiSSL); remoteSLEEDeploymentTask.setHostname("129.6.50.19"); remoteSLEEDeploymentTask.setPort(1199); remoteSLEEDeploymentTask.setCommand("install"); Commandline.Argument deployArg=new Commandline.Argument(); deployArg.setValue(sleeService); remoteSLEEDeploymentTask.addConfiguredArg(deployArg); remoteSLEEDeploymentTask.execute(); //activate the Service String serviceNameToActivate= "JAIN SIP Proxy Service 1.1, Open Cloud"; RMIAdaptorAntTask remoteSLEEActivateTask=new RMIAdaptorAntTask(); remoteSLEEActivateTask.setProject(project); remoteSLEEActivateTask.setRmissl(rmiSSL); remoteSLEEActivateTask.setHostname("129.6.50.19"); remoteSLEEActivateTask.setPort(1199); remoteSLEEActivateTask.setCommand("activateService"); Commandline.Argument activateArg=new Commandline.Argument(); activateArg.setValue(serviceNameToActivate); remoteSLEEActivateTask.addConfiguredArg(activateArg); remoteSLEEActivateTask.execute(); //remoteSLEEDeploymentTask.addConfiguredArg(); }*/ // successful completion service.setProcess(proc); status=REWRITTEN; } /** * Retrieve the status of the rewriting process * @return the status of the rewriting process */ public int getRewritingStatus(){ return status; } /** * Retrieve the error that happened during the rewriting process * @return the error that happened during the rewriting process */ public String getRewritingError(){ return rewriting_error; } /** * This method extracts the jar * and return the list of all the classes in the jar file * @param jarName - the name of the jar file * @param mainClass - the name of the main Class * @param safeClassLoader - the class loader which will rewrite the classes * @return the list of all the classes in the jar file */ private List extractJar( String jarName, String mainClass){ JarFile jarFile=null; List classesList=new Vector(); try{ jarFile = new JarFile(jarName); } catch(IOException ioe){ ioe.printStackTrace(); } Enumeration enum = jarFile.entries(); //for each entry of the jar while (enum.hasMoreElements()){ JarEntry entry=(JarEntry)enum.nextElement(); //we extract it extractEntry(entry,jarFile); String entryClassName=entry.getName(); //and if it's bytecode if(entryClassName.indexOf(".class")!=-1){ entryClassName=entryClassName.substring(0,entryClassName.indexOf(".class")).replace('/','.'); //we add the name of the class to the list of the classes we have to rewrite classesList.add(entryClassName); } //if not we just copy the file to the dump directory else{ try { File file=new File(userUploadDirectory+File.separatorChar+entryClassName); if(file.isFile()){ logger.debug("COPY filename : "+entryClassName); logger.debug("COPY filepath : "+userUploadDirectory+"dump"+File.separatorChar+entryClassName); //retrieve the file data FileInputStream stream = new FileInputStream(file); //write the file to the file specified OutputStream bos = new FileOutputStream( userUploadDirectory+"dump"+File.separatorChar+entryClassName); //we upload the file int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, bytesRead); } bos.close(); //close the stream stream.close(); } } catch (FileNotFoundException fnfe) { logger.debug("FileNotFoundException "+fnfe); } catch (IOException ioe) { logger.debug("IOException "+ ioe); } } } return classesList; } /** * This method extract the entry of the jar in parameter * @param entry- the entry of the jar to be extracted * @param jar - the jar file from where to read the entry */ private void extractEntry(JarEntry entry, JarFile jar){ //if the entry is a directory, we create it if(entry.isDirectory()){ String directoryName=entry.getName(); File directory=new File(userUploadDirectory.concat(directoryName)); if(!directory.exists()) directory.mkdir(); //we create also the directory tree to dump the file //which will be rewrote with our safe class loader File dumpDirectory= new File(userUploadDirectory+"dump"+File.separatorChar+directoryName); if(!dumpDirectory.exists()) dumpDirectory.mkdir(); } //else we extract the file from the jar else{ String fileName=entry.getName(); try{ //retrieve the file data InputStream stream = jar.getInputStream(entry); //write the file to the file specified OutputStream bos = new FileOutputStream(userUploadDirectory.concat(fileName)); //we extract the file int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, bytesRead); } bos.close(); //close the stream stream.close(); } catch(Exception e){ e.printStackTrace(); } } } /** * Method to add an Entry to a jar. * @param the jar to which add the entry * @the fully qualified name of the file acting like an entry */ /*private void addEntry(JarOutputStream jarFile,String entryName) { try { File file=null; if(entryName.indexOf(".class")!=-1) file=new File(uploadDirectory+"dump\\"+entryName); else file=new File(uploadDirectory.concat(entryName)); if(!file.isDirectory()){ FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); JarEntry fileEntry = new JarEntry(entryName); jarFile.putNextEntry(fileEntry); byte[] data = new byte[1024]; int byteCount; while ((byteCount = bis.read(data, 0, 1024)) > -1) { jarFile.write(data, 0, byteCount); } jarFile.closeEntry(); } } catch (IOException e) { e.printStackTrace(); logger.warn(e.toString()); } }*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -