You can write your own java service to write to a file.
Example -
Java Service name - writeToFile
Inputs - userData, filename, appendOverwriteFlag
Code -
IDataCursor idcPipeline = pipeline.getCursor();
String strUserData = null;
String strFullFilename = null;
if (idcPipeline.first(“userData”))
{
strUserData = (String)idcPipeline.getValue();
}
if (idcPipeline.first(“filename”))
{
strFullFilename = (String)idcPipeline.getValue();
}
else
{
throw new ServiceException(“filename is null!” );
}
idcPipeline.first(“appendOverwriteFlag”);
String appendOverwriteFlag = (String)idcPipeline.getValue();
// Separate filename into path and filename
// This is done so that the directory can be written (if necessary)
String separator = System.getProperty(“file.separator”);
int indexSeparator = strFullFilename.lastIndexOf(separator);
if (indexSeparator == -1)
{
// Account for fact that you can use either ‘' or ‘/’ in Windows
indexSeparator = strFullFilename.lastIndexOf(’/');
}
String strPathName = strFullFilename.substring(0, indexSeparator+1);
String strFileName = strFullFilename.substring(indexSeparator+1);
FileWriter fw = null;
try
{
File pathToBeWritten = new File(strPathName);
// System.out.println("canonical path = " + pathToBeWritten.getCanonicalPath());
// Write the directory...
if (pathToBeWritten.exists() == false)
{
throw new ServiceException("Path does not exist!");
}
// Check if file exists
File fileToBeWritten = new File(strFullFilename);
if (fileToBeWritten.exists() == true && appendOverwriteFlag != null && appendOverwriteFlag.equals("failIfFileExists"))
{
throw new ServiceException("File " + strFullFilename + " already exists!");
}
// Write the file...
if (appendOverwriteFlag != null && appendOverwriteFlag.equals("overwrite"))
{
// overwrite
fw = new FileWriter(strFullFilename, false);
}
else
{
// append
fw = new FileWriter(strFullFilename, true);
}
fw.write(strUserData);
}
catch (Exception e)
{
throw new ServiceException(e.getMessage());
}
finally
{
// Close the output stream…
try
{
fw.close();
}
catch (Exception e)
{}
idcPipeline.destroy();
}
#webMethods#Integration-Server-and-ESB#Flow-and-Java-services