我们使用camel(2.6)将一些文件从一个路径复制到另一个路径。由于我们没有进行单元测试,我正在尝试编写一个新单元,但我一直都会遇到这个错误:
org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: sftp://admin@localhost/?connectTimeout=1800000&delay=1800000&disconnect=true&filter=%23myFileFilter&initialDelay=120000&passiveMode=true&password=admin&reconnectDelay=180000&recursive=true&useFixedDelay=true due to: Could not find a suitable setter for property: filter as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.component.file.GenericFileFilter with value #myFileFilter
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:449)
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:463)
我粘贴了我的代码:
<bean id="myFileFilter" class="com.my.test.RouteFileFilter">
<constructor-arg type="java.lang.String"
value="Regex_filter"/>
</bean>
RouteFilter是genericFileFilter的实现
然后,在单元测试中我正在这样做:
CamelContext ctx = new DefaultCamelContext();
Exchange ex = new DefaultExchange(ctx);
Endpoint endpoint = new SftpEndpoint(sourceURI, new SftpComponent(), new SftpConfiguration());
ctx.addEndpoint(sourceURI, endpoint);
ctx.addRoutes(myBuilder);
ctx.start();
这是我收到错误的行:
getContext().getEndpoint(getSourceURIWithFilter(), GenericFileEndpoint.class).setProcessStrategy(new DefaultRouteFileProcessStrategy(this));
答案 0 :(得分:1)
好的,我在网上发现了很多这些错误,没有人可以回答这个问题。 这是解决方案:
mMyBuilder mybuilder = new MyBuilder();
SimpleRegistry registry = new SimpleRegistry();
registry.put("myFileFilter", myfileFilter); // myFileFilter is an instance of your filter
CamelContext context = new DefaultCamelContext(registry);
myBuilder.setMyFilter("#myFilter");
// your code
context.addRoutes(myBuilder);
context.start();