List of usage examples for org.apache.commons.vfs2 FileObject getURL
URL getURL() throws FileSystemException;
From source file:com.stratuscom.harvester.deployer.StarterServiceDeployer.java
private URL findServiceURL(FileObject serviceArchive, FileObject serviceRoot) throws FileSystemException { if (serviceArchive != null) { return serviceArchive.getURL(); }//from w w w . j av a2s . co m return serviceRoot.getURL(); }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignSource.java
public String getDesignLocation(WGADesign design) throws WGADesignConfigurationException, FileSystemException { String location;// ww w.j a v a2 s . c o m if (design.getName().startsWith(DESIGNNAMEPREFIX_ADDITIONALDIR)) { String addName = design.getName().substring(DESIGNNAMEPREFIX_ADDITIONALDIR.length()); location = _additionalDirs.get(addName); if (location == null) { throw new WGADesignConfigurationException( "Additional directory of name " + addName + " + is not defined"); } } else if (design.getName().startsWith(DESIGNNAMEPREFIX_ARCHIVE)) { FileObject designDir = WGUtils .resolveDirLink(_dir.getChild(design.getName().substring(DESIGNNAMEPREFIX_ARCHIVE.length()) + "." + ARCHIVED_DESIGN_EXTENSION)); if (designDir == null) { throw new WGADesignConfigurationException("Archived design '" + _dir.resolveFile(design.getName()).getURL().toString() + " not found"); } location = "zip:" + designDir.getURL().toString(); } else { FileObject designDir = WGUtils.resolveDirLink(_dir.getChild(design.getName())); if (designDir == null) { throw new WGADesignConfigurationException("Design directory '" + _dir.resolveFile(design.getName()).getURL().toString() + " not found"); } location = designDir.getURL().toString(); } return location; }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignSource.java
public WGADesign getDesign(final String name) throws WGADesignRetrievalException { try {// ww w.j ava2 s .c om // Design archive (obsolete) if (name.startsWith(DESIGNNAMEPREFIX_ARCHIVE)) { String designName = name.substring(DESIGNNAMEPREFIX_ARCHIVE.length()); FileObject designFile = _dir.resolveFile(designName + ARCHIVED_DESIGN_EXTENSION); if (!designFile.exists()) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(name); design.setTitle(designFile.getName().getBaseName()); design.setDescription("Design at location " + designFile.getURL().toString()); return design; } // Additional directory else if (name.startsWith(DESIGNNAMEPREFIX_ADDITIONALDIR)) { String designName = name.substring(DESIGNNAMEPREFIX_ADDITIONALDIR.length()); String dirPath = _additionalDirs.get(designName); if (dirPath == null) { return null; } FileObject dir = VFS.getManager().resolveFile((String) dirPath); if (!dir.exists() || !dir.getType().equals(FileType.FOLDER)) { return null; } FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(dir); // Non-empty directories without syncinfo may not be used as design directories if (syncInfo == null && dir.getChildren().length != 0) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(DESIGNNAMEPREFIX_ADDITIONALDIR + name); design.setTitle(dir.getName().getBaseName()); design.setDescription("Design at location " + dir.getURL().toString()); design.setConfig(loadConfig(syncInfo)); design.setOverlayData(loadOverlayData(syncInfo)); return design; } // Regular design in configured directory else { _dir.refresh(); FileObject child = _dir.resolveFile(name); if (!child.exists()) { return null; } FileObject resolvedChild = WGUtils.resolveDirLink(child); if (!resolvedChild.getType().equals(FileType.FOLDER)) { return null; } FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(resolvedChild); // Non-empty directories without syncinfo may not be used as design directories if (syncInfo == null && child.getChildren().length != 0) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(child.getName().getBaseName()); design.setTitle(child.getName().getBaseName()); design.setDescription("Design at location " + child.getURL().toString()); design.setConfig(loadConfig(syncInfo)); design.setOverlayData(loadOverlayData(syncInfo)); return design; } } catch (FileSystemException e) { throw new WGADesignRetrievalException("Exception retrieving file system designs", e); } }
From source file:com.app.server.SARDeployer.java
/** * This method extracts the SAR archive and configures for the SAR and starts the services * @param file//from w w w .ja va 2 s . c om * @param warDirectoryPath * @throws IOException */ public void extractSarDeploy(ClassLoader cL, Object... args) throws IOException { CopyOnWriteArrayList classPath = null; File file = null; String fileName = ""; String fileWithPath = ""; if (args[0] instanceof File) { classPath = new CopyOnWriteArrayList(); file = (File) args[0]; fileWithPath = file.getAbsolutePath(); ZipFile zip = new ZipFile(file); ZipEntry ze = null; fileName = file.getName(); fileName = fileName.substring(0, fileName.indexOf('.')); fileName += "sar"; String fileDirectory; Enumeration<? extends ZipEntry> entries = zip.entries(); int numBytes; while (entries.hasMoreElements()) { ze = entries.nextElement(); // //log.info("Unzipping " + ze.getName()); String filePath = serverConfig.getDeploydirectory() + "/" + fileName + "/" + 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(".jar")) { classPath.add(filePath); } } } zip.close(); } else if (args[0] instanceof FileObject) { FileObject fileObj = (FileObject) args[0]; fileName = fileObj.getName().getBaseName(); try { fileWithPath = fileObj.getURL().toURI().toString(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } fileName = fileName.substring(0, fileName.indexOf('.')); fileName += "sar"; classPath = unpack(fileObj, new File(serverConfig.getDeploydirectory() + "/" + fileName + "/"), (StandardFileSystemManager) args[1]); } URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); WebClassLoader sarClassLoader; if (cL != null) { sarClassLoader = new WebClassLoader(urls, cL); } else { sarClassLoader = new WebClassLoader(urls); } for (int index = 0; index < classPath.size(); index++) { // log.info("file:"+classPath.get(index)); sarClassLoader.addURL(new URL("file:" + classPath.get(index))); } sarClassLoader.addURL(new URL("file:" + serverConfig.getDeploydirectory() + "/" + fileName + "/")); //log.info(sarClassLoader.geturlS()); sarsMap.put(fileWithPath, sarClassLoader); try { Sar sar = (Sar) sardigester.parse(new InputSource(new FileInputStream( serverConfig.getDeploydirectory() + "/" + fileName + "/META-INF/" + "mbean-service.xml"))); CopyOnWriteArrayList mbeans = sar.getMbean(); //log.info(mbeanServer); ObjectName objName, classLoaderObjectName = new ObjectName("com.app.server:classLoader=" + fileName); if (!mbeanServer.isRegistered(classLoaderObjectName)) { mbeanServer.registerMBean(sarClassLoader, classLoaderObjectName); } else { mbeanServer.unregisterMBean(classLoaderObjectName); mbeanServer.registerMBean(sarClassLoader, classLoaderObjectName); ; } for (int index = 0; index < mbeans.size(); index++) { Mbean mbean = (Mbean) mbeans.get(index); //log.info(mbean.getObjectname()); //log.info(mbean.getCls()); objName = new ObjectName(mbean.getObjectname()); Class service = sarClassLoader.loadClass(mbean.getCls()); if (mbeanServer.isRegistered(objName)) { //mbs.invoke(objName, "stopService", null, null); //mbs.invoke(objName, "destroy", null, null); mbeanServer.unregisterMBean(objName); } mbeanServer.createMBean(service.getName(), objName, classLoaderObjectName); //mbs.registerMBean(obj, objName); CopyOnWriteArrayList attrlist = mbean.getMbeanAttribute(); if (attrlist != null) { for (int count = 0; count < attrlist.size(); count++) { MBeanAttribute attr = (MBeanAttribute) attrlist.get(count); Attribute mbeanattribute = new Attribute(attr.getName(), attr.getValue()); mbeanServer.setAttribute(objName, mbeanattribute); } } Attribute mbeanattribute = new Attribute("ObjectName", objName); mbeanServer.setAttribute(objName, mbeanattribute); if (((String) mbeanServer.getAttribute(objName, "Deployer")).equals("true")) { mbeanServer.invoke(objName, "init", new Object[] { deployerList }, new String[] { Vector.class.getName() }); } mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer }, new String[] { Vector.class.getName(), ServerConfig.class.getName(), MBeanServer.class.getName() }); mbeanServer.invoke(objName, "start", null, null); serviceListObjName.put(fileWithPath, objName); } } catch (Exception e) { log.error("Could not able to deploy sar archive " + fileWithPath, e); // TODO Auto-generated catch block //e.printStackTrace(); } }
From source file:com.app.server.EJBDeployer.java
public void scanJar(FileObject jarFile, HashSet<Class<?>>[] classanotwith, Class[] annot, ClassLoader cL) throws FileSystemException { //FileObject[] childs=jarFile.getChildren(); //for(FileObject child:childs){ FileObject[] classes = jarFile.findFiles(new FileSelector() { @Override/* www . j av a 2s.co m*/ public boolean includeFile(FileSelectInfo arg0) throws Exception { return arg0.getFile().getName().getBaseName().endsWith(".class"); } @Override public boolean traverseDescendents(FileSelectInfo arg0) throws Exception { // TODO Auto-generated method stub return true; } }); //} int index = 0; for (FileObject cls : classes) { try { Class<?> clz = cL.loadClass(cls.getURL().toURI().toString() .replace(jarFile.getURL().toURI().toString(), "").replace("/", ".").replace(".class", "")); index = 0; for (Class annotclz : annot) { if (clz.getAnnotation(annotclz) != null) { classanotwith[index].add(clz); } index++; } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.app.server.SARDeployer.java
public void deploy(FileObject fobj, StandardFileSystemManager fsManager, ClassLoader cL) { // TODO Auto-generated method stub //while(true){ try {// w w w . j a va2s .c o m //log.info(url); extractSarDeploy(cL, fobj, fsManager); numberOfSarDeployed++; sarsDeployed.add(fobj.getURL().toURI().toString()); log.info(fobj.getURL().toURI() + " Deployed"); } catch (Exception e) { try { log.error("Could not able to deploy sar package " + fobj.getURL().toURI(), e); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // TODO Auto-generated catch block //e.printStackTrace(); } //log.info("War Deployed Successfully in path: "+fileCurrLastModified.getFile().getAbsolutePath()); //} }
From source file:de.innovationgate.wgpublisher.services.WGACoreServicesImpl.java
private String computeRelativePath(FileObject base, FileObject file) throws FileSystemException { String basePath = base.getURL().getPath(); String currentPath = file.getURL().getPath(); String path = currentPath.substring(basePath.length()); if (path.startsWith("/")) { if (path.length() > 1) { path = path.substring(1);//from w ww .j a v a 2 s . c om } else { path = ""; } } return path; }
From source file:maspack.fileutil.FileCacher.java
public OutputStream getOutputStream(URIx uri) throws FileSystemException { FileObject remoteFile = null; // will resolve next // loop through authenticators until we either succeed or cancel boolean cancel = false; while (remoteFile == null && cancel == false) { remoteFile = resolveRemote(uri); }/*from w w w . j ava 2 s . c o m*/ if (remoteFile == null) { throw new FileSystemException("Cannot find remote file <" + uri.toString() + ">", new FileNotFoundException("<" + uri.toString() + ">")); } // open stream content OutputStream stream = null; try { stream = remoteFile.getContent().getOutputStream(); } catch (Exception e) { throw new RuntimeException("Failed to open " + remoteFile.getURL(), e); } finally { remoteFile.close(); } return stream; }
From source file:de.innovationgate.wgpublisher.services.WGACoreServicesImpl.java
public void mkFSDesignDir(RemoteSession session, String path) throws WGAServiceException { if (!isAdminServiceEnabled()) { throw new WGAServiceException("Administrative services are disabled"); }//from w ww . j a v a2s. c o m if (!isAdminSession(session)) { throw new WGAServiceException("You need an administrative login to access this service."); } WGADesignSource source = _core.getDesignManager().getDesignSources() .get(WGAConfiguration.UID_DESIGNSOURCE_FILESYSTEM); if (source instanceof FileSystemDesignSource) { FileSystemDesignSource fsSource = (FileSystemDesignSource) source; try { fsSource.getDir().refresh(); FileObject resource = fsSource.getDir().resolveFile(path); String basePath = fsSource.getDir().getURL().getPath(); String resourcePath = resource.getURL().getPath(); if (!resourcePath.startsWith(basePath)) { throw new WGAServiceException( new IllegalArgumentException("Illegal design resource path '" + path + "'.")); } resource.createFolder(); } catch (FileSystemException e) { throw new WGAServiceException("Creating of FSDesignDir '" + path + "' failed.", e); } } }
From source file:de.innovationgate.wgpublisher.services.WGACoreServicesImpl.java
public void updateFSDesignResource(RemoteSession session, String path, DataSource content, long lastModified) throws WGAServiceException { if (!isAdminServiceEnabled()) { throw new WGAServiceException("Administrative services are disabled"); }/* w ww . j av a 2 s . com*/ if (!isAdminSession(session)) { throw new WGAServiceException("You need an administrative login to access this service."); } WGADesignSource source = _core.getDesignManager().getDesignSources() .get(WGAConfiguration.UID_DESIGNSOURCE_FILESYSTEM); if (source instanceof FileSystemDesignSource) { FileSystemDesignSource fsSource = (FileSystemDesignSource) source; try { fsSource.getDir().refresh(); FileObject resource = fsSource.getDir().resolveFile(path); String basePath = fsSource.getDir().getURL().getPath(); String resourcePath = resource.getURL().getPath(); if (!resourcePath.startsWith(basePath)) { throw new WGAServiceException( new IllegalArgumentException("Illegal design resource path '" + path + "'.")); } resource.createFile(); OutputStream out = resource.getContent().getOutputStream(); InputStream in = content.getInputStream(); WGUtils.inToOut(in, out, 1024); out.close(); in.close(); resource.getContent().setLastModifiedTime(lastModified); clearDesignFileCache(fsSource, fsSource.getDir().getName().getRelativeName(resource.getName())); } catch (FileSystemException e) { // throw new WGAServiceException("Updating FSDesignResource '" + path + "' failed.", e); } catch (IOException e) { throw new WGAServiceException("Updating FSDesignResource '" + path + "' failed.", e); } } }