You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sub3 <st...@subwest.com> on 2010/03/26 16:36:36 UTC

How do I specify sorting in file component?

Hi,
Can someone tell me what I am doing wrong.  I am using the File component
and I am trying to make the incoming files come in in order.  However, I
don't know how to specify the sorter.

context.addRoutes(new RouteBuilder() {
	public void configure() {
		JndiContext jcontext = null;
		try{
			jcontext = new JndiContext();
			jcontext.bind("DeadLetterChannelProcessor",
DeadLetterChannelProcessor.getInstance());
			jcontext.bind("DPIFileSorter", new DPIFileSorter());
		} catch (Exception e){
			logger.error("Unable to create camel context in MultiFormatDPI", e);
		}
	
		from("file://"+dir+"?delete=true&sorter=#DPIFileSorter").
		
errorHandler(deadLetterChannel("bean:DeadLetterChannelProcessor?method=handleError").maximumRedeliveries(1)).process(new
Processor() {
			public void process(Exchange e) {
				try {
					File file = (File)e.getIn().getBody(File.class);
					logger.info("Filename: " + file.toString());
					...


It is in the context and I reference it with either DPIFileSorter or
#DPIFileSorter, but I still get:
Caused by: java.lang.IllegalArgumentException: Could not find a suitable
setter for property: sorter as there isn't a setter methd with same type:
java.lang.String nor type conversion possible: No type converter available
to convert from type: java.lang.Strig to the required type:
java.util.Comparator with value DPIFileSorter


Thanks for your help.
-- 
View this message in context: http://old.nabble.com/How-do-I-specify-sorting-in-file-component--tp28044191p28044191.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How do I specify sorting in file component?

Posted by Stephen Gargan <st...@gmail.com>.
This is coming down to how you are specifying the JndiContext. You
need to add your Comparator to the registry being used by the
CamelContext. If you are working with spring then your bean will be
automatically included in the registry. If you're working in plain
Java then you need to add a registry/JNDIContext when the CamelContext
is created.

If the bean reference is missing you'll get the string conversion
error that you're seeing. In your test you're adding it to a reg, jsut
not hte one used by the camell context.

The following CamelTestSupport test illustrates how to add beans to
the reg. You use the #beanname mechanism to retrieve registry
references.

public class FileSortTest extends CamelTestSupport {

    protected JndiRegistry createRegistry() throws Exception {
        Logger.getRootLogger().addAppender(new ConsoleAppender(new
PatternLayout("%c - %m%n")));
        JndiRegistry registry = super.createRegistry();

        registry.bind("mySorter", new Comparator<GenericFile>() {
            public int compare(GenericFile o1, GenericFile o2)
            {
                return o1.getFileName().compareToIgnoreCase(o2.getFileName());
            }
        });
        return registry;
    }

    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("file:///tmp/test?sorter=#mySorter").to("log:out");
            }
        };
    }

    @Test
    public void testFileSort() throws Exception {
        Thread.sleep(10000);
    }
}


Under the covers the Test is doing. new DefaultCamelContext(createRegistry());

Give this a try it should work fine for you.

rgds,

ste

On Fri, Mar 26, 2010 at 9:18 AM, sub3 <st...@subwest.com> wrote:
>
> Nope, I still get the same exception about wanting a Comparator but getting a
> string. Thanks.
>
>
>
> S. Ali Tokmen-4 wrote:
>>
>> Hello
>>
>> Please try the full class name (with package).
>>
>> For example: sorter=org.apache.camel.sorter.DPIFileSorter
>>
>> Cheers
>>
>> S. Ali Tokmen
>> savas-ali.tokmen@bull.net
>>
>> Office: +33 4 76 29 76 19
>> GSM:    +33 66 43 00 555
>>
>> Bull, Architect of an Open World TM
>> http://www.bull.com
>>
>>
>> Le 26/03/2010 16:36, sub3 a écrit :
>>> Hi,
>>> Can someone tell me what I am doing wrong.  I am using the File component
>>> and I am trying to make the incoming files come in in order.  However, I
>>> don't know how to specify the sorter.
>>>
>>> context.addRoutes(new RouteBuilder() {
>>>      public void configure() {
>>>              JndiContext jcontext = null;
>>>              try{
>>>                      jcontext = new JndiContext();
>>>                      jcontext.bind("DeadLetterChannelProcessor",
>>> DeadLetterChannelProcessor.getInstance());
>>>                      jcontext.bind("DPIFileSorter", new DPIFileSorter());
>>>              } catch (Exception e){
>>>                      logger.error("Unable to create camel context in MultiFormatDPI", e);
>>>              }
>>>
>>>              from("file://"+dir+"?delete=true&sorter=#DPIFileSorter").
>>>
>>> errorHandler(deadLetterChannel("bean:DeadLetterChannelProcessor?method=handleError").maximumRedeliveries(1)).process(new
>>> Processor() {
>>>                      public void process(Exchange e) {
>>>                              try {
>>>                                      File file = (File)e.getIn().getBody(File.class);
>>>                                      logger.info("Filename: " + file.toString());
>>>                                      ...
>>>
>>>
>>> It is in the context and I reference it with either DPIFileSorter or
>>> #DPIFileSorter, but I still get:
>>> Caused by: java.lang.IllegalArgumentException: Could not find a suitable
>>> setter for property: sorter as there isn't a setter methd with same type:
>>> java.lang.String nor type conversion possible: No type converter
>>> available
>>> to convert from type: java.lang.Strig to the required type:
>>> java.util.Comparator with value DPIFileSorter
>>>
>>>
>>> Thanks for your help.
>>>
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/How-do-I-specify-sorting-in-file-component--tp28044191p28044761.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Re: How do I specify sorting in file component?

Posted by sub3 <st...@subwest.com>.
Nope, I still get the same exception about wanting a Comparator but getting a
string. Thanks.



S. Ali Tokmen-4 wrote:
> 
> Hello
> 
> Please try the full class name (with package).
> 
> For example: sorter=org.apache.camel.sorter.DPIFileSorter
> 
> Cheers
> 
> S. Ali Tokmen
> savas-ali.tokmen@bull.net
> 
> Office: +33 4 76 29 76 19
> GSM:    +33 66 43 00 555
> 
> Bull, Architect of an Open World TM
> http://www.bull.com
> 
> 
> Le 26/03/2010 16:36, sub3 a écrit :
>> Hi,
>> Can someone tell me what I am doing wrong.  I am using the File component
>> and I am trying to make the incoming files come in in order.  However, I
>> don't know how to specify the sorter.
>>
>> context.addRoutes(new RouteBuilder() {
>> 	public void configure() {
>> 		JndiContext jcontext = null;
>> 		try{
>> 			jcontext = new JndiContext();
>> 			jcontext.bind("DeadLetterChannelProcessor",
>> DeadLetterChannelProcessor.getInstance());
>> 			jcontext.bind("DPIFileSorter", new DPIFileSorter());
>> 		} catch (Exception e){
>> 			logger.error("Unable to create camel context in MultiFormatDPI", e);
>> 		}
>> 	
>> 		from("file://"+dir+"?delete=true&sorter=#DPIFileSorter").
>> 		
>> errorHandler(deadLetterChannel("bean:DeadLetterChannelProcessor?method=handleError").maximumRedeliveries(1)).process(new
>> Processor() {
>> 			public void process(Exchange e) {
>> 				try {
>> 					File file = (File)e.getIn().getBody(File.class);
>> 					logger.info("Filename: " + file.toString());
>> 					...
>>
>>
>> It is in the context and I reference it with either DPIFileSorter or
>> #DPIFileSorter, but I still get:
>> Caused by: java.lang.IllegalArgumentException: Could not find a suitable
>> setter for property: sorter as there isn't a setter methd with same type:
>> java.lang.String nor type conversion possible: No type converter
>> available
>> to convert from type: java.lang.Strig to the required type:
>> java.util.Comparator with value DPIFileSorter
>>
>>
>> Thanks for your help.
>>    
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-do-I-specify-sorting-in-file-component--tp28044191p28044761.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How do I specify sorting in file component?

Posted by "S. Ali Tokmen" <sa...@bull.net>.
Hello

Please try the full class name (with package).

For example: sorter=org.apache.camel.sorter.DPIFileSorter

Cheers

S. Ali Tokmen
savas-ali.tokmen@bull.net

Office: +33 4 76 29 76 19
GSM:    +33 66 43 00 555

Bull, Architect of an Open World TM
http://www.bull.com


Le 26/03/2010 16:36, sub3 a écrit :
> Hi,
> Can someone tell me what I am doing wrong.  I am using the File component
> and I am trying to make the incoming files come in in order.  However, I
> don't know how to specify the sorter.
>
> context.addRoutes(new RouteBuilder() {
> 	public void configure() {
> 		JndiContext jcontext = null;
> 		try{
> 			jcontext = new JndiContext();
> 			jcontext.bind("DeadLetterChannelProcessor",
> DeadLetterChannelProcessor.getInstance());
> 			jcontext.bind("DPIFileSorter", new DPIFileSorter());
> 		} catch (Exception e){
> 			logger.error("Unable to create camel context in MultiFormatDPI", e);
> 		}
> 	
> 		from("file://"+dir+"?delete=true&sorter=#DPIFileSorter").
> 		
> errorHandler(deadLetterChannel("bean:DeadLetterChannelProcessor?method=handleError").maximumRedeliveries(1)).process(new
> Processor() {
> 			public void process(Exchange e) {
> 				try {
> 					File file = (File)e.getIn().getBody(File.class);
> 					logger.info("Filename: " + file.toString());
> 					...
>
>
> It is in the context and I reference it with either DPIFileSorter or
> #DPIFileSorter, but I still get:
> Caused by: java.lang.IllegalArgumentException: Could not find a suitable
> setter for property: sorter as there isn't a setter methd with same type:
> java.lang.String nor type conversion possible: No type converter available
> to convert from type: java.lang.Strig to the required type:
> java.util.Comparator with value DPIFileSorter
>
>
> Thanks for your help.
>