List of usage examples for org.apache.commons.vfs2 FileObject resolveFile
FileObject resolveFile(String path) throws FileSystemException;
From source file:org.kalypso.kalypsomodel1d2d.conv.Gml2TelemacConv.java
/** * *//*ww w. j a v a 2s . c om*/ public Map<GM_Position, Integer> writeTelemacModel(final FileObject pFileObjWorkingDir) { try { m_fileObjWorkingDir = pFileObjWorkingDir; // REMARK: Made a central formatter with US locale (causing decimal point to be '.'), // so no locale parameter for each format is needed any more . final FileObject lModelBoundNodesFile = pFileObjWorkingDir .resolveFile(getProjectFileName() + BOUNDARY_NODES_FILE_EXTENTION); final FileObject lModelBoundariesFile = pFileObjWorkingDir .resolveFile(getProjectFileName() + BOUNDARY_CONDITIONS_FILE_EXTENTION); m_formatterBoundNodes = new Formatter(lModelBoundNodesFile.getContent().getOutputStream(), Charset.defaultCharset().name(), Locale.US); m_formatterBoundaries = new Formatter(lModelBoundariesFile.getContent().getOutputStream(), Charset.defaultCharset().name(), Locale.US); determineBoundNodes(); initIParams(); writeTelemacNodesModel(pFileObjWorkingDir); FormatterUtils.checkIoException(m_formatterBoundNodes); FormatterUtils.checkIoException(m_formatterBoundaries); return m_mapNodesActPositions; } catch (Throwable t) { t.printStackTrace(); m_log.log(StatusUtilities.statusFromThrowable(t)); return null; } finally { if (m_formatterBoundNodes != null) { m_formatterBoundNodes.close(); } if (m_formatterBoundaries != null) { m_formatterBoundaries.close(); } } }
From source file:org.kalypso.kalypsomodel1d2d.conv.Gml2TelemacConv.java
/** * *///from ww w . j av a2 s. c o m private int writeAllElements(final List<GM_Triangle> pTriangles, final FileObject pFileObjWorkingDir) { m_listAllNodes = new ArrayList<>(countNodes(pTriangles)); if (m_boolDoShift) { m_iparams[2] = m_globalMinX; m_iparams[3] = m_globalMinY; } SerafinWriter serafinWriter = new SerafinWriter(m_calculationUnit.getName(), pTriangles/* , pMapPositionsToConditions */, m_listAllNodes, m_listBoundNodes, m_iparams, m_strCRS); // int timeSteps = 1; try { FileObject serafinFile = pFileObjWorkingDir .resolveFile(GEO_FILE_PREFIX + getProjectFileName() + SERAFIN_FILE_EXTENTION); serafinWriter.setFile(new File(serafinFile.getURL().toURI()));// pFileObjWorkingDir.getURL().toURI().resolve( // "test_telemac.slf" ) ) ); timeSteps serafinWriter.writeAll(m_paramNames, m_paramUnits, m_restartNodes); writeBoundNodes(); writeBoundaries(); } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:org.kalypso.kalypsomodel1d2d.sim.SWANKalypsoSimulation.java
/** * Runs SWAN calculation. The following steps are processed: * <ul>//www. j a va 2 s . c om * <li>write swan.exe to temporary directory</li> * <li>execute the swan.exe</li> * <li>read results files and process them to the output directory</li> * </ul> * * @see org.kalypso.simulation.core.ISimulation#run(java.io.File, org.kalypso.simulation.core.ISimulationDataProvider, * org.kalypso.simulation.core.ISimulationResultEater, org.kalypso.simulation.core.ISimulationMonitor) */ @Override public void run(final File tmpdir, final ISimulationDataProvider inputProvider, final ISimulationResultEater resultEater, final ISimulationMonitor monitor) throws SimulationException { final SimulationMonitorAdaptor progressMonitor = new SimulationMonitorAdaptor(monitor); final ICancelable progressCancelable = new ProgressCancelable(progressMonitor); try { m_log = new GeoLog(KalypsoModel1D2DPlugin.getDefault().getLog()); } catch (final Exception e) { throw new SimulationException("Could not initialize GeoLog", e); //$NON-NLS-1$ } OutputStream logOS = null; OutputStream errorOS = null; FileSystemManagerWrapper manager = null; try { manager = VFSUtilities.getNewManager(); // TODO: specific error message if exe was not found final String version = (String) inputProvider.getInputForID(INPUT_SWAN_VERSION); final File exeFile = findSWANExe(version); final FileObject executableFile = manager.toFileObject(exeFile); final String executableName = exeFile.getName(); final String processFactoryId = IProcessFactory.DEFAULT_PROCESS_FACTORY_ID; // simply switch here and we run in the grid :) // Remark: it would be good also for swan :) // final String processFactoryId = "org.kalypso.simulation.gridprocess"; //$NON-NLS-1$ final String tempDirName = tmpdir.getName(); final IProcess process = KalypsoCommonsExtensions.createProcess(processFactoryId, tempDirName, executableName); // process.setProgressMonitor( progress ); // add sandbox dir to results for monitoring (empty at this time) final String sandboxDirectory = process.getSandboxDirectory(); try { resultEater.addResult(SWANKalypsoSimulation.OUTPUT_RESULTS, new URI(sandboxDirectory)); //$NON-NLS-1$ } catch (final URISyntaxException e) { e.printStackTrace(); } // copy executable and write input files final FileObject lFileObjWorkingDir = manager.resolveFile(sandboxDirectory); VFSUtilities.copyFileTo(executableFile, lFileObjWorkingDir); final String lStrPreSWANURL = (String) inputProvider.getInputForID(PreSWANKalypso.OUTPUT_PATH_SWAN); final FileObject lFileObjPreResultsDir = manager.resolveFile(lStrPreSWANURL); copyFilesToWorkDir(lFileObjPreResultsDir, lFileObjWorkingDir); final File stdoutFile = new File(tmpdir, "exe.log"); //$NON-NLS-1$ final File stderrFile = new File(tmpdir, "exe.err"); //$NON-NLS-1$ logOS = new BufferedOutputStream(new FileOutputStream(stdoutFile)); errorOS = new BufferedOutputStream(new FileOutputStream(stderrFile)); // Run the Calculation // final SubMonitor progress = SubMonitor.convert( progressMonitor, m_controlModel.getNCYC() ); m_log.formatLog(IStatus.INFO, CODE_RUNNING, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.0") + ": " //$NON-NLS-1$//$NON-NLS-2$ + executableName); progressMonitor.subTask(Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.15")); //$NON-NLS-1$ process.startProcess(logOS, errorOS, null, progressCancelable); // decide based on ERROR.OUT if simulation was successful final FileObject errorFile = lFileObjWorkingDir.resolveFile("ERROR.OUT"); //$NON-NLS-1$ if (errorFile == null || !errorFile.exists() || errorFile.getContent().getSize() == 0) { /* Successfully finished simulation */ progressMonitor.done(new Status(IStatus.OK, KalypsoModel1D2DPlugin.PLUGIN_ID, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.20"))); //$NON-NLS-1$ } else { /* ERROR: return contents of error file as error message */ final byte[] content = FileUtil.getContent(errorFile); final String charset = Charset.defaultCharset().name(); final String errorMessage = new String(content, charset); final IStatus status = new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, errorMessage); progressMonitor.done(status); } // TODO: implement the results eater } catch (final ProcessTimeoutException e) { throw new SimulationException( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.0"), e); //$NON-NLS-1$ } catch (final OperationCanceledException e) { final CoreException ce = new CoreException(new Status(IStatus.CANCEL, KalypsoModel1D2DPlugin.PLUGIN_ID, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.2"), e)); //$NON-NLS-1$ throw new SimulationException( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.1"), ce); //$NON-NLS-1$ } catch (final CoreException e) { throw new SimulationException( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.2"), e); //$NON-NLS-1$ } catch (final IOException e) { throw new SimulationException( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.3"), e); //$NON-NLS-1$ } finally { IOUtils.closeQuietly(logOS); IOUtils.closeQuietly(errorOS); if (manager != null) manager.close(); } }
From source file:org.kalypso.kalypsomodel1d2d.sim.TelemacKalypsoSimulation.java
/** * Runs SWAN calculation. The following steps are processed: * <ul>/*from w w w. j av a 2 s . co m*/ * <li>write swan.exe to temporary directory</li> * <li>execute the swan.exe</li> * <li>read results files and process them to the output directory</li> * </ul> * * @see org.kalypso.simulation.core.ISimulation#run(java.io.File, org.kalypso.simulation.core.ISimulationDataProvider, * org.kalypso.simulation.core.ISimulationResultEater, org.kalypso.simulation.core.ISimulationMonitor) */ @Override public void run(final File tmpdir, final ISimulationDataProvider inputProvider, final ISimulationResultEater resultEater, final ISimulationMonitor monitor) throws SimulationException { final SimulationMonitorAdaptor progressMonitor = new SimulationMonitorAdaptor(monitor); final ICancelable progressCancelable = new ProgressCancelable(progressMonitor); try { m_log = new GeoLog(KalypsoModel1D2DPlugin.getDefault().getLog()); } catch (final Exception e) { throw new SimulationException("Could not initialize GeoLog", e); //$NON-NLS-1$ } OutputStream logOS = null; OutputStream errorOS = null; FileSystemManagerWrapper manager = null; try { manager = VFSUtilities.getNewManager(); // TODO: specific error message if exe was not found final String version = (String) inputProvider.getInputForID(INPUT_TELEMAC_VERSION); final File exeFile = findTelemacBatch(version, tmpdir); final FileObject executableFile = manager.toFileObject(exeFile); final String executableName = exeFile.getName(); final String processFactoryId = IProcessFactory.DEFAULT_PROCESS_FACTORY_ID; // simply switch here and we run in the grid :) // Remark: it would be good also for swan :) // final String processFactoryId = "org.kalypso.simulation.gridprocess"; //$NON-NLS-1$ final String tempDirName = tmpdir.getName(); final IProcess process = KalypsoCommonsExtensions.createProcess(processFactoryId, tempDirName, executableName); // process.setProgressMonitor( progress ); // add sandbox dir to results for monitoring (empty at this time) final String sandboxDirectory = process.getSandboxDirectory(); try { resultEater.addResult(TelemacKalypsoSimulation.OUTPUT_RESULTS, new URI(sandboxDirectory)); //$NON-NLS-1$ } catch (final URISyntaxException e) { e.printStackTrace(); } // copy executable and write input files final FileObject lFileObjWorkingDir = manager.resolveFile(sandboxDirectory); VFSUtilities.copyFileTo(executableFile, lFileObjWorkingDir); final String lStrPreTelemacURL = (String) inputProvider .getInputForID(PreTelemacKalypso.OUTPUT_PATH_Telemac); final FileObject lFileObjPreResultsDir = manager.resolveFile(lStrPreTelemacURL); copyFilesToWorkDir(lFileObjPreResultsDir, lFileObjWorkingDir); final File stdoutFile = new File(tmpdir, "exe.log"); //$NON-NLS-1$ final File stderrFile = new File(tmpdir, "exe.err"); //$NON-NLS-1$ logOS = new BufferedOutputStream(new FileOutputStream(stdoutFile)); errorOS = new BufferedOutputStream(new FileOutputStream(stderrFile)); // Run the Calculation // final SubMonitor progress = SubMonitor.convert( progressMonitor, m_controlModel.getNCYC() ); m_log.formatLog(IStatus.INFO, CODE_RUNNING, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.0") + ": " //$NON-NLS-1$//$NON-NLS-2$ + executableName); progressMonitor.subTask(Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.15")); //$NON-NLS-1$ process.startProcess(logOS, errorOS, null, progressCancelable); // decide based on ERROR.OUT if simulation was successful final FileObject errorFile = lFileObjWorkingDir.resolveFile("ERROR.OUT"); //$NON-NLS-1$ if (errorFile == null || !errorFile.exists() || errorFile.getContent().getSize() == 0) { /* Successfully finished simulation */ progressMonitor.done(StatusUtilities .createOkStatus(Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.20"))); //$NON-NLS-1$ } else { /* ERROR: return contents of error file as error message */ final byte[] content = FileUtil.getContent(errorFile); final String charset = Charset.defaultCharset().name(); final String errorMessage = new String(content, charset); final IStatus status = StatusUtilities.createErrorStatus(errorMessage); progressMonitor.done(status); } // TODO: implement the results eater } catch (final ProcessTimeoutException e) { throw new SimulationException( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.0"), e); //$NON-NLS-1$ } catch (final OperationCanceledException e) { throw new SimulationException( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.1"), //$NON-NLS-1$ new CoreException(StatusUtilities.createStatus(IStatus.CANCEL, Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.2"), e))); //$NON-NLS-1$ } catch (final CoreException e) { throw new SimulationException( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.2"), e); //$NON-NLS-1$ } catch (final IOException e) { throw new SimulationException( Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.3"), e); //$NON-NLS-1$ } finally { IOUtils.closeQuietly(logOS); IOUtils.closeQuietly(errorOS); if (manager != null) manager.close(); } }
From source file:org.kalypso.project.database.server.trigger.TriggerHelper.java
public static void handleBean(final KalypsoProjectBean bean, final IConfigurationElement element) throws Exception { /* resolve trigger extension class */ final String pluginid = element.getContributor().getName(); final Bundle bundle = Platform.getBundle(pluginid); final Class<?> triggerClass = bundle.loadClass(element.getAttribute("class")); //$NON-NLS-1$ final Constructor<?> constructor = triggerClass.getConstructor(); final IProjectDatabaseTrigger trigger = (IProjectDatabaseTrigger) constructor.newInstance(); final FileSystemManager manager = VFSUtilities.getManager(); /* resolve global dir */ final String urlGlobalPath = System.getProperty(IProjectDataBaseServerConstant.SERVER_GLOBAL_DATA_PATH); final FileObject folderGlobal = manager.resolveFile(urlGlobalPath); if (!folderGlobal.exists()) { folderGlobal.createFolder();/*from ww w. j a v a 2 s . c o m*/ } /* global "global" dir */ final FileObject destinationCommonFolder = folderGlobal.resolveFile(COMMON_FOLDER); if (!destinationCommonFolder.exists()) { destinationCommonFolder.createFolder(); } /* global project dir */ final FileObject destinationProjectFolder = folderGlobal.resolveFile(bean.getUnixName()); if (!destinationProjectFolder.exists()) { destinationProjectFolder.createFolder(); } trigger.handleCommonData(bean, destinationCommonFolder); trigger.handleProjectData(bean, destinationProjectFolder); }
From source file:org.kalypso.service.wps.client.NonBlockingWPSRequest.java
/** * Starts the simulation./*w w w. j ava 2 s . c om*/ * * @param monitor * The progress monitor. */ public IStatus run(IProgressMonitor monitor) { // TODO: clear old results: No not here! We have to introduce additional operation to the service // So the client can tell the server to release any resources. /* Monitor. */ monitor = SubMonitor.convert(monitor, Messages.getString("org.kalypso.service.wps.client.NonBlockingWPSRequest.4"), 200); //$NON-NLS-1$ KalypsoServiceWPSDebug.DEBUG.printf("Checking for service URL ...\n"); //$NON-NLS-1$ /* Check, if we have a service endpoint. */ if (m_serviceEndpoint == null) { KalypsoServiceWPSDebug.DEBUG.printf("No URL to the service is given.\n"); //$NON-NLS-1$ return StatusUtilities.statusFromThrowable( new WPSException(Messages.getString("org.kalypso.service.wps.client.NonBlockingWPSRequest.3"))); //$NON-NLS-1$ } /* Send the request. */ ExecuteResponseType executeResponse; final CodeType simulationIdentifier = WPS040ObjectFactoryUtilities.buildCodeType("", m_identifier); //$NON-NLS-1$ try { // decide between local and remote invocation if (WPSRequest.SERVICE_LOCAL.equals(m_serviceEndpoint)) { FileObject resultFile = null; try { /* Execute the simulation via a manager, so that more than one simulation can be run at the same time. */ final Execute execute = WPS040ObjectFactoryUtilities.buildExecute(simulationIdentifier, m_dataInputs, m_outputDefinitions, true, true); final WPSSimulationManager manager = WPSSimulationManager.getInstance(); final ExecuteMediator executeMediator = new ExecuteMediator(execute); final WPSSimulationInfo info = manager.startSimulation(executeMediator); m_jobId = info.getId(); /* Prepare the execute response. */ final FileObject resultDir = manager.getResultDir(info.getId()); resultFile = resultDir.resolveFile("executeResponse.xml"); //$NON-NLS-1$ final String statusLocation = WPSUtilities .convertInternalToClient(resultFile.getURL().toExternalForm()); final StatusType status = WPS040ObjectFactoryUtilities.buildStatusType("Process accepted.", //$NON-NLS-1$ true); executeResponse = WPS040ObjectFactoryUtilities.buildExecuteResponseType(simulationIdentifier, status, m_dataInputs, m_outputDefinitions, null, statusLocation, WPSUtilities.WPS_VERSION.V040.toString()); } catch (final IOException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } catch (final SimulationException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } catch (final OWSException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } finally { if (resultFile != null) try { resultFile.close(); } catch (final FileSystemException e) { // gobble } } } else { executeResponse = WPSUtilities.callExecute(m_serviceEndpoint, m_identifier, m_dataInputs, m_outputDefinitions); } } catch (final CoreException e) { return e.getStatus(); } final StatusType status = executeResponse.getStatus(); final ProcessFailedType processFailed = status.getProcessFailed(); if (processFailed != null) { final String errorString = WPSUtilities.createErrorString(processFailed.getExceptionReport()); return StatusUtilities.createErrorStatus(errorString); } /* If the user aborted the job. */ monitor.worked(100); if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } /* Retrieve the path to the status file of the process. */ m_statusLocation = executeResponse.getStatusLocation(); /* Finish. */ monitor.worked(100); return Status.OK_STATUS; }
From source file:org.kalypso.service.wps.refactoring.DefaultWPSProcess.java
/** * @see org.kalypso.service.wps.client.IWPSProcess#startProcess(java.util.Map, java.util.List, * org.eclipse.core.runtime.IProgressMonitor) *//*from w ww .j a va 2 s . c o m*/ @Override public synchronized void startProcess(final Map<String, Object> inputs, final List<String> outputs, IProgressMonitor monitor) throws CoreException { Assert.isTrue(m_executionResponse == null); /* Monitor. */ monitor = SubMonitor.convert(monitor, Messages.getString("org.kalypso.service.wps.refactoring.DefaultWPSProcess.4"), 200); //$NON-NLS-1$ KalypsoServiceWPSDebug.DEBUG.printf("Checking for service URL ...\n"); //$NON-NLS-1$ /* Get the process description. */ final ProcessDescriptionType processDescription = getProcessDescription(monitor); /* Get the input data. */ final DataInputsType dataInputs = createDataInputs(processDescription, inputs); /* Get the output data. */ m_outputDefinitions = WPSUtilities.createOutputDefinitions(processDescription, outputs); /* Loop, until an result is available, a timeout is reached or the user has cancelled the job. */ final String title = processDescription.getTitle(); monitor.setTaskName(Messages.getString("org.kalypso.service.wps.client.WPSRequest.1") + title); //$NON-NLS-1$ final CodeType simulationIdentifier = WPS040ObjectFactoryUtilities.buildCodeType("", m_identifier); // decide between local and remote invocation if (WPSRequest.SERVICE_LOCAL.equals(m_serviceEndpoint)) { FileObject resultFile = null; try { /* Execute the simulation via a manager, so that more than one simulation can be run at the same time. */ final Execute execute = WPS040ObjectFactoryUtilities.buildExecute(simulationIdentifier, dataInputs, m_outputDefinitions, true, true); final WPSSimulationManager manager = WPSSimulationManager.getInstance(); final ExecuteMediator executeMediator = new ExecuteMediator(execute); final WPSSimulationInfo info = manager.startSimulation(executeMediator); m_jobId = info.getId(); /* Prepare the execute response. */ final FileObject resultDir = manager.getResultDir(info.getId()); resultFile = resultDir.resolveFile("executeResponse.xml"); final String statusLocation = WPSUtilities .convertInternalToClient(resultFile.getURL().toExternalForm()); final StatusType status = WPS040ObjectFactoryUtilities.buildStatusType("Process accepted.", true); m_executionResponse = WPS040ObjectFactoryUtilities.buildExecuteResponseType(simulationIdentifier, status, dataInputs, m_outputDefinitions, null, statusLocation, WPSUtilities.WPS_VERSION.V040.toString()); } catch (final IOException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } catch (final SimulationException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } catch (final OWSException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } finally { if (resultFile != null) try { resultFile.close(); } catch (final FileSystemException e) { // gobble } } } else { m_executionResponse = WPSUtilities.callExecute(m_serviceEndpoint, m_identifier, dataInputs, m_outputDefinitions); // TODO: check status, should now at least be 'accepted' } // TODO: move outside // final StatusType status = executeResponse.getStatus(); // final ProcessFailedType processFailed = status.getProcessFailed(); // if( processFailed != null ) // { // final String errorString = WPSUtilities.createErrorString( processFailed.getExceptionReport() ); // return StatusUtilities.createErrorStatus( errorString ); // } /* If the user aborted the job. */ // ProgressUtilities.worked( monitor, 100 ); }
From source file:org.kalypso.service.wps.server.operations.ExecuteOperation.java
/** * @see org.kalypso.service.wps.operations.IOperation#executeOperation(org.kalypso.service.ogc.RequestBean) *//*from www. j a va 2s . c om*/ @Override public StringBuffer executeOperation(final RequestBean request) throws OWSException { final StringBuffer response = new StringBuffer(); /* Start the operation. */ KalypsoServiceWPSDebug.DEBUG.printf("Operation \"Execute\" started.\n"); //$NON-NLS-1$ /* Gets the identifier, but also unmarshalls the request, so it has to be done! */ final String requestXml = request.getBody(); Object executeRequest = null; try { executeRequest = MarshallUtilities.unmarshall(requestXml); } catch (final JAXBException e) { throw new OWSException(OWSException.ExceptionCode.NO_APPLICABLE_CODE, e, ""); //$NON-NLS-1$ } /* Execute the simulation via a manager, so that more than one simulation can be run at the same time. */ final WPSSimulationManager manager = WPSSimulationManager.getInstance(); // TODO version 1.0 final ExecuteMediator executeMediator = new ExecuteMediator(executeRequest); final WPSSimulationInfo info = manager.startSimulation(executeMediator); /* Prepare the execute response. */ FileObject resultFile = null; InputStream inputStream = null; try { final FileObject resultDir = manager.getResultDir(info.getId()); resultFile = resultDir.resolveFile("executeResponse.xml"); //$NON-NLS-1$ int time = 0; final int timeout = 10000; final int delay = 500; while (!resultFile.exists() && time < timeout) { Thread.sleep(delay); time += delay; } final FileContent content = resultFile.getContent(); inputStream = content.getInputStream(); final String responseXml = IOUtils.toString(inputStream); response.append(responseXml); } catch (final Exception e) { throw new OWSException(OWSException.ExceptionCode.NO_APPLICABLE_CODE, e, ""); //$NON-NLS-1$ } finally { /* Close the file object. */ VFSUtilities.closeQuietly(resultFile); /* Close the input stream. */ IOUtils.closeQuietly(inputStream); } return response; }
From source file:org.kalypso.service.wps.utils.simulation.WPSSimulationHandler.java
/** * This function creates the execute response in the location for the given thread. * * @param status/*from w ww . j a v a 2 s. c o m*/ * The status of the process. * @param ioValues * The ioValues for creating the process outputs, if any are here. Otherwise leave it null. */ private synchronized void createExecuteResponse(final StatusType status, final List<IOValueType> ioValues) throws Exception { /* Prepare the execute response. */ final FileObject resultDir = m_service.getResultDir(m_jobID); final FileObject resultFile = resultDir.resolveFile("executeResponse.xml"); //$NON-NLS-1$ final String statusLocation = WPSUtilities.convertInternalToClient(resultFile.getURL().toExternalForm()); ProcessOutputs processOutputs = null; if (ioValues != null) processOutputs = WPS040ObjectFactoryUtilities.buildExecuteResponseTypeProcessOutputs(ioValues); final ExecuteResponseType value = WPS040ObjectFactoryUtilities.buildExecuteResponseType( m_execute.getIdentifier(), status, m_execute.getDataInputs(), m_execute.getOutputDefinitions(), processOutputs, statusLocation, WPSUtilities.WPS_VERSION.V040.toString()); final JAXBElement<ExecuteResponseType> executeResponse = WPS040ObjectFactoryUtilities .buildExecuteResponse(value); /* Marshall it into one XML string. */ final String xml = MarshallUtilities.marshall(executeResponse, WPS_VERSION.V040); /* Copy the execute response to this url. */ VFSUtilities.copyStringToFileObject(xml, resultFile); resultFile.close(); }
From source file:org.kalypso.service.wps.utils.simulation.WPSSimulationResultEater.java
/** * The constructor./* w ww. java 2 s .c o m*/ * * @param processDescription * The process description. * @param execute * The execute request. * @param tmpDir * The temporary directory for that simulation. * @param resultDir * The FileObject contains information, where the results should be put, so that the client can read them. */ public WPSSimulationResultEater(final ProcessDescriptionMediator processDescriptionMediator, final ExecuteMediator executeMediator, final File tmpDir, final String resultSpace) throws SimulationException { try { m_processDescription = processDescriptionMediator.getProcessDescription(executeMediator.getProcessId()); } catch (final CoreException e1) { throw new SimulationException( Messages.getString("org.kalypso.service.wps.utils.simulation.WPSSimulationResultEater.0"), e1); //$NON-NLS-1$ } m_execute = executeMediator.getV04(); m_tmpDir = tmpDir; m_results = new LinkedHashMap<>(); m_references = new LinkedHashMap<>(); m_outputList = index(m_processDescription); m_outputListClient = indexClient(m_execute); try { m_vfsManager = VFSUtilities.getNewManager(); final String resultDirectoryName = tmpDir.getName(); final FileObject resultRoot; if (resultSpace != null) resultRoot = m_vfsManager.resolveFile(resultSpace); else resultRoot = m_vfsManager.toFileObject(FileUtilities.TMP_DIR); m_resultDir = resultRoot.resolveFile(resultDirectoryName); m_resultDir.createFolder(); } catch (final Exception e) { throw new SimulationException( Messages.getString("org.kalypso.service.wps.utils.simulation.WPSSimulationResultEater.1"), e); //$NON-NLS-1$ } checkExpectedOutput(); }