Camel fails to rename/delete the source file

2022-03-07 Thread Reto Peter
I am trying to convert an EDIFACT file into an XML file.
The conversion is done with smooks. The conversion works fine. The target file 
is successfully converted and also written to the disk.
The problem arises after when Camel try to move the file to the .camel subdir.
The source file is copied to the subdir, but the original file cannot be 
deleted.

Environment: Windows 10, Java 11, Camel 3.15, Smooks 2.0.0RC1, running in 
eclipse
If I omit the line with ".process(processor)", the file can be moved/deleted. 
But with executing the smooks step it always gives me error messages, (attached 
at the end of this post)

Following code shows the main program:
   public static void main(String[] args) throws Exception {
  CamelContext context = new DefaultCamelContext();
  context.addRoutes(new RouteBuilder() {

 @Override
 public void configure() throws Exception {

   Smooks smooks = new Smooks();
   smooks.setReaderConfig(new 
EdifactReaderConfigurator("/d01b/EDIFACT-Messages.dfdl.xsd"));
   smooks.setExports(new Exports(StringResult.class));
   SmooksProcessor processor = new 
SmooksProcessor(smooks, context);

   
from("file://C:/data/MediaMarkt/ORDERS/in?delay=1000")
  .process(processor)
  
.to("file://C:/data/MediaMarkt/ORDERS/out/?fileName=${file:name}.xml");
}

 });
 context.start();
 Thread.sleep(2);
 context.close();

   }

