[
https://issues.apache.org/jira/browse/CAMEL-7752?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14111944#comment-14111944
]
Raghavan commented on CAMEL-7752:
---------------------------------
The NPE is raised under
return file.getFileName().endsWith(".xml");
So added the if condition to check the file object and observed that
getFileName was returning null
if(file !=null && file.getFileName() != null) {
return file.getFileName().endsWith(".xml");
}
> filter with camel sftp is returnin NullPointerException
> -------------------------------------------------------
>
> Key: CAMEL-7752
> URL: https://issues.apache.org/jira/browse/CAMEL-7752
> Project: Camel
> Issue Type: Bug
> Components: camel-ftp
> Affects Versions: 2.10.0
> Environment: Windows 7, RedHat Linux 5.x
> Reporter: Raghavan
> Labels: GenericFile, camel-ftp, filter, ftp
>
> We are testing camel sftp with filter options to restrict the source files
> using a pattern.
> We get a NullPointerException when try to use a filter (CustomFilter)
> Attached herewith the code snippet
> [[CodeSnippet]]
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:camel="http://camel.apache.org/schema/spring"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd">
> <camelContext xmlns="http://camel.apache.org/schema/spring">
> <camel:propertyPlaceholder id="ftpadapterProperty"
> location="classpath:ftpadapter.properties"/>
>
> <!-- The file filter is to be tested -->
> <route>
> <from
> uri="sftp://{{ftp.user}}@{{ftp.host}}/{{ftp.remote.dir}}?password={{ftp.pwd}}&separator=UNIX&recursive={{ftp.dir.recursive}}&binary=true&delete={{ftp.deletefiles}}&stepwise={{ftp.stepwise}}&delay={{ftp.pollinginterval}}&filter=#fileFilter"/>
> <to
> uri="file://{{local.dir}}?fileName=${date:now:yyyyMMddhhmmss}_${file:onlyname.noext}.${file:ext}"/>
> <log message="Routing message from remote server to
> target folder with data ${body}" />
> </route>
> </camelContext>
>
> <bean id="fileFilter" class="org.myapp.ftpadapter.FileFilter"/>
>
> </beans>
> FileFilter src:
> public class FileFilter<T> implements GenericFileFilter<T> {
> private static Logger logger =
> LoggerFactory.getLogger(FileFilter.class);
>
> /* The purpose of this method is to apply a custom filter based on file
> pattern
> * This enables the ftp adapter to filter files based on the criteria
> implemented here
> * (non-Javadoc)
> * @see
> org.apache.camel.component.file.GenericFileFilter#accept(org.apache.camel.component.file.GenericFile)
> */
> public boolean accept(GenericFile<T> file) {
>
> if(logger.isDebugEnabled()) {
> logger.debug("IsDirectory=" + file.isDirectory());
> logger.debug("FileName="+file.getFileName());
> }
>
> if(file !=null && file.getFileName() != null) {
> return file.getFileName().endsWith(".xml");
> }
> else {
> return false;
> }
> }
> }
> [[/CodeSnippet]]
--
This message was sent by Atlassian JIRA
(v6.2#6252)