List of usage examples for org.apache.commons.vfs2.impl StandardFileSystemManager init
@Override public void init() throws FileSystemException
From source file:it.openprj.jValidator.services.ServiceScheduledJob.java
@Override protected synchronized void executeInternal(JobExecutionContext arg0) throws JobExecutionException { long jobId = arg0.getJobDetail().getJobDataMap().getLong("jobId"); JobsEntity jobEntity = jobsDao.find(jobId); if (!jobEntity.isWorking()) { if (jobsDao.setWorkStatus(jobId, true)) { try { long eventTriggerId = arg0.getJobDetail().getJobDataMap().getString("eventTriggerId") == null ? -1l/*from ww w .j av a2 s . com*/ : Long.parseLong(arg0.getJobDetail().getJobDataMap().getString("eventTriggerId")); if (eventTriggerId > 0) { EventTriggerEntity entity = eventTriggerDao.findEventTriggerById(eventTriggerId); String className = entity.getName(); try { String sourceCode = entity.getCode(); EventTrigger eventTrigger; String response; eventTrigger = (EventTrigger) CommonUtils.getClassInstance(className, "it.openprj.jValidator.eventtrigger.EventTrigger", EventTrigger.class, sourceCode); assert eventTrigger != null; response = eventTrigger.trigger(); log.info("Response From EventTrigger(" + className + ") :" + response); } catch (Exception e) { e.printStackTrace(); log.error("EventTrigger(" + className + ") :" + e.getMessage(), e); logDao.setErrorLogMessage("EventTrigger(" + className + ") :" + e.getMessage()); } catch (NoClassDefFoundError err) { log.error("EventTrigger(" + className + ") :" + err.getMessage(), err); logDao.setErrorLogMessage("EventTrigger(" + className + ") :" + err.getMessage()); } return; } int day = arg0.getJobDetail().getJobDataMap().getString("day") == null ? -1 : Integer.parseInt(arg0.getJobDetail().getJobDataMap().getString("day")); int month = arg0.getJobDetail().getJobDataMap().getString("month") == null ? -1 : Integer.parseInt(arg0.getJobDetail().getJobDataMap().getString("month")); if ((day > 0 && day != Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) || (month > 0 && month != (Calendar.getInstance().get(Calendar.MONTH) + 1))) { return; } StandardFileSystemManager fsManager = new StandardFileSystemManager(); boolean isDataStream = true; try { fsManager.init(); long schemaId = arg0.getJobDetail().getJobDataMap().getLong("schemaId"); long schedulerId = arg0.getJobDetail().getJobDataMap().getLong("schedulerId"); //long jobId = arg0.getJobDetail().getJobDataMap().getLong("jobId"); long connectionId = arg0.getJobDetail().getJobDataMap().getLong("connectionId"); String datastream = ""; int idSchemaType = schemasDao.find(schemaId).getIdSchemaType(); TasksEntity taskEntity = tasksDao.find(schedulerId); //JobsEntity jobEntity = jobsDao.find(jobId); if (taskEntity.getIsOneShoot()) { jobEntity.setIsActive(0); jobsDao.update(jobEntity); } if (idSchemaType == SchemaType.GENERATION) { StreamGenerationUtils sgu = new StreamGenerationUtils(); datastream = sgu.getStream(schemaId); log.debug("Content stream: " + schemaId); if (datastream.trim().length() > 0) { log.debug("Datastream to validate: " + datastream); DatastreamsInput datastreamsInput = new DatastreamsInput(); String result = datastreamsInput.datastreamsInput(datastream, schemaId, null); log.debug("Validation result: " + result); } else { isDataStream = false; log.debug("No datastream create"); } } if (connectionId != 0) { int serviceId = Integer .parseInt(arg0.getJobDetail().getJobDataMap().getString("serviceId")); String hostName = arg0.getJobDetail().getJobDataMap().getString("ftpServerIp"); String port = arg0.getJobDetail().getJobDataMap().getString("port"); String userName = arg0.getJobDetail().getJobDataMap().getString("userName"); String password = arg0.getJobDetail().getJobDataMap().getString("password"); String inputDirectory = arg0.getJobDetail().getJobDataMap().getString("inputDirectory"); String fileName = arg0.getJobDetail().getJobDataMap().getString("fileName"); ConnectionsEntity conn; conn = connectionsDao.find(connectionId); if (inputDirectory == null || inputDirectory.trim().length() == 0) { inputDirectory = fileName; } else if (!(conn.getIdConnType() == GenericType.uploadTypeConn && serviceId == Servers.HTTP.getDbCode())) { inputDirectory = inputDirectory + "/" + fileName; } log.info("(jobId:" + jobEntity.getName() + ") - Trying to Server polling at server [" + hostName + ":" + port + "] with user[" + userName + "]."); String url = ""; if (serviceId == Servers.SAMBA.getDbCode()) { if (!fsManager.hasProvider("smb")) { fsManager.addProvider("smb", new SmbFileProvider()); } url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory; } else if (serviceId == Servers.HTTP.getDbCode()) { if (!fsManager.hasProvider("http")) { fsManager.addProvider("http", new HttpFileProvider()); } url = "http://" + hostName + ":" + port + "/" + inputDirectory; } else if (serviceId == Servers.FTP.getDbCode()) { if (!fsManager.hasProvider("ftp")) { fsManager.addProvider("ftp", new FtpFileProvider()); } url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory; } log.info("url:" + url); final FileObject fileObject = fsManager.resolveFile(url); if (conn.getIdConnType() == GenericType.DownloadTypeConn) { if (conn.getFileDateTime() != null && conn.getFileDateTime().getTime() == fileObject .getContent().getLastModifiedTime()) { log.info("There is no New or Updated '" + fileName + "' file on server to validate. Returning ..."); return; } else { log.info("There is New or Updated '" + fileName + "' file on server to validate. Validating ..."); ConnectionsEntity connection = connectionsDao.find(connectionId); connection.setFileDateTime( new Date(fileObject.getContent().getLastModifiedTime())); ApplicationContext ctx = AppContext.getApplicationContext(); ConnectionsDao connDao = (ctx.getBean(ConnectionsDao.class)); if (connDao != null) { connDao.update(connection); } Map<String, byte[]> resultMap = new HashMap<String, byte[]>(); byte data[] = new byte[(int) fileObject.getContent().getSize()]; fileObject.getContent().getInputStream().read(data); resultMap.put(fileObject.getName().getBaseName(), data); Set<String> keySet = resultMap.keySet(); Iterator<String> itr = keySet.iterator(); while (itr.hasNext()) { String strFileName = itr.next(); String result = ""; try { Long longSchemaId = schemaId; SchemaEntity schemaEntity = schemasDao.find(longSchemaId); if (schemaEntity == null) { result = "No schema found in database with Id [" + longSchemaId + "]"; log.error(result); logDao.setErrorLogMessage(result); } else { if (strFileName.endsWith(FileExtensionType.ZIP.getAbbreviation())) { // Case 1: When user upload a Zip file - All ZIP entries should be validate one by one ZipInputStream inStream = null; try { inStream = new ZipInputStream( new ByteArrayInputStream(resultMap.get(fileName))); ZipEntry entry; while (!(isStreamClose(inStream)) && (entry = inStream.getNextEntry()) != null) { if (!entry.isDirectory()) { DatastreamsInput datastreamsInput = new DatastreamsInput(); datastreamsInput .setUploadedFileName(entry.getName()); byte[] byteInput = IOUtils.toByteArray(inStream); result += datastreamsInput.datastreamsInput( new String(byteInput), longSchemaId, byteInput); } inStream.closeEntry(); } log.debug(result); } catch (IOException ex) { result = "Error occured during fetch records from ZIP file."; log.error(result); logDao.setErrorLogMessage(result); } finally { if (inStream != null) inStream.close(); } } else { DatastreamsInput datastreamsInput = new DatastreamsInput(); datastreamsInput.setUploadedFileName(strFileName); result = datastreamsInput.datastreamsInput( new String(resultMap.get(strFileName)), longSchemaId, resultMap.get(strFileName)); log.debug(result); } } } catch (Exception ex) { ex.printStackTrace(); result = "Exception occured during process the message for xml file " + strFileName + " Error - " + ex.getMessage(); log.error(result); logDao.setErrorLogMessage(result); } } } } else if (isDataStream && (conn.getIdConnType() == GenericType.uploadTypeConn)) { File uploadFile = File.createTempFile(fileName, ".tmp"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(uploadFile)); bw.write(datastream); bw.flush(); bw.close(); } catch (IOException ioex) { log.error("Datastream file can't be created"); logDao.setErrorLogMessage("Datastream file can't be created"); return; } if (serviceId == Servers.HTTP.getDbCode()) { try { HttpClient httpclient = new HttpClient(); PostMethod method = new PostMethod(url); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); Part[] parts = new Part[] { new FilePart("file", uploadFile.getName(), uploadFile) }; method.setRequestEntity( new MultipartRequestEntity(parts, method.getParams())); method.setDoAuthentication(true); int statusCode = httpclient.executeMethod(method); String responseBody = new String(method.getResponseBody()); if (statusCode != HttpStatus.SC_OK) { throw new HttpException(method.getStatusLine().toString()); } else { System.out.println(responseBody); } method.releaseConnection(); } catch (Exception ex) { log.error("Exception occurred during uploading of file at HTTP Server: " + ex.getMessage()); logDao.setErrorLogMessage( "Exception occurred during uploading of file at HTTP Server: " + ex.getMessage()); } } else { try { FileObject localFileObject = fsManager .resolveFile(uploadFile.getAbsolutePath()); fileObject.copyFrom(localFileObject, Selectors.SELECT_SELF); System.out.println("File uploaded at : " + new Date()); if (uploadFile.exists()) { uploadFile.delete(); } } catch (Exception ex) { log.error( "Exception occurred during uploading of file: " + ex.getMessage()); logDao.setErrorLogMessage( "Exception occurred during uploading of file: " + ex.getMessage()); } } } } } catch (Exception ex) { log.error("Error " + ": " + ex.getMessage()); } finally { fsManager.close(); } } finally { jobsDao.setWorkStatus(jobId, false); } } else { log.error("Can not set " + jobEntity.getName() + "working."); } } else { log.debug("Job " + jobEntity.getName() + " is working."); } }
From source file:com.yenlo.synapse.transport.vfs.VFSTransportListener.java
@Override protected void doInit() throws AxisFault { super.doInit(); try {// w w w . ja va 2 s . co m StandardFileSystemManager fsm = new StandardFileSystemManager(); fsm.setConfiguration(getClass().getClassLoader().getResource("providers.xml")); fsm.init(); this.workerPool = super.workerPool; fsManager = fsm; Parameter lockFlagParam = getTransportInDescription().getParameter(VFSConstants.TRANSPORT_FILE_LOCKING); if (lockFlagParam != null) { String strLockingFlag = lockFlagParam.getValue().toString(); // by-default enabled, if explicitly specified as "disable" make it disable if (VFSConstants.TRANSPORT_FILE_LOCKING_DISABLED.equals(strLockingFlag)) { globalFileLockingFlag = false; } } } catch (FileSystemException e) { handleException("Error initializing the file transport : " + e.getMessage(), e); } }
From source file:de.innovationgate.wgpublisher.services.WGACoreServicesImpl.java
public void initializeOverlay(RemoteSession session, PluginInfo pluginInfo, String designFolder) throws WGAServiceException { StandardFileSystemManager fsManager = new StandardFileSystemManager(); try {//from w ww. j a v a 2s . c om fsManager.init(); if (!isAdminServiceEnabled()) { throw new WGAServiceException("Administrative services are disabled"); } if (!isAdminSession(session)) { throw new WGAServiceException("You need an administrative login to access this service."); } WGAPlugin basePlugin = _core.getPluginSet().getPluginsByInstallationKey() .get(pluginInfo.getInstallationKey()); if (basePlugin == null) { throw new WGAServiceException( "No plugin is installed with installation key " + pluginInfo.getInstallationKey()); } WGDatabase pluginDB = _core.getContentdbs().get(basePlugin.buildDatabaseKey()); if (pluginDB == null) { throw new WGAServiceException( "Plugin database not connected for plugin " + basePlugin.getIdentification()); } FileSystemDesignSource fsDesignSource = (FileSystemDesignSource) _core.getDesignManager() .getDesignSources().get(WGAConfiguration.UID_DESIGNSOURCE_FILESYSTEM); WGADesign overlayDesign = fsDesignSource.getDesign(designFolder); if (overlayDesign == null) { throw new WGAServiceException("File Directory Design '" + designFolder + "' does not exist"); } String designFolderLocation = fsDesignSource.getDesignLocation(overlayDesign); FileObject designFolderObj = fsManager.resolveFile(designFolderLocation); if (!designFolderObj.exists() || !designFolderObj.getType().equals(FileType.FOLDER)) { throw new WGAServiceException( "Design folder '" + designFolder + "' cannot be found or is no folder"); } // Determine design encoding of folder to import to DesignDefinition designDef = null; FileObject designDefFile = designFolderObj.resolveFile("design.xml"); if (designDefFile.exists()) { designDef = DesignDefinition.load(designDefFile); } CSConfig csConfig = null; FileObject csConfigFile = designFolderObj.resolveFile("files/system/csconfig.xml"); if (csConfigFile.exists()) { csConfig = CSConfig.load(csConfigFile); } String designEncoding = FileSystemDesignManager.determineDesignEncoding(designDef, csConfig); // Trigger overlay init/uprade process OverlayStatus status = FileSystemDesignProvider.determineOverlayStatus( (FileSystemDesignProvider) pluginDB.getDesignProvider(), basePlugin.getPluginID(), designFolderObj, designEncoding, _core.getLog(), _core.getDesignFileValidator()); FileSystemDesignProvider.upgradeOverlay((FileSystemDesignProvider) pluginDB.getDesignProvider(), basePlugin.getPluginID(), status, designFolderObj, designEncoding, _core.getLog(), _core.getDesignFileValidator()); // Disconnect consumer apps WGADesignManager designManager = _core.getDesignManager(); for (WGDatabase consumerDb : _core.getContentdbs().values()) { WGDesignProvider provider = consumerDb.getDesignProvider(); if (provider instanceof OverlayDesignProvider) { OverlayDesignProvider overlayProvider = (OverlayDesignProvider) provider; if (overlayProvider.getOverlay() instanceof FileSystemDesignProvider) { FileSystemDesignProvider fsProvider = (FileSystemDesignProvider) overlayProvider .getOverlay(); if (fsProvider.getBaseFolder().equals(designFolderObj)) { _core.removeContentDB(consumerDb.getDbReference()); } } } } // Run update content dbs to reconnect _core.updateContentDBs(); } catch (Exception e) { if (e instanceof WGAServiceException) { throw (WGAServiceException) e; } else { throw new WGAServiceException("Overlay initialisation failed.", e); } } finally { fsManager.close(); } }
From source file:com.web.server.EARDeployer.java
public void run() { StandardFileSystemManager fsManager = null; fsManager = new StandardFileSystemManager(); try {/* ww w . ja va2s . c o m*/ System.setProperty("java.io.tmpdir", this.cacheDir); /*DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator);*/ fsManager.init(); } catch (FileSystemException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } // fsManager.addProvider("file", new JarFileProvider()); File file = new File(scanDirectory); File[] files = file.listFiles(); CopyOnWriteArrayList<String> classList; ConcurrentHashMap jarClassListMap = new ConcurrentHashMap(); task = new EARFileListener(executorServiceMap, urlClassLoaderMap, earsDeployed); 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(".ear")) { String filePath = files[i].getAbsolutePath(); com.web.server.util.FileUtil util = new com.web.server.util.FileUtil(); FileObject earFile = null; try { System.out.println("Before resolve file"); System.out.println("jar:file:///" + filePath); earFile = fsManager.resolveFile("jar:file:///" + scanDirectory + "/" + files[i].getName()); System.out.println("After resolve file"); } catch (FileSystemException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { deleteExecutorServicesEar(files[i].getName(), fsManager); deployExecutorServicesEar(files[i].getName(), earFile, fsManager); numberOfEarsDeployed++; log.info("deployed Ear:" + files[i].getName()); } catch (Exception ex) { // TODO Auto-generated catch block log.info("Could not deploy Ear:" + file.getName(), ex); //e.printStackTrace(); } // logger.info("filePath"+filePath); /*filePath = filePath.substring(0, filePath.toLowerCase() .lastIndexOf(".ear")); VFSClassLoader customClassLoader = null; try { CopyOnWriteArrayList<FileObject> fileObjects = new CopyOnWriteArrayList<FileObject>(); System.out.println("EARFILE:/ \n\n\n\n\n\n\n\n\n\n" + earFile); obtainUrls(earFile, earFile, fileObjects, jarClassListMap, fsManager); System.out.println(fileObjects); System.out.println(jarClassListMap); VFSClassLoader customClassLoaderBaseLib = new VFSClassLoader( fileObjects.toArray(new FileObject[fileObjects .size()]), fsManager, Thread .currentThread().getContextClassLoader()); // customClassLoader.loadClass(classList.get(0).toString()); Set keys = jarClassListMap.keySet(); Iterator key = keys.iterator(); for (int keyCount = 0; keyCount < keys.size(); keyCount++) { FileObject jarFileObject = (FileObject) key.next(); classList = (CopyOnWriteArrayList<String>) jarClassListMap .get(jarFileObject); for (int classCount = 0; classCount < classList.size(); classCount++) { String classwithpackage = classList.get(classCount) .substring( 0, classList.get(classCount).indexOf( ".class")); classwithpackage = classwithpackage.replace("/", "."); System.out.println("classList:" + classwithpackage.replace("/", ".")); try { if (!classwithpackage.contains("$")) { customClassLoader = new VFSClassLoader( jarFileObject, fsManager, customClassLoaderBaseLib); this.urlClassLoaderMap.put(scanDirectory + "/" + files[i].getName() + "/" + jarFileObject.getName() .getBaseName(), customClassLoader); Class executorServiceClass = customClassLoader .loadClass(classwithpackage); System.out.println(executorServiceClass .newInstance()); // System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); // System.out.println(); Method[] methods = executorServiceClass .getMethods(); for (Method method : methods) { Annotation[] annotations = method .getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof ExecutorServiceAnnot) { ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation; ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo(); executorServiceInfo .setExecutorServicesClass(executorServiceClass); executorServiceInfo .setMethod(method); executorServiceInfo .setMethodParams(method .getParameterTypes()); // System.out.println("method="+executorServiceAnnot.servicename()); // System.out.println("method info="+executorServiceInfo); // if(servicesMap.get(executorServiceAnnot.servicename())==null)throw // new Exception(); executorServiceMap.put( executorServiceAnnot .servicename(), executorServiceInfo); } } } } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } jarFileObject.close(); } for (FileObject fobject : fileObjects) { fobject.close(); } } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { earFile.close(); fsManager.closeFileSystem(earFile.getFileSystem()); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ } } //fsManager.close(); if (exec == null) { exec = Executors.newSingleThreadScheduledExecutor(); exec.scheduleAtFixedRate(task, 0, 1000, TimeUnit.MILLISECONDS); } }
From source file:com.web.server.EJBDeployer.java
@Override public void run() { EJBJarFileListener jarFileListener = new EJBJarFileListener(registry, this.servicesRegistryPort, jarEJBMap, jarMDBMap, jms, connectionFactory); DefaultFileMonitor fm = new DefaultFileMonitor(jarFileListener); FileObject listendir = null;/*from w w w .ja va 2s . co m*/ StandardFileSystemManager fsManager = new StandardFileSystemManager(); String[] dirsToScan = scanDirectory.split(";"); EJBContext ejbContext; try { File scanDirFile = new File(dirsToScan[0]); File[] scanJarFiles = scanDirFile.listFiles(); System.out.println("SCANDIRECTORY=" + scanDirectory); if (scanJarFiles != null) { for (File scanJarFile : scanJarFiles) { if (scanJarFile.isFile() && scanJarFile.getAbsolutePath().endsWith(".jar")) { URLClassLoader classLoader = new URLClassLoader( new URL[] { new URL("file:///" + scanJarFile.getAbsolutePath()) }, Thread.currentThread().getContextClassLoader()); ConfigurationBuilder config = new ConfigurationBuilder(); config.addUrls(ClasspathHelper.forClassLoader(classLoader)); config.addClassLoader(classLoader); org.reflections.Reflections reflections = new org.reflections.Reflections(config); EJBContainer container = EJBContainer .getInstance("file:///" + scanJarFile.getAbsolutePath(), config); container.inject(); Set<Class<?>> cls = reflections.getTypesAnnotatedWith(Stateless.class); Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class); Object obj; System.gc(); if (cls.size() > 0) { ejbContext = new EJBContext(); ejbContext.setJarPath(scanJarFile.getAbsolutePath()); ejbContext.setJarDeployed(scanJarFile.getName()); for (Class<?> ejbInterface : cls) { //BeanPool.getInstance().create(ejbInterface); obj = BeanPool.getInstance().get(ejbInterface); System.out.println(obj); ProxyFactory factory = new ProxyFactory(); obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj), servicesRegistryPort); String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + obj); if (remoteBinding != null) { //registry.unbind(remoteBinding); registry.rebind(remoteBinding, (Remote) obj); ejbContext.put(remoteBinding, obj.getClass()); } //registry.rebind("name", (Remote) obj); } jarEJBMap.put("file:///" + scanJarFile.getAbsolutePath().replace("\\", "/"), ejbContext); } System.out.println("Class Message Driven" + clsMessageDriven); if (clsMessageDriven.size() > 0) { System.out.println("Class Message Driven"); MDBContext mdbContext; ConcurrentHashMap<String, MDBContext> mdbContexts; if (jarMDBMap.get(scanJarFile.getAbsolutePath()) != null) { mdbContexts = jarMDBMap.get(scanJarFile.getAbsolutePath()); } else { mdbContexts = new ConcurrentHashMap<String, MDBContext>(); } jarMDBMap.put("file:///" + scanJarFile.getAbsolutePath().replace("\\", "/"), mdbContexts); MDBContext mdbContextOld; for (Class<?> mdbBean : clsMessageDriven) { String classwithpackage = mdbBean.getName(); System.out.println("class package" + classwithpackage); classwithpackage = classwithpackage.replace("/", "."); System.out.println("classList:" + classwithpackage.replace("/", ".")); try { if (!classwithpackage.contains("$")) { //System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); //System.out.println(); if (!mdbBean.isInterface()) { Annotation[] classServicesAnnot = mdbBean.getDeclaredAnnotations(); if (classServicesAnnot != null) { for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof MessageDriven) { MessageDriven messageDrivenAnnot = (MessageDriven) classServicesAnnot[annotcount]; ActivationConfigProperty[] activationConfigProperties = messageDrivenAnnot .activationConfig(); mdbContext = new MDBContext(); mdbContext.setMdbName(messageDrivenAnnot.name()); for (ActivationConfigProperty activationConfigProperty : activationConfigProperties) { if (activationConfigProperty.propertyName() .equals(MDBContext.DESTINATIONTYPE)) { mdbContext.setDestinationType( activationConfigProperty.propertyValue()); } else if (activationConfigProperty.propertyName() .equals(MDBContext.DESTINATION)) { mdbContext.setDestination( activationConfigProperty.propertyValue()); } else if (activationConfigProperty.propertyName() .equals(MDBContext.ACKNOWLEDGEMODE)) { mdbContext.setAcknowledgeMode( activationConfigProperty.propertyValue()); } } if (mdbContext.getDestinationType() .equals(Queue.class.getName())) { mdbContextOld = null; if (mdbContexts.get(mdbContext.getMdbName()) != null) { mdbContextOld = mdbContexts .get(mdbContext.getMdbName()); if (mdbContextOld != null && mdbContext.getDestination().equals( mdbContextOld.getDestination())) { throw new Exception( "Only one MDB can listen to destination:" + mdbContextOld .getDestination()); } } mdbContexts.put(mdbContext.getMdbName(), mdbContext); Queue queue = (Queue) jms .lookup(mdbContext.getDestination()); Connection connection = connectionFactory .createConnection("guest", "guest"); connection.start(); Session session; if (mdbContext.getAcknowledgeMode() != null && mdbContext.getAcknowledgeMode() .equals("Auto-Acknowledge")) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } else { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } MessageConsumer consumer = session .createConsumer(queue); consumer.setMessageListener( (MessageListener) mdbBean.newInstance()); mdbContext.setConnection(connection); mdbContext.setSession(session); mdbContext.setConsumer(consumer); System.out.println("Queue=" + queue); } else if (mdbContext.getDestinationType() .equals(Topic.class.getName())) { if (mdbContexts.get(mdbContext.getMdbName()) != null) { mdbContextOld = mdbContexts .get(mdbContext.getMdbName()); if (mdbContextOld.getConsumer() != null) mdbContextOld.getConsumer() .setMessageListener(null); if (mdbContextOld.getSession() != null) mdbContextOld.getSession().close(); if (mdbContextOld.getConnection() != null) mdbContextOld.getConnection().close(); } mdbContexts.put(mdbContext.getMdbName(), mdbContext); Topic topic = (Topic) jms .lookup(mdbContext.getDestination()); Connection connection = connectionFactory .createConnection("guest", "guest"); connection.start(); Session session; if (mdbContext.getAcknowledgeMode() != null && mdbContext.getAcknowledgeMode() .equals("Auto-Acknowledge")) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } else { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } MessageConsumer consumer = session .createConsumer(topic); consumer.setMessageListener( (MessageListener) mdbBean.newInstance()); mdbContext.setConnection(connection); mdbContext.setSession(session); mdbContext.setConsumer(consumer); System.out.println("Topic=" + topic); } } } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } classLoader.close(); System.out.println(scanJarFile.getAbsolutePath() + " Deployed"); } } } FileSystemOptions opts = new FileSystemOptions(); FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); fsManager.init(); for (String dir : dirsToScan) { if (dir.startsWith("ftp://")) { listendir = fsManager.resolveFile(dir, opts); } else { listendir = fsManager.resolveFile(dir); } fm.addFile(listendir); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } fm.setRecursive(true); fm.setDelay(1000); fm.start(); }
From source file:org.anarres.filechooser.impl.vfs2.VFSJFileChooserTest.java
@Test public void testFileChooser() throws Exception { StandardFileSystemManager manager = new StandardFileSystemManager(); manager.init(); final FileObject root = manager.resolveFile("ram:/"); FileObject foo = root.resolveFile("foo"); foo.createFolder();//w w w . jav a 2 s.co m foo.resolveFile("foo0").createFile(); foo.resolveFile("foo1").createFile(); root.resolveFile("bar").createFile(); EventQueue.invokeLater(new Runnable() { @Override public void run() { try { CommonsVfs2JFileChooser chooser = new CommonsVfs2JFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.setCurrentDirectory(root); VFSJFileChooser.RETURN_TYPE ret = chooser.showOpenDialog(null); LOG.info("RETURN_TYPE = " + ret); LOG.info("Selected FO = " + chooser.getSelectedFile()); LOG.info("Selected FOs = " + Arrays.toString(chooser.getSelectedFiles())); print(chooser.getSelectedFile()); for (FileObject file : chooser.getSelectedFiles()) { print(file); } } catch (FileSystemException e) { throw new RuntimeException(e); } } }); Robot robot = BasicRobot.robotWithCurrentAwtHierarchy(); robot.waitForIdle(); VFSJFileChooserFixture<FileObject> chooser = VFSJFileChooserFinder.<FileObject>findFileChooser() .using(robot); // Thread.sleep(2000); chooser.setCurrentDirectory(foo); // Thread.sleep(2000); chooser.approve(); }
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * This function returns a new private StandardFileSystemManager. It is the caller's responsibility to close the * manager and release any resources associated with its file systems. *//*from w w w . j a v a 2 s. com*/ public static FileSystemManagerWrapper getNewManager() throws FileSystemException { // create new file system manager final StandardFileSystemManager fsManager = new StandardFileSystemManager(); fsManager.setConfiguration(VFSUtilities.class.getResource("vfs-providers.xml")); //$NON-NLS-1$ fsManager.init(); configureManager(fsManager); return new FileSystemManagerWrapper(fsManager, FILE_SYSTEM_MANAGER_DELEGATE); }
From source file:org.wso2.carbon.connector.util.FileConnectorUtils.java
public static StandardFileSystemManager getManager() { StandardFileSystemManager fsm = null; try {//from w ww.j ava2s. c om fsm = new StandardFileSystemManager(); fsm.init(); } catch (FileSystemException e) { log.error("Unable to get FileSystemManager: " + e.getMessage(), e); } return fsm; }
From source file:org.wso2.carbon.inbound.endpoint.protocol.file.FilePollingConsumer.java
public FilePollingConsumer(Properties vfsProperties, String name, SynapseEnvironment synapseEnvironment, long scanInterval) { this.vfsProperties = vfsProperties; this.name = name; this.synapseEnvironment = synapseEnvironment; this.scanInterval = scanInterval; this.lastRanTime = null; setupParams();/*from ww w.ja v a 2 s .co m*/ try { StandardFileSystemManager fsm = new StandardFileSystemManager(); fsm.setConfiguration(getClass().getClassLoader().getResource("providers.xml")); fsm.init(); fsManager = fsm; } catch (Exception e) { log.error(e); throw new RuntimeException(e); } //Setup SFTP Options try { fso = VFSUtils.attachFileSystemOptions(parseSchemeFileOptions(fileURI), fsManager); } catch (Exception e) { log.warn("Unable to set the sftp Options", e); fso = null; } }
From source file:org.wso2.carbon.transport.file.connector.server.FileConsumer.java
public FileConsumer(String id, Map<String, String> fileProperties, CarbonMessageProcessor messageProcessor) throws ServerConnectorException { this.serviceName = id; this.fileProperties = fileProperties; this.messageProcessor = messageProcessor; setupParams();//from w ww. jav a 2s . co m try { StandardFileSystemManager fsm = new StandardFileSystemManager(); fsm.setConfiguration(getClass().getClassLoader().getResource("providers.xml")); fsm.init(); fsManager = fsm; } catch (FileSystemException e) { throw new ServerConnectorException( "Could not initialize File System Manager from " + "the configuration: providers.xml", e); } Map<String, String> options = parseSchemeFileOptions(fileURI); fso = FileTransportUtils.attachFileSystemOptions(options, fsManager); if (options != null && Constants.SCHEME_FTP.equals(options.get(Constants.SCHEME))) { FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fso, true); } try { fileObject = fsManager.resolveFile(fileURI, fso); } catch (FileSystemException e) { throw new FileServerConnectorException( "Failed to resolve fileURI: " + FileTransportUtils.maskURLPassword(fileURI), e); } }