webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Writing in file .xml

    Posted Tue October 21, 2008 07:06 PM

    Hello,
    I’m very new at this from the WM, I am working with the Developer, and I’m making some transformations of an XML format to another new format, what I want to know is how physically write to a file. Xml with the document generated with The new format, or modify and update its contents (of the file. xml) with the document and its new format.

    I show them the screens of my service flow
    Nissan.jpg
    nissan2.jpg


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 2.  RE: Writing in file .xml

    Posted Tue October 21, 2008 11:20 PM

    Hi,
    U can write the newly formed xml into a file using the PS utilities. u can get this package from the advantage site. By default the PS utilities write the files into the indegration folder. If u want to write to your mentioned folder or directory, add teh path in utilitie config file


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: Writing in file .xml

    Posted Wed October 22, 2008 12:20 AM

    Thanks for your answer, but from where I get these Utilities PS, I’m new in WM and no where is this tool that I mention, if you could please tell me where he is, is a flow service or that is?


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: Writing in file .xml

    Posted Wed October 22, 2008 12:29 AM

    Thanks for your answer, but from where I get these Utilities PS, I’m new in WM and no where is this tool that I mention, if you could please tell me where he is, is a flow or service that is?


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 5.  RE: Writing in file .xml

    Posted Wed October 22, 2008 12:39 AM

    Ok U will get this package from the www.advantage.webmethods.com

    Just search for PSutilities. BUt remember whne ever u change the config file u need to load the file from the developer…no need to restart the IS.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 6.  RE: Writing in file .xml

    Posted Wed October 22, 2008 08:07 AM

    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


  • 7.  RE: Writing in file .xml

    Posted Wed October 22, 2008 11:00 PM

    Thanks for your answer, a question which is the function of these variables: UserData, filename, appendOverwriteFlag, who served for each of them?, If you could please explain.

    Thank you for your attention.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB