write data into local file system

Hi Reamon,

Will you please tell me that which developer service i can use to write data into local file system. e.g. file IO in java. I want to write some data in text file or xml file using IS service.

Thanks
AShah

Such a service is not provided in a standard installation.

The PSUtilities package, which can be downloaded from Advantage, has several IO related services including several that write to a file.

Hello Reamon,

I searched for the PSUtilties package on advantage site but was unable to locate it. I am using WM 7.1.2 version.

Can you please let me know the download link for PSUtilities package?

THanks,

a simple search on Advantage… :wink: https://advantage.webmethods.com/advantage?targChanId=kb_home&oid=1614310672

You can write simple Java service to do so. A simple program -

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();

}

use streamtofile service from PSUtils. on the input set it to be the full path name where you wnat to save your file. also add that dir to the allowed dirs on the config of the PSUtil package.

Cheers

Hellow,

The java service throwing the service exception " path does not exist"
How can i rectify the exception and execute the java service

Thanks,

S Banu Prakash

Did you check the path to access? Is it a full absolute path you have given accessible to IS?

What are the inputs required to execute the above service and how can we map the elements in the pipeline.

I’m just guessing but I think it is saying that the directory path you’re trying to write to does not exist on the server. :slight_smile:

Is the directory path should present in the directory in which we installed Webmethods or we may specify any directory in the system

Thanks,

Banu Prakash

Yes.

Thanks for your clarification

Thanks,

Banu Prakash

The answer to your inputs question is in the code. Please review to see if you can determine the inputs needed. If afterwards you’re still stuck post your specific question.

Did you check this first thing “path does not exist”?

HTH,
RMG

I tried to run with Psutilities\file\writeToFile

and provided inputs filename as *C:\sample\test\error.txt
and map userdata that we want to store in the file, but the txt file on running service does not store any information.

any one help on this issue

It is written on the IS server, not on your computer.

Also, if you use the PSUtilities services they have a configuration file which is used to control which directories are accessible. You’ll need to update the configuration. Refer to the docs in PSUtilities. Or use a different service.

I have psutilities , so how can I save pipeline to file by using writeToFile

Thanks,

Banu

You save pipeline to file by using savePipelineToFile. You wouldn’t use writeToFile for that.

I would also encourage not using PSUtilities directly. Copy the services you want to use to your own utilities or “public” package.

If you’re using version 8 and have a need to write your own data to a file, pub.file now has services to write to a file.

My requirement in the project is I need to map the error information to a document and then saving the document to a file , through which we can refer the error information, So, that I tried to use the Psutilities\file\writeToFile service.

If we use SavePipelineToFile then the same thing can be achieved.

Thanks in advonce,

S Banu Prakash