2016-06-17 4 views
3

pollStrategy가 정의되어 있고 레지스트리에 추가 된 소비자 엔드 포인트로 ftp uri 표준 경로가 있습니다. 그러나 다음과 같은 오류가 발생합니다.pollStrategy가있는 Camel FTP가 실패합니다.

Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: pollStrategy 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.spi.PollingConsumerPollStrategy with value #pollingStrategy 
     at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:588) 
     at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:616) 
     at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:473) 
     at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:483) 
     at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:255) 
     at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:257) 
     at org.apache.camel.component.file.GenericFileComponent.createEndpoint(GenericFileComponent.java:67) 
     at org.apache.camel.component.file.GenericFileComponent.createEndpoint(GenericFileComponent.java:37) 
     at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:114) 
     at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:568) 

다른 조합을 시도했지만 항상이 오류로 끝납니다. 아무도 내가 놓친 것을 발견 할 수 있습니까? 내 코드는 내가 본 카멜 단위 테스트와 상당히 유사합니다. 경로는 다음과 같습니다.

import org.apache.camel.*; 
import org.apache.camel.builder.RouteBuilder; 
import org.apache.camel.impl.DefaultPollingConsumerPollStrategy; 
import org.apache.camel.spi.PollingConsumerPollStrategy; 
import org.apache.camel.util.ServiceHelper; 
import org.apache.commons.lang3.StringUtils; 
import java.util.HashMap; 
import java.util.Map; 
import java.util.concurrent.CountDownLatch; 
import static org.apache.camel.builder.ProcessorBuilder.setBody; 

public class Test extends RouteBuilder { 

    final CamelContext camelContext = getContext(); 
    final org.apache.camel.impl.SimpleRegistry registry = new org.apache.camel.impl.SimpleRegistry(); 
    final org.apache.camel.impl.CompositeRegistry compositeRegistry = new org.apache.camel.impl.CompositeRegistry(); 
    private final CountDownLatch latch = new CountDownLatch(1); 

    @Override 
    public void configure() throws Exception { 
    ExceptionBuilder.setup(this); 
    compositeRegistry.addRegistry(camelContext.getRegistry()); 
    compositeRegistry.addRegistry(registry); 
    ((org.apache.camel.impl.DefaultCamelContext) camelContext).setRegistry(compositeRegistry); 
    registry.put("pollingStrategy", new MyPollStrategy()); 
    from("ftp://[email protected]/receive/in?password=1234&autoCreate=false&startingDirectoryMustExist=true&pollStrategy=#pollingStrategy&fileName=test.csv&consumer.delay=10m") 
      .convertBodyTo(String.class) 
      .log(LoggingLevel.INFO, "TEST", "${body} : ${headers}"); 

    } 

    private class MyPollStrategy implements PollingConsumerPollStrategy { 
    int maxPolls=3; 
    public boolean begin(Consumer consumer, Endpoint endpoint) { 
     return true; 
    } 

    public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) { 
     if (polledMessages > maxPolls) { 
     maxPolls = polledMessages; 
     } 
     latch.countDown(); 
    } 

    public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause) throws Exception { 
     return false; 
    } 
    } 
} 

uri에서 pollStrategy 참조를 제거하면 모든 것이 작동합니다.

답변

1

좋아, 해결책을 찾았습니다.이 작업을 할 때 맥주가 너무 많았을 것입니다. 너무 명확합니다.

final CamelContext camelContext = getContext(); 
    final org.apache.camel.impl.SimpleRegistry registry = new org.apache.camel.impl.SimpleRegistry(); 
    final org.apache.camel.impl.CompositeRegistry compositeRegistry = new org.apache.camel.impl.CompositeRegistry(); 

해당 부분은 클래스 변수 선언 부분이 아니라 configure 메소드에 있어야합니다.

관련 문제