Use custom processStrategy with file endpoint

89 views Asked by At

I have created a custom processStrategy that is an extention of the GenericFileDeleteProcessStrategy:

@Component
public class AlwaysDeleteProcessStrategy<T> extends GenericFileDeleteProcessStrategy<T> {

    private static final Logger LOGGER = LoggerFactory.getLogger(AlwaysDeleteProcessStrategy.class);

    @Override
    public void rollback(GenericFileOperations<T> operations, GenericFileEndpoint<T> endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
        LOGGER.info("Deleting file despite exception");
        super.commit(operations, endpoint, exchange, file);
    }
}

When using this in an endpoint-dsl this works perfectly fine, but when I build the endpoint with a String it stops working:

//Works fine
from(file("src/test/resources/input").advanced().processStrategy(new AlwaysDeleteProcessStrategy()))  

//Doesn't work
from("file://src/test/resources/input?processStrategy=#alwaysDeleteProcessStrategy")

This is the exception that gets thrown when I try adding it to the String endpoint:

Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: alwaysDeleteProcessStrategy of type: org.apache.camel.component.file.GenericFileProcessStrategy
    at org.apache.camel.support.CamelContextHelper.mandatoryLookupAndConvert(CamelContextHelper.java:253)
    at org.apache.camel.support.EndpointHelper.resolveReferenceParameter(EndpointHelper.java:376)
    at org.apache.camel.support.EndpointHelper.resolveReferenceParameter(EndpointHelper.java:336)
    at org.apache.camel.support.component.PropertyConfigurerSupport.property(PropertyConfigurerSupport.java:55)
    at org.apache.camel.component.file.FileEndpointConfigurer.configure(FileEndpointConfigurer.java:131)
    at org.apache.camel.support.PropertyBindingSupport.setSimplePropertyViaConfigurer(PropertyBindingSupport.java:733)
    ... 43 common frames omitted

I have also tried manually creating the bean incase the @Component annotation wasn't enough, but that made no difference. How can I make both situations work?

1

There are 1 answers

1
Jeremy Ross On BEST ANSWER

Did you add an instance of AlwaysDeleteProcessStrategy to the registry?

getContext().getRegistry().bind("alwaysDeleteProcessStrategy", new AlwaysDeleteProcessStrategy());