IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

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.  java's dir question.

    Posted Tue May 11, 2010 01:36 PM

    Hi all,

    I have a java service that is basically scanning a directory. To be short, the code looks like :

    String dir_list[];
    dir_list = dir.list();
    idcPipeline.insertAfter("fileList", dir_list);

    Then this service is used in a web service.

    The problem is “fileList” parameter is not an array of string as expected but an array of pointer (according to the pipeline’s icon for this field) so the consumer of my webService can’t read it :

    object(stdClass)#5 (1) {
    ["ArrayOfstringItem"]=>
    string(27) "[Ljava.lang.Object;@9113f94"
    }

    As consequence, I have to loop against this array in a Flow in order to
    build a real string array. Any way more efficient way to do that ? How
    can I get directly an array of string as output of my java service ?

    Thanks

    Laurent


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


  • 2.  RE: java's dir question.

    Posted Tue May 11, 2010 02:09 PM

    I’ve tried this code in a java service

    And when i run it, the fileList is a String List
    can you try ?

    I’v tested on IS 6.5.


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


  • 3.  RE: java's dir question.

    Posted Tue May 11, 2010 02:39 PM

    Thanks arnaud.

    It is :confused:

    The full code is :

    IDataCursor idcPipeline = pipeline.getCursor();
    
    String filterString = null;
    if (idcPipeline.first("filter")) {
    filterString = (String) idcPipeline.getValue();
    }
    
    String directory = null;
    if (idcPipeline.first("directory")){
    directory = (String) idcPipeline.getValue();
    } else {
    throw new ServiceException("Directory is null!");
    }
    
    String MaxNum = null;
    if (idcPipeline.first("MaxFiles")) {
    MaxNum = (String) idcPipeline.getValue();
    }
    
    Integer FromDate = null;
    if (idcPipeline.first("FromDate")) {
    FromDate = Integer.valueOf((String) idcPipeline.getValue()).intValue();
    }
    Integer ToDate = null;
    if (idcPipeline.first("ToDate")) {
    ToDate = Integer.valueOf((String) idcPipeline.getValue()).intValue();
    }
    
    
    File dir = new File(directory);
    if (!dir.exists() || !dir.isDirectory()) {
    throw new ServiceException("Error reading inbox directory!");
    }
    
    String dir_list[];
    if ((filterString != null) && filterString.length() > 0){
    JZOOWildCardFilter filter = new JZOOWildCardFilter(filterString);
    dir_list = dir.list(filter);
    } else {
    dir_list = dir.list();
    }
    
    Arrays.sort(dir_list, Collections.reverseOrder());
    
    if(FromDate != null){
    [B]    Vector lst = new Vector();
    int i;[/b]
    
    [B]    for(i=0; i<dir_list.length; i++){
    Integer j = Integer.valueOf(dir_list[i].substring(0,8)).intValue();
    if(j >= FromDate && j <= ToDate)
    lst.add(dir_list[i]);
    }
    
    Object res[] = lst.toArray();
    idcPipeline.insertAfter("fileList", res);
    return;[/b]
    } else if(MaxNum != null){
    int i = Integer.valueOf(MaxNum).intValue();
    if ( i != 0 && i <  dir_list.length){
    String ndl[] = new String[ i ];
    System.arraycopy(dir_list,0, ndl, 0, i);
    idcPipeline.insertAfter("fileList", ndl);
    return;
    }
    }
    idcPipeline.insertAfter("fileList", dir_list);

    In my case, MaxFiles is empty and I use FromDate and ToDate … I suspect the “Vector” manipulation to convert to pointer :angry: I’m not a java expert so it was the most logical way I found to do that.

    Any better way ?

    Thanks

    Laurent


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


  • 4.  RE: java's dir question.

    Posted Tue May 11, 2010 03:09 PM

    try

    and it should work :happy:

    it’s an object not a pointer :wink:


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


  • 5.  RE: java's dir question.

    Posted Tue May 11, 2010 03:20 PM

    Working very well :smiley:

    Thanks a lot.

    Bye

    Laurent


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