In fact with Mule ESB I use an SFTP connector to transfer files and a Java component that implements ClamAV to be able to analyze them. My concern is that I can not recover the file that is in the payload to pass to the scan method that expects an InputStream while the payload sends me a String. Has anyone ever used ClamAV with Mule ESB
Thank you
<flow name="ScanWithClamAvAndTransferFileOK">
<sftp:inbound-endpoint connector-ref="SFTP" host="${sftp.host}" port="${sftp.port}" path="${sftp.path}" user="${sftp.user}" password="${sftp.password}" responseTimeout="30000" doc:name="Transfer file to SFTP Server"/>
<component class="reporting.ClamAvTranformer" doc:name="Antivirus ClamAV"/>
<file:outbound-endpoint path="/home/test" connector-ref="File" responseTimeout="10000" outputPattern="#[function:datestamp]-#[message.inboundProperties['originalFilename']]" doc:name="File"/>
</flow>
public Object onCall(MuleEventContext eventContext) throws Exception {
// TODO Auto-generated method stub
MuleMessage message = eventContext.getMessage();
byte[] reply = getReply((SftpInputStream) message.getPayload());
return handleReply(reply);
}
private Object handleReply(byte[] reply) throws Exception{
ResponseDTO response = new ResponseDTO();
if (ClamAVClient.isCleanReply(reply)) {
response.setResponseType("Scan réussi avec succès !");
} else {
response.setResponseType("Scan rejeté !");
response.setMessage(byteToString(reply));
//response.setResultType(ResultType.BUSINESS_FAULT.toString());
}
return response;
}
private byte[] getReply(InputStream stream) throws IllegalStateException{
try {
return clamAV.scan(stream);
} catch (Exception e) {
throw new IllegalStateException("Le fichier ne peut pas etre scanner, cause : "+e.getMessage(),e);
}
}
private String byteToString(byte[] reply) throws Exception{
return new String(reply, "UTF-8").trim();
}