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
Expand all | Collapse all

pub.file:getFile as Stream, can't close

  • 1.  pub.file:getFile as Stream, can't close

    Posted Thu February 23, 2006 08:57 PM

    I have a service doing a getFile loadAs = Stream

    If for some reason the convertToValues fails, the flow drops down to the catch block. The file then stays locked. I can not delete or change.

    I have a closeStream in the try block that works fine but when I copy it to my catch block and try to dig the stream out of lastError/pipeline, the file remains locked.

    Any ideas on how to cleanup the stream/file in this scenario?

    Thanks!
    Cort


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


  • 2.  RE: pub.file:getFile as Stream, can't close

    Posted Fri February 24, 2006 04:02 PM

    Cort,

    The problem you’re running into is that it can be tricky to retrieve elements from the lastError/pipeline document, ESPECIALLY when dealing with objects.

    I, for one, try to avoid retrieving elements from the lastError/pipeline as much as possible. The way I accomplish this is by initializing every variable I may have to use in the catch block BEFORE the try block. In your case, however, you’re dealing with an InputStream object so it’s NOT as easy as setting a string to an empty value with a simple MAP step in the beginning of the service.

    My suggestion to you then is to get the file before you jump into the try block. You could, however, get an exception when simply trying to open the file, so you’re going to need two sets of try-catch blocks. Here’s what your code should end up looking like:

    main: SEQUENCE (Exit on SUCCESS)
    — try: SEQUENCE (Exit on FAILURE)
    ------ getFile (this initializes the stream object)
    — catch: SEQUENCE (Exit on DONE)
    ------ getLastError
    ------ Handle error (ex. send notification, signal failure, etc.)

    main: SEQUENCE (Exit on SUCCESS)
    — try: SEQUENCE (Exit on FAILURE)
    ------ Code that is throwing the exception
    — catch: SEQUENCE (Exit on DONE)
    ------ getLastError
    ------ closeFile using the stream object initialized via getFile
    ------ Handle error (ex. send notification, signal failure, etc.)

    Let me know if I can help further.

    • Percio

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


  • 3.  RE: pub.file:getFile as Stream, can't close

    Posted Mon February 27, 2006 07:21 PM

    Hi Percio,

    Thanks for the tip! I tested this and it’s working great.

    -Cort-


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