Error message:
[  main] ScannerWARN  Not 
scanning classpath for ClassLoader 
'jdk.internal.loader.ClassLoaders$AppClassLoader'.  ClassLoader must implement 
'java.net.URLClassLoader'.
[  main] ScannerWARN  Not 
scanning classpath for ClassLoader 
'jdk.internal.loader.ClassLoaders$AppClassLoader'.  ClassLoader must implement 
'java.net.URLClassLoader'.
[  main] SmooksProcessorWARN  
Attachments module could not be found: attachments will not be propagated
[  main] SmooksProcessorINFO  
SmooksProcessor [configUri=null] Started
[  main] SmooksProcessorWARN  
Attachments module could not be found: attachments will not be propagated
[  main] SmooksProcessorINFO  
SmooksProcessor [configUri=null] Started
[  main] SmooksProcessorWARN  
Attachments module could not be found: attachments will not be propagated
[  main] SmooksProcessorINFO  
SmooksProcessor [configUri=null] Started
[  main] SmooksProcessorWARN  
Attachments module could not be found: attachments will not be propagated
[  main] SmooksProcessorINFO  
SmooksProcessor [configUri=null] Started
[  main] SmooksProcessorWARN  
Attachments module could not be found: attachments will not be propagated
[  main] SmooksProcessorINFO  
SmooksProcessor [configUri=null] Started
[  main] AbstractCamelContext   INFO  Routes 
startup (total:1 started:1)
[  main] AbstractCamelContext   INFO  
Started route1 (file://C:/data/MediaMarkt/ORDERS/in)
[  main] AbstractCamelContext   INFO  Apache 
Camel 3.15.0 (camel-1) started in 193ms (build:36ms init:136ms start:21ms)
CamelContext status: Started
[//C:/data/MediaMarkt/ORDERS/in] DataProcessorFactory   INFO  Compiling 
and caching DFDL schema...
[//C:/data/MediaMarkt/ORDERS/in] GenericFileOnCompletionWARN  Error 
during commit. Exchange[0C5E19CEB8FC187-]. Caused by: 
[org.apache.camel.component.file.GenericFileOperationFailedException - Error 
renaming file from C:\data\MediaMarkt\ORDERS\in\ORDERS 
000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi to 
C:\data\MediaMarkt\ORDERS\in\.camel\ORDERS 
000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi]
org.apache.camel.component.file.GenericFileOperationFailedException: Error 
renaming file from C:\data\MediaMarkt\ORDERS\in\ORDERS 
000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi to 
C:\data\MediaMarkt\ORDERS\in\.camel\ORDERS 
000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi
   at 
org.apache.camel.component.file.FileOperations.renameFile(FileOperations.java:93)
 ~[camel-file-3.15.0.jar:3.15.0]
   at 
org.apache.camel.component.file.strategy.GenericFileProcessStrategySupport.renameFile(GenericFileProcessStrategySupport.java:145)
 ~[camel-fil

RE: Camel fails to rename/delete the source file

2022-03-07 Thread Reto Peter
Hi Claus

Thanks for the fast answer!
Well, this is the smooks processor, not my custom processor.
Does that mean, the Camel file component does give the file access to the next 
component and not just the file content?
Sorry, I am a Camel beginner.

Regards Reto

-Original Message-
From: Claus Ibsen  
Sent: Monday, March 7, 2022 4:41 PM
To: users@camel.apache.org
Subject: Re: Camel fails to rename/delete the source file

Hi

That is because you do something in the custom processor that locks the file.
You need to make sure you close the file / input stream etc that you may be 
doing.

On Mon, Mar 7, 2022 at 9:14 AM Reto Peter  wrote:
>
> I am trying to convert an EDIFACT file into an XML file.
>
> The conversion is done with smooks. The conversion works fine. The target 
> file is successfully converted and also written to the disk.
>
> The problem arises after when Camel try to move the file to the .camel subdir.
>
> The source file is copied to the subdir, but the original file cannot be 
> deleted.
>
>
>
> Environment: Windows 10, Java 11, Camel 3.15, Smooks 2.0.0RC1, running 
> in eclipse
>
> If I omit the line with “.process(processor)”, the file can be 
> moved/deleted. But with executing the smooks step it always gives me 
> error messages, (attached at the end of this post)
>
>
>
> Following code shows the main program:
>
>public static void main(String[] args) throws Exception {
>
>   CamelContext context = new DefaultCamelContext();
>
>   context.addRoutes(new RouteBuilder() {
>
>
>
>  @Override
>
>  public void configure() throws Exception {
>
>
>
>Smooks smooks = new Smooks();
>
>smooks.setReaderConfig(new 
> EdifactReaderConfigurator("/d01b/EDIFACT-Messages.dfdl.xsd"));
>
>smooks.setExports(new 
> Exports(StringResult.class));
>
>SmooksProcessor processor = new 
> SmooksProcessor(smooks, context);
>
>
>
>
> from("file://C:/data/MediaMarkt/ORDERS/in?delay=1000")
>
>   .process(processor)
>
>   
> .to("file://C:/data/MediaMarkt/ORDERS/out/?fileName=${file:name}.xml")
> ;
>
> }
>
>
>
>  });
>
>  context.start();
>
>  Thread.sleep(2);
>
>  context.close();
>
>
>
>}
>
>
>
> Error message:
>
> [  main] ScannerWARN  Not 
> scanning classpath for ClassLoader 
> 'jdk.internal.loader.ClassLoaders$AppClassLoader'.  ClassLoader must 
> implement 'java.net.URLClassLoader'.
>
> [  main] ScannerWARN  Not 
> scanning classpath for ClassLoader 
> 'jdk.internal.loader.ClassLoaders$AppClassLoader'.  ClassLoader must 
> implement 'java.net.URLClassLoader'.
>
> [  main] SmooksProcessorWARN  
> Attachments module could not be found: attachments will not be propagated
>
> [  main] SmooksProcessorINFO  
> SmooksProcessor [configUri=null] Started
>
> [  main] SmooksProcessorWARN  
> Attachments module could not be found: attachments will not be propagated
>
> [  main] SmooksProcessorINFO  
> SmooksProcessor [configUri=null] Started
>
> [  main] SmooksProcessorWARN  
> Attachments module could not be found: attachments will not be propagated
>
> [  main] SmooksProcessorINFO  
> SmooksProcessor [configUri=null] Started
>
> [  main] SmooksProcessorWARN  
> Attachments module could not be found: attachments will not be propagated
>
> [  main] SmooksProcessorINFO  
> SmooksProcessor [configUri=null] Started
>
> [  main] SmooksProcessorWARN  
> Attachments module could not be found: attachments will not be propagated
>
> [  main] SmooksProcessorINFO  
> SmooksProcessor [configUri=null] Started
>
> [  main] AbstractCamelContext   INFO  Routes 
> startup (total:1 started:1)
>
> [  main] AbstractCamelContext   INFO  
> Started route1 (file://C:/data/MediaMarkt/ORDERS/in)

RE: Camel fails to rename/delete the source file

2022-03-07 Thread Reto Peter
Hi

Super. That works!!!

-Original Message-
From: Claus Ibsen  
Sent: Monday, March 7, 2022 6:03 PM
To: users@camel.apache.org
Subject: Re: Camel fails to rename/delete the source file

Hi

Yes it depends what smooks does, but you can change the message body from a 
file / input stream and read it into memory as a string and then give that to 
smooks.
Then smooks dont have anything to worry about closing file handles / resources

So try add before the processor

.convertBodyTo(String.class)


On Mon, Mar 7, 2022 at 10:40 AM Reto Peter  wrote:
>
> Hi Claus
>
> Thanks for the fast answer!
> Well, this is the smooks processor, not my custom processor.
> Does that mean, the Camel file component does give the file access to the 
> next component and not just the file content?
> Sorry, I am a Camel beginner.
>
> Regards Reto
>
> -Original Message-
> From: Claus Ibsen 
> Sent: Monday, March 7, 2022 4:41 PM
> To: users@camel.apache.org
> Subject: Re: Camel fails to rename/delete the source file
>
> Hi
>
> That is because you do something in the custom processor that locks the file.
> You need to make sure you close the file / input stream etc that you may be 
> doing.
>
> On Mon, Mar 7, 2022 at 9:14 AM Reto Peter  wrote:
> >
> > I am trying to convert an EDIFACT file into an XML file.
> >
> > The conversion is done with smooks. The conversion works fine. The target 
> > file is successfully converted and also written to the disk.
> >
> > The problem arises after when Camel try to move the file to the .camel 
> > subdir.
> >
> > The source file is copied to the subdir, but the original file cannot be 
> > deleted.
> >
> >
> >
> > Environment: Windows 10, Java 11, Camel 3.15, Smooks 2.0.0RC1, 
> > running in eclipse
> >
> > If I omit the line with “.process(processor)”, the file can be 
> > moved/deleted. But with executing the smooks step it always gives me 
> > error messages, (attached at the end of this post)
> >
> >
> >
> > Following code shows the main program:
> >
> >public static void main(String[] args) throws Exception {
> >
> >   CamelContext context = new DefaultCamelContext();
> >
> >   context.addRoutes(new RouteBuilder() {
> >
> >
> >
> >  @Override
> >
> >  public void configure() throws Exception {
> >
> >
> >
> >Smooks smooks = new Smooks();
> >
> >smooks.setReaderConfig(new 
> > EdifactReaderConfigurator("/d01b/EDIFACT-Messages.dfdl.xsd"));
> >
> >smooks.setExports(new 
> > Exports(StringResult.class));
> >
> >SmooksProcessor processor = new 
> > SmooksProcessor(smooks, context);
> >
> >
> >
> >
> > from("file://C:/data/MediaMarkt/ORDERS/in?delay=1000")
> >
> >   .process(processor)
> >
> >
> > .to("file://C:/data/MediaMarkt/ORDERS/out/?fileName=${file:name}.xml
> > ")
> > ;
> >
> > }
> >
> >
> >
> >  });
> >
> >  context.start();
> >
> >  Thread.sleep(2);
> >
> >  context.close();
> >
> >
> >
> >}
> >
> >
> >
> > Error message:
> >
> > [  main] ScannerWARN  Not 
> > scanning classpath for ClassLoader 
> > 'jdk.internal.loader.ClassLoaders$AppClassLoader'.  ClassLoader must 
> > implement 'java.net.URLClassLoader'.
> >
> > [  main] ScannerWARN  Not 
> > scanning classpath for ClassLoader 
> > 'jdk.internal.loader.ClassLoaders$AppClassLoader'.  ClassLoader must 
> > implement 'java.net.URLClassLoader'.
> >
> > [  main] SmooksProcessorWARN  
> > Attachments module could not be found: attachments will not be propagated
> >
> > [  main] SmooksProcessorINFO  
> > SmooksProcessor [configUri=null] Started
> >
> > [  main] SmooksProcessorWARN  
> > Attachments module could not be found: attachments will not be propagated
> >
> > [  main] SmooksProcessorINFO  
> >

CamelSqlGeneratedKeyRows is not updated

2022-03-23 Thread Reto Peter
Hi

I have a route with 2 following SQL INSERT commands.
One inserts into table A (CamelSqlGeneratedKeyRows is correct)
Next inserts into table B (CamelSqlGeneratedKeyRows is wrong, the value is not 
updated, it remains the same)

I am using mySQL and Java 11

My simplified route:
 
from("file:{{dir.from.flowline.test}}?preMove=.inprogress&move=.done&delay=1000")
.tracing()
.log("Processing file: ${file:name}")
.convertBodyTo(String.class)
.setHeader("CamelSqlRetrieveGeneratedKeys").simple("true")
.to("sql:INSERT INTO files_from_partner(filename, 
filecontent, partner_id) VALUES (:#${file:name},:#${body}, 1)")
.log("${headers.CamelSqlGeneratedKeyRows}")
.to("sql:INSERT INTO message_out(identifier) VALUES (1)")
.log("${headers.CamelSqlGeneratedKeyRows}");

Output when I process 1 files is:
Processing file: GDELR_1848540_BL-V2100029_55234 use it 4 TESTS II.xml
[{GENERATED_KEY=58}] correct
[{GENERATED_KEY=58}] wrong

Do I do something wrong, is it a bug?
I also tried to set the Header CamelSqlGeneratedColumns as follows:
@Component
class SetFilesFromPartnerKeyColumnsBean {
   public void setKeys(String message, @Headers Map 
outHeaders) {
 outHeaders.put("CamelSqlGeneratedColumns", new String[] 
{"files_id"});
   }
} And before executing the SQL INSERT in the route: 
.bean(setFilesFromPartnerKeyColumnsBean)
But there was no effect, same results

MY workaround is with the "SELECT LAST_INSERT_ID()" which works but of course 
not the way we should ...

Regards Reto


Re: CamelSqlGeneratedKeyRows is not updated

2022-03-23 Thread Reto Peter
Ya sorry.
Camel version: 3.15.0

On 23 March 2022 17:03:19 Andrea Cosentino  wrote:

Report the camel version, please

Il mer 23 mar 2022, 09:59 Reto Peter  ha scritto:

Hi

I have a route with 2 following SQL INSERT commands.
One inserts into table A (CamelSqlGeneratedKeyRows is correct)
Next inserts into table B (CamelSqlGeneratedKeyRows is wrong, the value is
not updated, it remains the same)

I am using mySQL and Java 11

My simplified route:

from("file:{{dir.from.flowline.test}}?preMove=.inprogress&move=.done&delay=1000")
.tracing()
.log("Processing file: ${file:name}")
.convertBodyTo(String.class)

.setHeader("CamelSqlRetrieveGeneratedKeys").simple("true")
.to("sql:INSERT INTO files_from_partner(filename,
filecontent, partner_id) VALUES (:#${file:name},:#${body}, 1)")
.log("${headers.CamelSqlGeneratedKeyRows}")
.to("sql:INSERT INTO message_out(identifier) VALUES
(1)")
.log("${headers.CamelSqlGeneratedKeyRows}");

Output when I process 1 files is:
Processing file: GDELR_1848540_BL-V2100029_55234 use it 4 TESTS II.xml
[{GENERATED_KEY=58}] correct
[{GENERATED_KEY=58}] wrong

Do I do something wrong, is it a bug?
I also tried to set the Header CamelSqlGeneratedColumns as follows:
@Component
class SetFilesFromPartnerKeyColumnsBean {
public void setKeys(String message, @Headers Map
outHeaders) {
 outHeaders.put("CamelSqlGeneratedColumns", new String[]
{"files_id"});
}
} And before executing the SQL INSERT in the route:
.bean(setFilesFromPartnerKeyColumnsBean)
But there was no effect, same results

MY workaround is with the "SELECT LAST_INSERT_ID()" which works but of
course not the way we should ...

Regards Reto



Sent with Aqua Mail for 
Android<https://play.google.com/store/apps/details?id=org.kman.AquaMail>
https://www.aqua-mail.com


RE: CamelSqlGeneratedKeyRows is not updated

2022-03-23 Thread Reto Peter
Hi

I tried both with no success
a) it works as normal, I get the keys back if I only run the 2nd select
b) I set the Header before first statement and before second statement but no 
change. 

-Original Message-
From: Claus Ibsen  
Sent: Thursday, March 24, 2022 3:51 AM
To: users@camel.apache.org
Subject: Re: CamelSqlGeneratedKeyRows is not updated

Hi

a)
Can you try with just 1 sql insert,
   .to("sql:INSERT INTO message_out(identifier) VALUES (1)")

It may be that this SQL does not return any generated keys


b)
Can you try to set the header to get keys before calling the 2nd insert
 .setHeader("CamelSqlRetrieveGeneratedKeys").simple("true")

On Wed, Mar 23, 2022 at 9:59 AM Reto Peter  wrote:
>
> Hi
>
> I have a route with 2 following SQL INSERT commands.
> One inserts into table A (CamelSqlGeneratedKeyRows is correct) Next 
> inserts into table B (CamelSqlGeneratedKeyRows is wrong, the value is 
> not updated, it remains the same)
>
> I am using mySQL and Java 11
>
> My simplified route:
>  
> from("file:{{dir.from.flowline.test}}?preMove=.inprogress&move=.done&delay=1000")
> .tracing()
> .log("Processing file: ${file:name}")
> .convertBodyTo(String.class)
> .setHeader("CamelSqlRetrieveGeneratedKeys").simple("true")
> .to("sql:INSERT INTO files_from_partner(filename, 
> filecontent, partner_id) VALUES (:#${file:name},:#${body}, 1)")
> .log("${headers.CamelSqlGeneratedKeyRows}")
> .to("sql:INSERT INTO message_out(identifier) VALUES (1)")
> .log("${headers.CamelSqlGeneratedKeyRows}");
>
> Output when I process 1 files is:
> Processing file: GDELR_1848540_BL-V2100029_55234 use it 4 TESTS II.xml 
> [{GENERATED_KEY=58}] correct [{GENERATED_KEY=58}] wrong
>
> Do I do something wrong, is it a bug?
> I also tried to set the Header CamelSqlGeneratedColumns as follows:
> @Component
> class SetFilesFromPartnerKeyColumnsBean {
>public void setKeys(String message, @Headers Map 
> outHeaders) {
>  outHeaders.put("CamelSqlGeneratedColumns", new String[] 
> {"files_id"});
>}
> } And before executing the SQL INSERT in the route: 
> .bean(setFilesFromPartnerKeyColumnsBean)
> But there was no effect, same results
>
> MY workaround is with the "SELECT LAST_INSERT_ID()" which works but of course 
> not the way we should ...
>
> Regards Reto



--
Claus Ibsen
-
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


JdbcAggregationRepository is not permanently?

2022-04-05 Thread Reto Peter
Hi

Using the JdbcAggregationRepository I am trying to save the relation between my 
incoming messages and the aggregate, as a 1-n relation. It is actually the EDI 
Messages (Single message) into the EDI Interchange (Collection of messages).
When I run the route, I see that the entries are available in the my-SQL 
aggregation table.
If the aggregate is finished, then all the entries are gone, both tables 
aggregation and aggregation_completed are empty
Is that normal? Or Do I have an error somewhere in my setup?

I was trying to find another solution to get my relation saved. In my 
AggregatorStrategy class, in the aggregate method I did save a list of 
messages, and in the onCompletion method, I set that list as a Header. This 
works only if I use the correlationExpression 'true', but actually I do 
aggregate messages with same doctype like "DESADV" and "INVOIC" and then the 
value of the Header is always just the one from the last processed aggregate

My route looks like this (simplified)

from("file:{{dir.from}}")
.choice()
.when()setHeader("doctype").constant("DESADV")
.when()setHeader("doctype").constant("INVOICE")
.aggregate(header("doctype"), new 
EDIMessageToInterchangeAggregator()).aggregationRepository("repo3")
.log("Header: ${header.messageIDList}") // Shows always the latest Aggregate 
Header only

If I run message for one doctype only, then it all works, cause there will only 
be one aggregate

My bean config is like this:
   
 
 
 
 

 
 
   
 doctype
 messageID
 interchangeID
   
 
   

   
   
   

My environment:
Camel 3.16.0
Java 11
SpringBoot 2.6.4
MySQL 8.x




RE: JdbcAggregationRepository is not permanently?

2022-04-08 Thread Reto Peter
Hi Karen

I actually need INSERT INTO  (interchangeID, messageID)

The question was if the AGGREGATE method can save the relation between the 
incoming MESSAGES(files) and the produced AGGREGATE (INTERCHANGE) inside the 
database without any hassle. With the aggregation repo that would be there 
automatically. But its only temporary...

So I do need a db-table with InterchangeID as the PRIMARY KEY and MessageID as 
foreign Key. Many Messages(files) for 1 Interchange (Aggregate). In my case I 
do have different incoming type of messages (DESADV and INVOIC)
I solved this issue already inside the AggregatorStrategy. I saved the 
MessageID's in a list there for each doctype (desadvMessageIDs and 
invoicMessageIds) At "onCompletion" then I do set the outgoing Header to the 
specific messageIDs. Inside the route then I do update the related messages 
with the created InterchangeID.

It took me a lot of time to find this solutionbut now it all works

-Original Message-
From: Karen Lease  
Sent: Friday, April 8, 2022 9:34 PM
To: users@camel.apache.org
Subject: Re: JdbcAggregationRepository is not permanently?

Hi,

To store the aggregated results, you need to create a separate table in your 
database.
Then you can add something like the following statement to your route after the 
aggregation:

.to("sql:insert into messages (doctype, messageID) values (:#doctype, 
:#messageID)"); The values of the named parameters will be taken from the 
corresponding headers in the aggregated Exchange.


On 05/04/2022 10:12, Reto Peter wrote:
> Hi
> 
> Using the JdbcAggregationRepository I am trying to save the relation between 
> my incoming messages and the aggregate, as a 1-n relation. It is actually the 
> EDI Messages (Single message) into the EDI Interchange (Collection of 
> messages).
> When I run the route, I see that the entries are available in the my-SQL 
> aggregation table.
> If the aggregate is finished, then all the entries are gone, both 
> tables aggregation and aggregation_completed are empty Is that normal? Or Do 
> I have an error somewhere in my setup?
> 
> I was trying to find another solution to get my relation saved. In my 
> AggregatorStrategy class, in the aggregate method I did save a list of 
> messages, and in the onCompletion method, I set that list as a Header. 
> This works only if I use the correlationExpression 'true', but 
> actually I do aggregate messages with same doctype like "DESADV" and 
> "INVOIC" and then the value of the Header is always just the one from 
> the last processed aggregate
> 
> My route looks like this (simplified)
> 
> from("file:{{dir.from}}")
> .choice()
> .when()setHeader("doctype").constant("DESADV")
> .when()setHeader("doctype").constant("INVOICE")
> .aggregate(header("doctype"), new 
> EDIMessageToInterchangeAggregator()).aggregationRepository("repo3")
> .log("Header: ${header.messageIDList}") // Shows always the latest 
> Aggregate Header only
> 
> If I run message for one doctype only, then it all works, cause there 
> will only be one aggregate
> 
> My bean config is like this:
>
> class="org.apache.camel.processor.aggregate.jdbc.JdbcAggregationRepository">
>   
>   
>   
>   
> 
>   
>   
> 
>   doctype
>   messageID
>   interchangeID
> 
>   
> 
> 
>  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
> 
> 
> 

> 
> 
> 


DropBox expired_token

2022-04-10 Thread Reto Peter
Hi

I have successfully used the dropbox component for download, upload and delete 
files.
You can see my implementation below, cause there was some important issues to 
solve before it worked

Actually the only problem I have is the expired_token. The generated token 
(which I created in the app console) does always expire after 4 hours and then 
I get the error message from the component:
InvalidAccessTokenException: {"error_summary": "expired_access_token/...", 
"error": {".tag": "expired_access_token"}}

I read about other SDK which access the dropbox API, that the API does handle 
to refresh the access_token if its expired.
What is my mistake? Is there a way to generate a permament access_token in 
dropbox itself or how?

Here is my route for DOWNLOAD:
from("timer://simpleTimer?period=1")
   .to("dropbox://get?accessToken={{dropbox.accessToken}}"
  + "&clientIdentifier={{drobbox.clientIdentifier}}"
  + "&remotePath=/from_cellular")
   .log("Dropbox download 'from Cellular': Check if there are files 
available from Cellular in DropBox CellularEDI")
   .choice()
  .when(simple("${header:DOWNLOADED_FILES} == ''"))
.log("Dropbox download: No files available")
  .when(simple("${header:DOWNLOADED_FILES} == null && 
${header:DOWNLOADED_FILE} != ''"))
.log("Dropbox download: 1 file available: 
'${header:DOWNLOADED_FILE}'")

.to("file:{{dir.from.cellular}}?fileName=${header:DOWNLOADED_FILE}")
.toD("dropbox://del?accessToken={{dropbox.accessToken}}"
   + "&clientIdentifier={{drobbox.clientIdentifier}}"
   + "&remotePath=${header:DOWNLOADED_FILE}")
  .when(simple("${header:DOWNLOADED_FILES} != '' && 
${header:DOWNLOADED_FILE} == null"))
.log("Dropbox download: Several files available: 
'${header:DOWNLOADED_FILES}'")
.split(simple("${in.body.entrySet}"))
.setHeader("DropBoxFileName", simple("${body.getKey}"))
.setBody(simple("${body.getValue}"))
.log("Dropbox download: Save file: 
${header.DropBoxFileName}")

.to("file:{{dir.from.cellular}}?fileName=${header.DropBoxFileName}")
.toD("dropbox://del?accessToken={{dropbox.accessToken}}"
   + "&clientIdentifier={{drobbox.clientIdentifier}}"
   + "&remotePath=${header.DropBoxFileName}");

Here is my route for UPLOAD:
from("file:{{dir.to.cellular}}?preMove=.inprogress&move=.done&delay=1000")
   .log("Dropbox upoad: Trying to upload file ${file:name} to DropBox 
CellularEDI")
   .setHeader(DropboxConstants.HEADER_PUT_FILE_NAME, simple("${file:name}"))
   .to("dropbox://put?accessToken={{dropbox.accessToken}}"
 + "&clientIdentifier={{drobbox.clientIdentifier}}"
 + "&uploadMode=force"
 + "&remotePath=/to_cellular/")
   // The upload does not work if I don't put the last '/'
   .choice()
  .when(simple("${body} == 'OK'"))
 .log("Dropbox upload success: File ${file:name} was uploaded to 
DropBox folder: ${header:UPLOADED_FILE}")
   .otherwise()
 .log("Dropbox upload FAILED: File ${file:name} Failed with result: 
${body}");


Environment:
Camel 3.16.0
SpringBoot 2.6.4
Java 11

Reto


RE: DropBox expired_token

2022-04-11 Thread Reto Peter
Hi Claus

It looks like that dropbox will now only issue short-lived access tokens and 
working with additional refresh tokens.
From dropbox doc:
On September 30th, 2021, Dropbox will retire the creation of long-lived access 
tokens. Apps that require background (“offline”) access but have not yet 
implemented refresh tokens will be impacted.
Implement refresh tokens: For apps that "Want to interact with the Dropbox API 
when a user isn’t actively interacting with the app (“offline” access)", we 
offer a long-lived refresh_token that can be used to request a new, short-lived 
access token.

I think there must be an adjustment in the API Camel is using.

Reto

-Original Message-
From: Claus Ibsen  
Sent: Monday, April 11, 2022 7:35 PM
To: users@camel.apache.org
Subject: Re: DropBox expired_token

Hi

Ah is that because your token is some kind of developer token that is short 
lived?
Or do you know if its standard at DropBox to have tokens limited to 4 hours?

If its so short lived, then we should look at a way for Camel to be able to 
automatic extend the token expiry, fetch a updated token, or what means DropBox 
supports.


On Mon, Apr 11, 2022 at 8:14 AM Reto Peter  wrote:
>
> Hi
>
> I have successfully used the dropbox component for download, upload and 
> delete files.
> You can see my implementation below, cause there was some important 
> issues to solve before it worked
>
> Actually the only problem I have is the expired_token. The generated token 
> (which I created in the app console) does always expire after 4 hours and 
> then I get the error message from the component:
> InvalidAccessTokenException: {"error_summary": 
> "expired_access_token/...", "error": {".tag": "expired_access_token"}}
>
> I read about other SDK which access the dropbox API, that the API does handle 
> to refresh the access_token if its expired.
> What is my mistake? Is there a way to generate a permament access_token in 
> dropbox itself or how?
>
> Here is my route for DOWNLOAD:
> from("timer://simpleTimer?period=1")
>.to("dropbox://get?accessToken={{dropbox.accessToken}}"
>   + "&clientIdentifier={{drobbox.clientIdentifier}}"
>   + "&remotePath=/from_cellular")
>.log("Dropbox download 'from Cellular': Check if there are files 
> available from Cellular in DropBox CellularEDI")
>.choice()
>   .when(simple("${header:DOWNLOADED_FILES} == ''"))
> .log("Dropbox download: No files available")
>   .when(simple("${header:DOWNLOADED_FILES} == null && 
> ${header:DOWNLOADED_FILE} != ''"))
> .log("Dropbox download: 1 file available: 
> '${header:DOWNLOADED_FILE}'")
> 
> .to("file:{{dir.from.cellular}}?fileName=${header:DOWNLOADED_FILE}")
> .toD("dropbox://del?accessToken={{dropbox.accessToken}}"
>+ "&clientIdentifier={{drobbox.clientIdentifier}}"
>+ "&remotePath=${header:DOWNLOADED_FILE}")
>   .when(simple("${header:DOWNLOADED_FILES} != '' && 
> ${header:DOWNLOADED_FILE} == null"))
> .log("Dropbox download: Several files available: 
> '${header:DOWNLOADED_FILES}'")
> .split(simple("${in.body.entrySet}"))
> .setHeader("DropBoxFileName", simple("${body.getKey}"))
> .setBody(simple("${body.getValue}"))
> .log("Dropbox download: Save file: 
> ${header.DropBoxFileName}")
> 
> .to("file:{{dir.from.cellular}}?fileName=${header.DropBoxFileName}")
> .toD("dropbox://del?accessToken={{dropbox.accessToken}}"
>+ "&clientIdentifier={{drobbox.clientIdentifier}}"
>+ "&remotePath=${header.DropBoxFileName}");
>
> Here is my route for UPLOAD:
> from("file:{{dir.to.cellular}}?preMove=.inprogress&move=.done&delay=1000")
>.log("Dropbox upoad: Trying to upload file ${file:name} to DropBox 
> CellularEDI")
>.setHeader(DropboxConstants.HEADER_PUT_FILE_NAME, 
> simple("${file:name}"))
>.to("dropbox://put?accessToken={{dropbox.accessToken}}"
>  + "&clientIdentifier={{drobbox.clientIdentifier}}"
>  + "&uploadMode=force"
>  + "&remotePath=/to_cellular/")
>// The upload does not work if I don't put the last '/'
>.choice()
>   .when(simple("${body} == 'OK'"))
>  .log("Dropbox upload success: File ${file:name} was uploaded to 
> DropBox folder: ${header:UPLOADED_FILE}")
>.otherwise()
>  .log("Dropbox upload FAILED: File ${file:name} Failed 
> with result: ${body}");
>
>
> Environment:
> Camel 3.16.0
> SpringBoot 2.6.4
> Java 11
>
> Reto



--
Claus Ibsen
-
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


SFTP fails after upgrade to Camel 3.18.0

2022-07-13 Thread Reto Peter
Hi

In Camel 3.16.0 we did successfully use the SFTP component like this:

from("sftp://{{sftp.host}}:{{sftp.port}}/{{sftp.remotedir.from.customer}}";
  + "?username={{sftp.username}}"
  + "&password={{sftp.password}}"
  + 
"&useUserKnownHostsFile=false&delete=true&delay=3")

The version of the lib used was jsch-0.1.55.jar


After upgrading to Camel 3.18.0 we got errors like this:

org.apache.camel.component.file.GenericFileOperationFailedException: Cannot 
connect to sftp://xxx.com@xxx.hosting:5544
Caused by: com.jcraft.jsch.JSchException: Algorithm negotiation fail
  at com.jcraft.jsch.Session.receive_kexinit(Session.java:604)
  at com.jcraft.jsch.Session.connect(Session.java:334)
  at 
org.apache.camel.component.file.remote.SftpOperations.tryConnect(SftpOperations.java:160)
  at 
org.apache.camel.support.task.ForegroundTask.run(ForegroundTask.java:92)
  at 
org.apache.camel.component.file.remote.SftpOperations.connect(SftpOperations.java:135)

The lib used was jsch-0.2.1.jar

After replacing the new with the old library jsch-0.1.55.jar, everything works 
again
Any idea?


CXF: Unable to locate Spring NamespaceHandler

2022-09-10 Thread Reto Peter
Hi

I try to invoke my first Webservice with CXF inside Camel.
Camel: 3.18.2, Java 15, SpringBoot 2.7.3

But got the following error:
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema 
namespace [http://camel.apache.org/schema/cxf]

My POM includes CXF as follows:

   org.apache.camel.springboot
   camel-cxf-soap-starter
   ${camel.version} // is version 3.18.2


My beans-config as follows:
http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:cxf="http://camel.apache.org/schema/cxf";
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd";>
   http://services.xxx.xxx.com"; />

There must be a jar missing, but which one?


RE: Unable to locate Spring NamespaceHandler

2022-09-10 Thread Reto Peter
Hi

I finally found the correct namespaces inside the 3.18 Upgrade guide: 
https://camel.apache.org/manual/camel-3x-upgrade-guide-3_18.html and the error 
disappeared
But I now got the problem "Get the wrong parameter size to invoke the out 
service, Expect size 6, Parameter size 1. Please check if the message body 
matches the CXFEndpoint POJO Dataformat request."

.setHeader("username", simple("CONNECT"))
.setHeader("password", simple("F97DD39025331DA3DD857C134C43D93CFDE51C4B"))
.setHeader("orgID", simple("403"))
.bean(loginRequestBuilder, "getLogin")

.log("Body is: ${body}") --> my body consist of the Login POJO which is built 
by the loginRequestBuilder: Body is: com.xxx.xxx.services.Login@712739c3

.setHeader(CxfConstants.OPERATION_NAME, constant("login"))
.setHeader(CxfConstants.OPERATION_NAMESPACE, 
constant("http://services.mlsonline.sowatec.com";))

.to("cxf:bean:sessionServiceEndpoint")

>From the doc I know that the default message type is POJO. Does the POJO need 
>any special Annotation to be able to read the parameters of the Login object?
In my case it has public getters and setters and is annotated like this:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "login", propOrder = {
"userName",     "password", "anotherId","anotherIdx"," 
anotherIdxx"," anotherIdxx"
}) public class Login { 

-Original Message-
From: Reto Peter  
Sent: Saturday, 10 September 2022 10:43
To: users@camel.apache.org
Subject: CXF: Unable to locate Spring NamespaceHandler

Hi

I try to invoke my first Webservice with CXF inside Camel.
Camel: 3.18.2, Java 15, SpringBoot 2.7.3

But got the following error:
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema 
namespace [http://camel.apache.org/schema/cxf]

My POM includes CXF as follows:

   org.apache.camel.springboot
   camel-cxf-soap-starter
   ${camel.version} // is version 3.18.2 

My beans-config as follows:
http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:cxf="http://camel.apache.org/schema/cxf";
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd";>
   http://services.xxx.xxx.com"; />

There must be a jar missing, but which one?


Predicates

2022-10-17 Thread Reto Peter
Hi
I have a simple question about the Predicates
I got a systemConfig object, which has 2 getters/setters.
The systemConfig object is set as an exchange property.

When I use a the simple function, that works!
from("direct:testPredicates")
.to("direct:getSystemConfig")
   .choice()
.when(simple("${exchangeProperty.systemConfig.isActive} == false || 
${exchangeProperty.systemConfig.isEnabled} == false"))
   .log("System is active and System is enabled")
  .otherwise()
.log("System is not active or MLSSync is disabled")
   .end();

When I try to use Predicates, then I thought this should work like this:
Before the route:
Predicate isSystemActive = 
exchangeProperty("systemConfig.isActive").isEqualTo(true);
Predicate isSystemEnabled = 
exchangeProperty("systemConfig.isEnabled").isEqualTo(false);

Inside the route:
from("direct:testPredicates")
.to("direct:getSystemConfig")
   .choice()
  .when(and(isSystemActive, isSystemEnabled))
.log("System is active and System is enabled")
  .otherwise()
.log("System is not active or MLSSync is disabled")
   .end();

I am using Camel 3.18.2


RE: Predicates

2022-10-18 Thread Reto Peter
Hi Clause

So for a header I can define a Predicate, but for a property I can't?

Example with header: (that works?)
Predicate isSystemActive = header("isSystemActive").isEqualTo("true");

Example with property: (that doesn’t work?)
Predicate isSystemActive = exchangeProperty 
("systemConfig.isActive").isEqualTo(true);

So later I can use:
choice().when(isSystemActive)

-Original Message-
From: Claus Ibsen  
Sent: Monday, 17 October 2022 20:49
To: users@camel.apache.org
Subject: Re: Predicates

Hi

> exchangeProperty("systemConfig.isActive")

This is not simple language, but refers to a exchange property key with the 
given name.
You need to use simple as predicate instead of exchangeProperty






On Mon, Oct 17, 2022 at 7:38 PM Reto Peter  wrote:

> Hi
> I have a simple question about the Predicates I got a systemConfig 
> object, which has 2 getters/setters.
> The systemConfig object is set as an exchange property.
>
> When I use a the simple function, that works!
> from("direct:testPredicates")
> .to("direct:getSystemConfig")
>.choice()
> .when(simple("${exchangeProperty.systemConfig.isActive} == false || 
> ${exchangeProperty.systemConfig.isEnabled} == false"))
>.log("System is active and System is enabled")
>   .otherwise()
> .log("System is not active or MLSSync is disabled")
>.end();
>
> When I try to use Predicates, then I thought this should work like this:
> Before the route:
> Predicate isSystemActive =
> exchangeProperty("systemConfig.isActive").isEqualTo(true);
> Predicate isSystemEnabled =
> exchangeProperty("systemConfig.isEnabled").isEqualTo(false);
>
> Inside the route:
> from("direct:testPredicates")
> .to("direct:getSystemConfig")
>.choice()
>   .when(and(isSystemActive, isSystemEnabled))
> .log("System is active and System is enabled")
>   .otherwise()
> .log("System is not active or MLSSync is disabled")
>.end();
>
> I am using Camel 3.18.2
>


--
Claus Ibsen
-
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


RE: Predicates

2022-10-18 Thread Reto Peter
Hi Claus

Thanks! Now it works
I do use: Predicate isSystemActive = 
simple("${exchangeProperty.systemConfig.isActive}").isEqualTo(true);

-Original Message-
From: Claus Ibsen  
Sent: Tuesday, 18 October 2022 09:13
To: users@camel.apache.org
Subject: Re: Predicates

Hi

systemConfig.isActive is a key name, so that only works if the property is 
really named like that.
Its not doing any kind of method call - i.e. calling isActive() on the property 
with key , that the simple can do.

On Tue, Oct 18, 2022 at 9:01 AM Reto Peter  wrote:

> Hi Clause
>
> So for a header I can define a Predicate, but for a property I can't?
>
> Example with header: (that works?)
> Predicate isSystemActive = header("isSystemActive").isEqualTo("true");
>
> Example with property: (that doesn’t work?) Predicate isSystemActive = 
> exchangeProperty ("systemConfig.isActive").isEqualTo(true);
>
> So later I can use:
> choice().when(isSystemActive)
>
> -Original Message-
> From: Claus Ibsen 
> Sent: Monday, 17 October 2022 20:49
> To: users@camel.apache.org
> Subject: Re: Predicates
>
> Hi
>
> > exchangeProperty("systemConfig.isActive")
>
> This is not simple language, but refers to a exchange property key 
> with the given name.
> You need to use simple as predicate instead of exchangeProperty
>
>
>
>
>
>
> On Mon, Oct 17, 2022 at 7:38 PM Reto Peter 
> wrote:
>
> > Hi
> > I have a simple question about the Predicates I got a systemConfig 
> > object, which has 2 getters/setters.
> > The systemConfig object is set as an exchange property.
> >
> > When I use a the simple function, that works!
> > from("direct:testPredicates")
> > .to("direct:getSystemConfig")
> >.choice()
> > .when(simple("${exchangeProperty.systemConfig.isActive} == false || 
> > ${exchangeProperty.systemConfig.isEnabled} == false"))
> >.log("System is active and System is enabled")
> >   .otherwise()
> > .log("System is not active or MLSSync is disabled")
> >.end();
> >
> > When I try to use Predicates, then I thought this should work like this:
> > Before the route:
> > Predicate isSystemActive =
> > exchangeProperty("systemConfig.isActive").isEqualTo(true);
> > Predicate isSystemEnabled =
> > exchangeProperty("systemConfig.isEnabled").isEqualTo(false);
> >
> > Inside the route:
> > from("direct:testPredicates")
> > .to("direct:getSystemConfig")
> >.choice()
> >   .when(and(isSystemActive, isSystemEnabled))
> > .log("System is active and System is enabled")
> >   .otherwise()
> > .log("System is not active or MLSSync is disabled")
> >.end();
> >
> > I am using Camel 3.18.2
> >
>
>
> --
> Claus Ibsen
> -
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


--
Claus Ibsen
-
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


Splitter and Aggregater onCompletion

2022-11-08 Thread Reto Peter
Hi all

I am using a Splitter and an Aggregator.
All of the output are written into the final result. But at the end of the 
Split, I wanted to add something more.
This is where the 'onCompletion' method inside the Aggregator can be used (in 
my mind, cause that works for scenarios without a Splitter).

But if have the 'onCompletion' method, then the Aggregator does not finish his 
job (cause it probably doesn't know when to stop)
If I have no 'onCompletion' method, then the Aggregator does finish his job and 
the route does go on

My question is: Why I cannot use the onCompletion method on the Aggregator. 
Cause that Aggregator does the start work and should also do the end work of 
the aggregation. I have used the Aggregator in other scenarios (without the 
Splitter), and there it worked smoothly

Route where it does work, but I needed to call a bean after the end of the 
Splitter.
from("direct:anything")
   .to("direct:getSomething")
   .split(simple("${body}"), new EdiInterchangeAggregator()) // For each 
document
 .to("direct:prepareSomething")
 .to("direct:createSomethingMore")
   .end()
   .log("CamelSplitSize: ${exchangeProperty.CamelSplitSize} documents")
   .bean(EDIFinalizer.class, "finalizeInterchange");

So what I want is to implement the onCompletion method on the class 
EdiInterchangeAggregator.
Is this really not possible?

Regards
Reto


RE: Splitter and Aggregater onCompletion

2022-11-08 Thread Reto Peter
Hi Claus

Thanks, but the Aggregator has its interface AggregationStrategy and there is 
the 'onCompletion' method.
And this method is invoked in case of the following route:

from("direct:processAndAggregate")
.toD("xslt-saxon:mm/transform- -${header.doctype}-to-EDI-XML.xsl")
.aggregate(header("doctype"), new EDIMessageToInterchangeAggregatorMM())
.forceCompletionOnStop()
.to("sql:INSERT something");

So that means, in this route the onCompletion of the Aggregator is called cause 
the entire route is completed?

-Original Message-
From: Claus Ibsen  
Sent: Tuesday, 8 November 2022 09:50
To: users@camel.apache.org
Subject: Re: Splitter and Aggregater onCompletion

Hi

onCompletion is its own EIP
https://camel.apache.org/manual/oncompletion.html

The onCompletion works on the incoming exchange in the route, and the 
aggregator is separated from that incoming exchange, as the output of the 
aggregator runs its own "lifecycle", in its own exchange.
So it has no onCompletion.

The route above you show, is that when the split end() then you are continuing 
the incoming exchange which has onCompletion.

Its a bit difficult to explain, if you have the CiA2 book then take a look in 
the EIP chapter about the aggregator.



On Tue, Nov 8, 2022 at 9:43 AM Reto Peter  wrote:

> Hi all
>
> I am using a Splitter and an Aggregator.
> All of the output are written into the final result. But at the end of 
> the Split, I wanted to add something more.
> This is where the 'onCompletion' method inside the Aggregator can be 
> used (in my mind, cause that works for scenarios without a Splitter).
>
> But if have the 'onCompletion' method, then the Aggregator does not 
> finish his job (cause it probably doesn't know when to stop) If I have 
> no 'onCompletion' method, then the Aggregator does finish his job and 
> the route does go on
>
> My question is: Why I cannot use the onCompletion method on the 
> Aggregator. Cause that Aggregator does the start work and should also 
> do the end work of the aggregation. I have used the Aggregator in 
> other scenarios (without the Splitter), and there it worked smoothly
>
> Route where it does work, but I needed to call a bean after the end of 
> the Splitter.
> from("direct:anything")
>.to("direct:getSomething")
>.split(simple("${body}"), new EdiInterchangeAggregator()) // 
> For each document
>  .to("direct:prepareSomething")
>  .to("direct:createSomethingMore")
>.end()
>.log("CamelSplitSize: ${exchangeProperty.CamelSplitSize} documents")
>.bean(EDIFinalizer.class, "finalizeInterchange");
>
> So what I want is to implement the onCompletion method on the class 
> EdiInterchangeAggregator.
> Is this really not possible?
>
> Regards
> Reto
>


--
Claus Ibsen
-
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


RE: Splitter and Aggregater onCompletion

2022-11-08 Thread Reto Peter
Camel 3.18.3

Yes, I am talking about the onCompletion method of the AggregationStrategy.
So when I define the Splitter, I do define the AggregationStrategy class, and 
in this class it should be possible that the method onCompletion is called.
But where I can define the options to the AggregationStrategy, I mean the 
completionSize, completionInterval or completionTimeout?

-Original Message-
From: Claus Ibsen  
Sent: Tuesday, 8 November 2022 11:54
To: users@camel.apache.org
Subject: Re: Splitter and Aggregater onCompletion

What camel version do you use?

On Tue, Nov 8, 2022 at 11:53 AM Claus Ibsen  wrote:

> Hi
>
> Ah sorry there is both an onCompletion EIP you can use in routes.
> And then AggregationStrategy with overloaded/default methods for 
> various callbacks.
>
>
>
> On Tue, Nov 8, 2022 at 11:39 AM Reto Peter 
> wrote:
>
>> Hi Claus
>>
>> Thanks, but the Aggregator has its interface AggregationStrategy and 
>> there is the 'onCompletion' method.
>> And this method is invoked in case of the following route:
>>
>> from("direct:processAndAggregate")
>> .toD("xslt-saxon:mm/transform- -${header.doctype}-to-EDI-XML.xsl")
>> .aggregate(header("doctype"), new
>> EDIMessageToInterchangeAggregatorMM())
>> .forceCompletionOnStop()
>> .to("sql:INSERT something");
>>
>> So that means, in this route the onCompletion of the Aggregator is 
>> called cause the entire route is completed?
>>
>> -Original Message-
>> From: Claus Ibsen 
>> Sent: Tuesday, 8 November 2022 09:50
>> To: users@camel.apache.org
>> Subject: Re: Splitter and Aggregater onCompletion
>>
>> Hi
>>
>> onCompletion is its own EIP
>> https://camel.apache.org/manual/oncompletion.html
>>
>> The onCompletion works on the incoming exchange in the route, and the 
>> aggregator is separated from that incoming exchange, as the output of 
>> the aggregator runs its own "lifecycle", in its own exchange.
>> So it has no onCompletion.
>>
>> The route above you show, is that when the split end() then you are 
>> continuing the incoming exchange which has onCompletion.
>>
>> Its a bit difficult to explain, if you have the CiA2 book then take a 
>> look in the EIP chapter about the aggregator.
>>
>>
>>
>> On Tue, Nov 8, 2022 at 9:43 AM Reto Peter 
>> wrote:
>>
>> > Hi all
>> >
>> > I am using a Splitter and an Aggregator.
>> > All of the output are written into the final result. But at the end 
>> > of the Split, I wanted to add something more.
>> > This is where the 'onCompletion' method inside the Aggregator can 
>> > be used (in my mind, cause that works for scenarios without a Splitter).
>> >
>> > But if have the 'onCompletion' method, then the Aggregator does not 
>> > finish his job (cause it probably doesn't know when to stop) If I 
>> > have no 'onCompletion' method, then the Aggregator does finish his 
>> > job and the route does go on
>> >
>> > My question is: Why I cannot use the onCompletion method on the 
>> > Aggregator. Cause that Aggregator does the start work and should 
>> > also do the end work of the aggregation. I have used the Aggregator 
>> > in other scenarios (without the Splitter), and there it worked 
>> > smoothly
>> >
>> > Route where it does work, but I needed to call a bean after the end 
>> > of the Splitter.
>> > from("direct:anything")
>> >.to("direct:getSomething")
>> >.split(simple("${body}"), new EdiInterchangeAggregator()) // 
>> > For each document
>> >  .to("direct:prepareSomething")
>> >  .to("direct:createSomethingMore")
>> >.end()
>> >.log("CamelSplitSize: ${exchangeProperty.CamelSplitSize}
>> documents")
>> >.bean(EDIFinalizer.class, "finalizeInterchange");
>> >
>> > So what I want is to implement the onCompletion method on the class 
>> > EdiInterchangeAggregator.
>> > Is this really not possible?
>> >
>> > Regards
>> > Reto
>> >
>>
>>
>> --
>> Claus Ibsen
>> -
>> @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>
>
>
> --
> Claus Ibsen
> -
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


--
Claus Ibsen
-
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


Consume Files with specific dynamic content only

2023-02-21 Thread Reto Peter
Hi

I want to read all files inside a directory, but only process files with a 
specific file content.
The specific file content is dynamic. It is available inside the route as a 
Property, Header or Body
The reason is, cause I have any files inside a directory, (for ex. Orders, 
Invoices) and the file processing depends on its content

For example in my route:
.from("timer.")
.setHeader("SearchForFileContent", simple("${body}")) // Dynamic file content 
filter
.loopDoWhile(body().isNotNull()) // Read all files in a directory
.pollEnrich()
.simple("file:...filter=#FileContentFilter")
...


Is there any chance I can access the Exchange inside the filter 
(GenericFileFilter)?
Or how can I achieve to process only files with specific dynamic content

Camel 3.20.2
SpringBoot 2.7.8




PollEnrich with File from classpath

2023-03-01 Thread Reto Peter
Hi

I have a simple issue with the following route:

This works

.pollEnrich("file://src/main/resources/supplier/xxx/article?fileName=ExcelFooter.txt&noop=true&idempotent=false")
But I need to replace the classpath 'src/main/resources' folder, cause 
otherwise it doesn't work when its deployed.
How to PollEnrich a file from classpath?

Camel: 3.20.2
Spring Boot 2.7.8


How to clear the cache of MemoryIdempotentRepository

2023-04-19 Thread Reto Peter
Hi all

I have a route, which checks for uniqueness of a certain value (find 
duplicates, and in case of duplicates, the route will throw an exception).
That works fine so far.

At the end of the route, I want to clear the cache, so next time the route gets 
executed, it shall start with an empty cache.

My question: How can I clear the cache at the end of the route?

My route(simplified)


from("direct:processArticles")

  .split(xpath("//Article")) // for each Article

 .setHeader("ArtEAN", xpath("Article/ArtEAN/text()"))

 .idempotentConsumer(header("ArtEAN"), 
MemoryIdempotentRepository.memoryIdempotentRepository(2000)).skipDuplicate(false)

  
.choice().when(header(Exchange.DUPLICATE_MESSAGE).isEqualTo(true)).throwException(ImportException.class,
 "Line/Unit: ${exchangeProperty.CamelSplitIndex}: Found Duplicates").end()

 // do some processing

  .end()

Camel 3.20.3, Spring Boot 2.7.10


Route doesnt get started

2023-05-24 Thread Reto Peter
Hi

I have a strange situation with a Route, which is not getting started when it 
is called by another Route.
If the Route is not called by any other Route, it is getting started.

Example:

from("direct:checkClientSession")

.routeId("checkClientSession")

.to("log:myLogger?showAll=true")

.log("check session cookie and get the correct SupGID for which the client can 
send data")

.choice()

  .when(header("cookie").isNotNull())

 .to("sql:SELECT SupGID from client_session WHERE 
SessionCookie=:#${header.cookie} AND Sessionstart >= now(3) - INTERVAL 1 DAY 
AND IsActive=1?outputHeader=AuthorizedSupGID&outputType=SelectOne")

 .log("We found a cookie: ${header.cookie}, we will now check for 
which SupGID the client can send exchange data")

 .to("direct:checkCookie")

  .otherwise()

 .log("No cookie found in the request")

 .process(this::returnUnauthorizedCall)

 .stop()

.end();



If the above Route is standalone (no other routes inside the same configure 
method do call it) then the route will be started)



If another route does call it, then it wont get started,



For ex:

from("direct:restImportConfirmRequest")

  .routeId("restImportConfirmRequest")

  .log("REST: IMPORT CONFIRM called")

  .to("direct:checkClientSession")

;



Do you have any idea what could be the reason for that, or what I can do to 
find a solution?



Regards

Reto

Camel: 3.20.4, Spring Boot 2.7.11




Issue with ProducerTemplate (processor not started)

2023-08-11 Thread Reto Peter
Hi

I got an issue with the ProducerTemplate used inside a bean
The Bean class called Resolvement.class injects the ProducerTemplate as follows:


@EndpointInject

private ProducerTemplate producer;

inside the bean resolve() method, I do then use this producer like this:

producer.requestBodyAndHeader(...)

The method of the bean class is called by a camel route as follows:

.split(simple("${body}"), new CSVFileAggregator())

.parallelProcessing()

.bean(Resolvement.class, "resolve")

That normally works fine!
But in some cases, I get an error like this:
Caused by: java.lang.IllegalStateException: No producer, this processor has not 
been started: ProducerCache for source: toD20, capacity: 1000
  at 
org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProducer(DefaultProducerCache.java:300)
  at 
org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:182)
  at 
org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:477)
  at 
org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeFromQueue(DefaultReactiveExecutor.java:212)
  at 
org.apache.camel.impl.engine.DefaultReactiveExecutor.executeFromQueue(DefaultReactiveExecutor.java:77)
  at 
org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.await(DefaultAsyncProcessorAwaitManager.java:96)
  at 
org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:85)
  at 
org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:108)
  at 
org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProducerCache.java:199)
  at 
org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:176)
  at 
org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:172)
  at 
org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:158)
  at 
org.apache.camel.impl.engine.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:229)

That means for me, in some situations the Producer is not properly initialized.

My question is:
How can I make sure the producer is initialized properly?
Is this a synchronization issue cause I do use parallelProcessing and I must 
use some synchronizing strategies?
Or what could be the problem or the method to help for this issue?

Camel Version: 3.20.6
Java: 17
Sping Boot 2.7.12


RE: Issue with ProducerTemplate (processor not started)

2023-08-11 Thread Reto Peter
Hi Claus

Thanks for fast response.
The call is to an SQL query:
result = producer.requestBodyAndHeader("direct:executeQuery", "", "sqlquery", 
query);

and the route looks like this:
from("direct:executeQuery")
.routeId("Execute resolvement query")
.toD("sql:${header.sqlquery}")
;

-Original Message-
From: Claus Ibsen  
Sent: Friday, 11 August 2023 22:29
To: users@camel.apache.org
Subject: Re: Issue with ProducerTemplate (processor not started)

What endpoint do you send to with the producer template

On Fri, Aug 11, 2023 at 4:15 PM Reto Peter  wrote:

> Hi
>
> I got an issue with the ProducerTemplate used inside a bean The Bean 
> class called Resolvement.class injects the ProducerTemplate as
> follows:
>
>
> @EndpointInject
>
> private ProducerTemplate producer;
>
> inside the bean resolve() method, I do then use this producer like this:
>
> producer.requestBodyAndHeader(...)
>
> The method of the bean class is called by a camel route as follows:
>
> .split(simple("${body}"), new CSVFileAggregator())
>
> .parallelProcessing()
>
> .bean(Resolvement.class, "resolve")
>
> That normally works fine!
> But in some cases, I get an error like this:
> Caused by: java.lang.IllegalStateException: No producer, this 
> processor has not been started: ProducerCache for source: toD20, capacity: 
> 1000
>   at
> org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProducer(DefaultProducerCache.java:300)
>   at
> org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:182)
>   at
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:477)
>   at
> org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeFromQueue(DefaultReactiveExecutor.java:212)
>   at
> org.apache.camel.impl.engine.DefaultReactiveExecutor.executeFromQueue(DefaultReactiveExecutor.java:77)
>   at
> org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.await(DefaultAsyncProcessorAwaitManager.java:96)
>   at
> org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:85)
>   at
> org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:108)
>   at
> org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProducerCache.java:199)
>   at
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:176)
>   at
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:172)
>   at
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:158)
>   at
> org.apache.camel.impl.engine.DefaultProducerTemplate.sendBodyAndHeader
> (DefaultProducerTemplate.java:229)
>
> That means for me, in some situations the Producer is not properly 
> initialized.
>
> My question is:
> How can I make sure the producer is initialized properly?
> Is this a synchronization issue cause I do use parallelProcessing and 
> I must use some synchronizing strategies?
> Or what could be the problem or the method to help for this issue?
>
> Camel Version: 3.20.6
> Java: 17
> Sping Boot 2.7.12
>


--
Claus Ibsen
-
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


RE: Issue with ProducerTemplate (processor not started)

2023-08-11 Thread Reto Peter
Hi Claus

You mean I should just change my executeQuery route this way, from dynamic to 
static?

OLD
from("direct:executeQuery")
.toD("sql:${header.sqlquery}")

NEW
from("direct:executeQuery")
.setHeader("CamelSqlQuery", simple("${header.sqlquery}"
.to("sql:SELECT")

Correct?
But the bean class does still have the injected producerTemplate. The only 
change is the static call to the sql component

-Original Message-
From: Claus Ibsen  
Sent: Friday, 11 August 2023 22:54
To: users@camel.apache.org
Subject: Re: Issue with ProducerTemplate (processor not started)

Hi

Its much better to use a header with the dynamic query (key = 
SqlConstants.SQL_QUERY) 
https://camel.apache.org/components/3.21.x/sql-component.html#_message_headers

and use a static "to" endpoint then you dont have the overhead of creating a 
new endpoint/producer per SQL query combination.




On Fri, Aug 11, 2023 at 4:39 PM Reto Peter  wrote:

> Hi Claus
>
> Thanks for fast response.
> The call is to an SQL query:
> result = producer.requestBodyAndHeader("direct:executeQuery", "", 
> "sqlquery", query);
>
> and the route looks like this:
> from("direct:executeQuery")
> .routeId("Execute resolvement query")
> .toD("sql:${header.sqlquery}")
> ;
>
> -Original Message-
> From: Claus Ibsen 
> Sent: Friday, 11 August 2023 22:29
> To: users@camel.apache.org
> Subject: Re: Issue with ProducerTemplate (processor not started)
>
> What endpoint do you send to with the producer template
>
> On Fri, Aug 11, 2023 at 4:15 PM Reto Peter 
> wrote:
>
> > Hi
> >
> > I got an issue with the ProducerTemplate used inside a bean The Bean 
> > class called Resolvement.class injects the ProducerTemplate as
> > follows:
> >
> >
> > @EndpointInject
> >
> > private ProducerTemplate producer;
> >
> > inside the bean resolve() method, I do then use this producer like this:
> >
> > producer.requestBodyAndHeader(...)
> >
> > The method of the bean class is called by a camel route as follows:
> >
> > .split(simple("${body}"), new CSVFileAggregator())
> >
> > .parallelProcessing()
> >
> > .bean(Resolvement.class, "resolve")
> >
> > That normally works fine!
> > But in some cases, I get an error like this:
> > Caused by: java.lang.IllegalStateException: No producer, this 
> > processor has not been started: ProducerCache for source: toD20,
> capacity: 1000
> >   at
> >
> org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProducer(
> DefaultProducerCache.java:300)
> >   at
> >
> org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicPro
> cessor.java:182)
> >   at
> >
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleT
> ask.run(RedeliveryErrorHandler.java:477)
> >   at
> >
> org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeFro
> mQueue(DefaultReactiveExecutor.java:212)
> >   at
> >
> org.apache.camel.impl.engine.DefaultReactiveExecutor.executeFromQueue(
> DefaultReactiveExecutor.java:77)
> >   at
> >
> org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.await(D
> efaultAsyncProcessorAwaitManager.java:96)
> >   at
> >
> org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process
> (DefaultAsyncProcessorAwaitManager.java:85)
> >   at
> >
> org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(Shar
> edCamelInternalProcessor.java:108)
> >   at
> >
> org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProduc
> erCache.java:199)
> >   at
> >
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProdu
> cerTemplate.java:176)
> >   at
> >
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProdu
> cerTemplate.java:172)
> >   at
> >
> org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProdu
> cerTemplate.java:158)
> >   at
> > org.apache.camel.impl.engine.DefaultProducerTemplate.sendBodyAndHead
> > er
> > (DefaultProducerTemplate.java:229)
> >
> > That means for me, in some situations the Producer is not properly 
> > initialized.
> >
> > My question is:
> > How can I make sure the producer is initialized properly?
> > Is this a synchronization issue cause I do use parallelProcessing 
> > and I must use some synchronizing strategies?
> > Or what could be the problem or the method to help for this issue?
> >
> > Camel Version: 3.20.6
> > Java: 17
> > Sping Boot 2.7.12
> >
>
>
> --
> Claus Ibsen
> -
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


--
Claus Ibsen
-
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2


RE: Issue with ProducerTemplate (processor not started)

2023-08-11 Thread Reto Peter
Hi Claus

Oh, yes, that makes everything more easy!
Thank you so much for your super quick response and your great help!!!

By the way: I love Camel (not the cigarette). Thanks for that great product!

Reto

-Original Message-
From: Claus Ibsen  
Sent: Friday, 11 August 2023 23:13
To: users@camel.apache.org
Subject: Re: Issue with ProducerTemplate (processor not started)

On Fri, Aug 11, 2023 at 5:08 PM Reto Peter  wrote:

> Hi Claus
>
> You mean I should just change my executeQuery route this way, from 
> dynamic to static?
>
> OLD
> from("direct:executeQuery")
> .toD("sql:${header.sqlquery}")
>
> NEW
> from("direct:executeQuery")
> .setHeader("CamelSqlQuery", simple("${header.sqlquery}"
> .to("sql:SELECT")
>
> Correct?
> But the bean class does still have the injected producerTemplate. The 
> only change is the static call to the sql component
>
>
Yes correct and you can also just set the header from the template and avoid 
the .setHeader in the route

result = producer.requestBodyAndHeader("direct:executeQuery", "", 
"CamelSqlQuery", query);

And since you route is just from direct to sql, you can also call it directly 
from template, and not have that route

result = producer.requestBodyAndHeader("sql:SELECT", "", "CamelSqlQuery", 
query);


> -Original Message-
> From: Claus Ibsen 
> Sent: Friday, 11 August 2023 22:54
> To: users@camel.apache.org
> Subject: Re: Issue with ProducerTemplate (processor not started)
>
> Hi
>
> Its much better to use a header with the dynamic query (key =
> SqlConstants.SQL_QUERY)
> https://camel.apache.org/components/3.21.x/sql-component.html#_message
> _headers
>
> and use a static "to" endpoint then you dont have the overhead of 
> creating a new endpoint/producer per SQL query combination.
>
>
>
>
> On Fri, Aug 11, 2023 at 4:39 PM Reto Peter 
> wrote:
>
> > Hi Claus
> >
> > Thanks for fast response.
> > The call is to an SQL query:
> > result = producer.requestBodyAndHeader("direct:executeQuery", "", 
> > "sqlquery", query);
> >
> > and the route looks like this:
> > from("direct:executeQuery")
> > .routeId("Execute resolvement query")
> > .toD("sql:${header.sqlquery}")
> > ;
> >
> > -Original Message-
> > From: Claus Ibsen 
> > Sent: Friday, 11 August 2023 22:29
> > To: users@camel.apache.org
> > Subject: Re: Issue with ProducerTemplate (processor not started)
> >
> > What endpoint do you send to with the producer template
> >
> > On Fri, Aug 11, 2023 at 4:15 PM Reto Peter 
> > wrote:
> >
> > > Hi
> > >
> > > I got an issue with the ProducerTemplate used inside a bean The 
> > > Bean class called Resolvement.class injects the ProducerTemplate 
> > > as
> > > follows:
> > >
> > >
> > > @EndpointInject
> > >
> > > private ProducerTemplate producer;
> > >
> > > inside the bean resolve() method, I do then use this producer like
> this:
> > >
> > > producer.requestBodyAndHeader(...)
> > >
> > > The method of the bean class is called by a camel route as follows:
> > >
> > > .split(simple("${body}"), new CSVFileAggregator())
> > >
> > > .parallelProcessing()
> > >
> > > .bean(Resolvement.class, "resolve")
> > >
> > > That normally works fine!
> > > But in some cases, I get an error like this:
> > > Caused by: java.lang.IllegalStateException: No producer, this 
> > > processor has not been started: ProducerCache for source: toD20,
> > capacity: 1000
> > >   at
> > >
> > org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProduce
> > r(
> > DefaultProducerCache.java:300)
> > >   at
> > >
> > org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicP
> > ro
> > cessor.java:182)
> > >   at
> > >
> > org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$Simpl
> > eT
> > ask.run(RedeliveryErrorHandler.java:477)
> > >   at
> > >
> > org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.executeF
> > ro
> > mQueue(DefaultReactiveExecutor.java:212)
> > >   at
> > >
> > org.apache.camel.impl.engine.DefaultReactiveExecutor.executeFromQueu
> > e(
> >

Error with dynamic HTTPS call

2023-09-05 Thread Reto Peter
Hi

I have an error when initiating a dynamic HTTPS call as follows:


.toD("${header.URLString}")

The URLString in this case is:
https://apps.synesty.com/studio/api/flow/v1?id=J4M_SportXX_Verkaufsauftraege_abholen&t=Ubk15h-jeO50n-qQ31y9-a7ixv3&proxyHost=webproxy.dc.migros.ch&proxyPort=9099&httpMethod=GET

It results in the following error:
javax.net.ssl.SSLException: Unsupported or unrecognized SSL message

When I open this URL inside a browser, it works without any troubles.

Is this cause it is a dynamic call?

Camel 3.20.6
Java 17
Spring Boot 2.7.12


Single threaded route execution

2023-10-24 Thread Reto Peter
Hi

I got troubles, cause several threads are executing my route at the same time
Now I want to make sure the route can only be executed by max. 1 thread at a 
time.
But I couldn't find the definition how to do that.

In older versions there was a
.synchronized()

Or a

.executorService(Executors.newSingleThreadExecutor());

Can someone give me a hint on how to make it single threaded?

Camel 3.20.6
Spring Boot 2.7.12
Java 17

Thanks in advance
Reto