Help with remoteFilesystemStrategy-class
perlil Dec 16, 2010 2:43 PMHi,
I'm using JBoss SOA 4.3.0.GA_CP02_SOA, and I have created a FTP Provider, in read only mode. The files are picked up and works fine.
Now I want to create my own remoteFilesystemStrategy-class, my class implements RemoteFileSystemStrategy and in that class I'm wrapping a ReadOnlyRemoteFileSystemStrategy. The only method that I'm overriding is the filterFileList method (and init), in which I'm filtering the files based on their size.
My problem is that the remoteFilesystemStrategy-class is not picked up, and instead the ReadOnlyRemoteFileSystemStrategy is used (default).
Does anyone have any ideas? Or is there a better way to filter the files on the FTP by their size (I want to be able to set a maximum size of a file as a security measurement)?
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.listeners.gateway.remotestrategies.ReadOnlyRemoteFileSystemStrategy;
import org.jboss.soa.esb.listeners.gateway.remotestrategies.RemoteFileSystemStrategy;
import org.jboss.soa.esb.listeners.gateway.remotestrategies.RemoteFileSystemStrategyException;
public class SizeBasedReadOnlyRemoteFileSystemStrategy implements RemoteFileSystemStrategy{
private final static Logger log = Logger.getLogger(SizeBasedReadOnlyRemoteFileSystemStrategy.class);
private ReadOnlyRemoteFileSystemStrategy strategy;
private final static long K = 1024;
private final static long M = K*K;
private final static long G = K*M;
private final static long T = K*G;
//Set default value of maxSize for a file to 5 Mega Byte.
private static long maxSize = 5*M;
private static long minSize = 0;
@Override
public void init(String arg0) throws RemoteFileSystemStrategyException {
strategy = new ReadOnlyRemoteFileSystemStrategy();
strategy.init(arg0);
log.debug("******************************** INIT ***********************************");
try{
log.debug("Loading properies from ftp-filter.properties");
Properties properties = new Properties();
properties.load(SizeBasedReadOnlyRemoteFileSystemStrategy.class.getResourceAsStream("/ftp-filter.properties"));
String maxSizeAsString = properties.getProperty("maxSize");
String minSizeAsString = properties.getProperty("minSize");
if(maxSizeAsString != null && !maxSizeAsString.isEmpty()){
String maxPostfix = maxSizeAsString.substring(maxSizeAsString.length()-1, maxSizeAsString.length());
Integer maxValue = new Integer(maxSizeAsString.substring(0, maxSizeAsString.length()-1));
if(maxPostfix.equalsIgnoreCase("K")){
maxSize = maxValue * K;
}
else if(maxPostfix.equalsIgnoreCase("M")){
maxSize = maxValue * M;
}
else if(maxPostfix.equalsIgnoreCase("G")){
maxSize = maxValue * G;
}
else if(maxPostfix.equalsIgnoreCase("T")){
maxSize = maxValue * T;
}
}
if(minSizeAsString != null && !minSizeAsString.isEmpty()){
String minPostfix = minSizeAsString.substring(minSizeAsString.length()-1, minSizeAsString.length());
Integer minValue = new Integer(minSizeAsString.substring(0, minSizeAsString.length()-1));
if(minPostfix.equalsIgnoreCase("K")){
minSize = minValue * K;
}
else if(minPostfix.equalsIgnoreCase("M")){
minSize = minValue * M;
}
else if(minPostfix.equalsIgnoreCase("G")){
minSize = minValue * G;
}
else if(minPostfix.equalsIgnoreCase("T")){
minSize = minValue * T;
}
}
}
catch(IOException ioe){
log.warn("Could not load /ftp-filter.properties, using default values.");
}
}
public static long getMaxSize() {
return maxSize;
}
public static long getMinSize() {
return minSize;
}
public static void setMaxSize(long maxSize) {
SizeBasedReadOnlyRemoteFileSystemStrategy.maxSize = maxSize;
}
public static void setMinSize(long minSize) {
SizeBasedReadOnlyRemoteFileSystemStrategy.minSize = minSize;
}
@Override
public File[] filterFileList(File[] arg0) throws RemoteFileSystemStrategyException {
arg0 = strategy.filterFileList(arg0);
List<File> files = new ArrayList<File>();
log.error("Filtering FTP files, current number of files = " + arg0.length);
log.error("MaxSize = " + maxSize);
log.error("MinSize = " + minSize);
for(File currentFile : arg0){
log.error("Checking size of file " + currentFile.getAbsolutePath() + ", szie = " + currentFile.length());
if(currentFile.length() >= minSize && currentFile.length() <= maxSize){
log.error("Size of file is within limit.");
files.add(currentFile);
}
}
return (File[])files.toArray();
}
@Override
public boolean deleteFile(File arg0) throws RemoteFileSystemStrategyException {
return strategy.deleteFile(arg0);
}
@Override
public void destroy() {
strategy.destroy();
}
@Override
public File getWorkFileName(File arg0, String arg1) {
return strategy.getWorkFileName(arg0, arg1);
}
@Override
public boolean renameFile(File arg0, File arg1) throws RemoteFileSystemStrategyException {
return strategy.renameFile(arg0, arg1);
}
@Override
public void stop() {
strategy.stop();
}
}
And my jboss-esb.xml looks like this:
<?xml version = "1.0" encoding = "UTF-8"?>
<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" parameterReloadSecs="5">
<providers>
<ftp-provider name="FTPprovider" hostname="ftp.ftpserver.com" >
<ftp-bus busid="ServiceFTPChannel" >
<ftp-message-filter
username="username"
password="password"
read-only="true"
passive="false"
directory="adir"
input-suffix=".xml" />
</ftp-bus>
</ftp-provider>
<jms-provider name="JBossMQ" connection-factory="ConnectionFactory" >
<jms-bus busid="ServiceEsbChannel" >
<jms-message-filter
dest-type="TOPIC"
dest-name="topic/service"
selector="source='fromServiceFTPAction'"/>
</jms-bus>
</jms-provider>
</providers>
<services>
<service category="myCategory"
name="myFileListener"
description="Service File Action (esb listener)" >
<listeners >
<ftp-listener name="FtpGateway"
busidref="ServiceFTPChannel"
is-gateway="true"
schedule-frequency="5">
<property name="remoteFilesystemStrategy-class" value="my.code.SizeBasedReadOnlyRemoteFileSystemStrategy"/>
<property name="remoteFileSystemStrategy-configFile" value="/ftpfile-cache-config.xml"/>
</ftp-listener >
<jms-listener name="ServiceFileAction" busidref="ServiceEsbChannel" />
</listeners>
<actions>
<action class="org.jboss.soa.esb.actions.SystemPrintln" name="PrintMessage">
<property name="message" value="Message"/>
</action>
</actions>
</service>
</services>
</jbossesb>