I want to use an aggregator to create a message out of two messages, but i'm not sure how to do this.
At the moment i'm reading in two files from a directory and want to aggregate those messages into one.
My whole project looks like this:
read in .zip -> pass to custom message handler that unzips it into a directory -> read files from this directory -> try to aggregate them
It would be great if i could send a message with two payloads after unzipping the file, but aggregating after reading it would suffice.
My unzipper looks like this:
public class ZipHandler extends AbstractMessageHandler {
File dat;
File json;
@Override
protected void handleMessageInternal(Message<?> message) throws Exception {
byte[] buffer = new byte[1024];
try {
File file = (File) message.getPayload();
ZipFile zip = new ZipFile(file);
for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries
.hasMoreElements();) {
ZipEntry ze = entries.nextElement();
String name = ze.getName();
if (name.endsWith(".dat") || name.endsWith(".DAT")) {
InputStream input = zip.getInputStream(ze);
File datFile = new File("D:/lrtrans/zipOut"
+ File.separator + name);
FileOutputStream fos = new FileOutputStream(datFile);
int len;
while ((len = input.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
this.dat = datFile;
fos.close();
} else if (name.endsWith(".json") || name.endsWith(".JSON")) {
InputStream input = zip.getInputStream(ze);
File jsonFile = new File("D:/lrtrans/zipOut"
+ File.separator + name);
FileOutputStream fos = new FileOutputStream(jsonFile);
int len;
while ((len = input.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
this.json = jsonFile;
fos.close();
}
}
zip.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
It takes those files and puts them into two directories, from which i read them in again using FileReadingMessageSource. I also would like to solve this using only annotation based notation, not xml.
Aucun commentaire:
Enregistrer un commentaire