Hi Percio,
The following is my Java code that lists files between date range. We are developoing this as part of utility service which searches in a list of directories(read from a config XML file) and between the given date range.
IDataCursor pipelineCursor = pipeline.getCursor();
String fileDir = IDataUtil.getString( pipelineCursor, “fileDir” );
String date1 = IDataUtil.getString( pipelineCursor, “date1” );
String date2 = IDataUtil.getString( pipelineCursor, “date2” );
String errorMessage = “”;
String fileListErrorMessage = “”;
File[] dirList = new File(fileDir).listFiles();
DateFormat df1 = new SimpleDateFormat(“E MMM dd HH:mm:ss z yyyy”);
DateFormat df2 = new SimpleDateFormat(“E MMM dd HH:mm:ss z yyyy”);
List filteredFiles = new ArrayList();
final SimpleDateFormat FORMAT = new SimpleDateFormat(“E MMM dd HH:mm:ss z yyyy”);
long d1 =0;
long d2 =0;
try{
Date dt1 = df1.parse(date1);
Date dt2 = df2.parse(date2);
d1 = dt1.getTime();
d2 = dt2.getTime();
for ( int i = 0; i < dirList.length; i++)
{
if((dirList[i].lastModified() > d1) && (dirList[i].lastModified() < d2))
filteredFiles.add(dirList[i].getPath().toString());
}
}catch(Exception e1) {
errorMessage = e1.getLocalizedMessage();
System.out.println("Problem occured while converting the dates "+errorMessage);
IDataUtil.put( pipelineCursor, “errorMessage”, errorMessage );
}
pipelineCursor.destroy();
IDataCursor pipelineCursor_1 = pipeline.getCursor();
try{
int s = filteredFiles.size();
IData fileList = new IData[s];
for(int j=0; j <fileList.length; j++){
fileList[j] = IDataFactory.create();
IDataCursor fileListCursor = fileList[j].getCursor();
//File f = (File)fileList[j];
String f = String.valueOf(filteredFiles.get(j));
IDataUtil.put( fileListCursor, “serialNumber”, (j+1)+“”);
IDataUtil.put( fileListCursor, “fileName”, f);
fileListCursor.destroy();
}
IDataUtil.put( pipelineCursor_1, “fileList”, fileList );
}catch(Exception e2){
fileListErrorMessage = e2.getMessage();
System.out.println("Problem occured while Listing Files "+fileListErrorMessage);
IDataUtil.put( pipelineCursor_1, “fileListErrorMessage”, fileListErrorMessage );
}
pipelineCursor_1.destroy();
The code is working fine if am giving the local directory say some c:\abc and input will be two dates. I am able to login using pub.client.ftp:login into that host and it sontains some files . I am invoking this java service in a flow service which reads directories and logs into that target host and supplies dirname, date1 and date2 inputs to my Java service. I am getting nullPointerException after invoking the Java service.
Thanks a lot in adv,
Regards,
Datta
#Integration-Server-and-ESB#webMethods#Flow-and-Java-services