Hello Babak,
I have read your thread [2] and the problem of "renaming/moving/deleting" is
of mine.
I believe that it's posible control a ftp route with 3 elements:
I will use an example
//Exception control
onException(Exception.class).bean(myErrorControl).handled(true).to("mock:error");
// FTP Route.
from(ftp:server/path?....&processStrategy=#myProcessStrategy&PollStrategy=#myPollStrategy).bean(myProcess);
1) *On Exception*: With this route we can control all the exception during
the life of the Exchange. So, all exceptions don't control in the bean
myProcess. (by example one division by 0)
2)* PollStrategy*: With this class we can control the problem during the
poll. By example the server is shutdown.
3) *ProcessStrategy*: With this class we can control the problem like
""renaming/moving/deleting". But it isn't easy make this class (at least for
me) with a clear code. I am using the code of *FtpProcessStrategyFactory*
for my class. In my example only control "move" operation.
Below a show my example of MyProcessEstrategy. The method most important is
*prepareOnStartup*. The code in this method is necesary to actually the
files are moved.
I wouldn't need this class if I could change the LoggingExceptionHandler (I
don't know nothing about the log) Is it possible indicate to
LoggingExceptionHandler that use one class indicated for me to control the
Exception?
Perhaps, another option would be use your advice
"exchange.addOnCompletion(MyHandler)". I will try. But I like I am using all
component by default. The default code will be executed
" exchange.addOnCompletion(new GenericFileOnCompletion<T>(endpoint,
operations, target, absoluteFileName));" won't it? Then I will have 2
OnCompletion. One by default and another in myProcess
The ideal would be can indicate the ExceptionHandler in the uri like
processStrategy or pollStrategy.
My idea is control the route with these 3 elements, but I will prefer don't
use ProcessStrategy.
If I have understand well your thread [2], as you might have appreciated, my
english isn't the best , you will could use a similar scenary
I've recently worked with camel and I can be talking nonsense or
complicating the code more than necessary.
public class MyProcessEstrategia <FTPFile> extends
*GenericFileRenameProcessStrategy*<FTPFile> {
public EscipionProcessEstrategia() {
}
@Override
public boolean begin(GenericFileOperations<FTPFile> operations,
GenericFileEndpoint<FTPFile> endpoint, Exchange
exchange,
GenericFile<FTPFile> file) throws Exception {
// TODO Auto-generated method stub
boolean retorno= true;
System.out.println("****** BEGIN PROCESS ESTRATEGIA
***********");
try {
retorno =super.begin(operations, endpoint, exchange,
file);
}catch (Exception e){
System.out.println("Process Estrategia Begin:"+
e.getCause());
System.out.println("Process Estrategia Begin:"+
e.getMessage());
}
return retorno;
}
@Override
public void rollback(GenericFileOperations<FTPFile> operations,
GenericFileEndpoint<FTPFile> endpoint, Exchange
exchange,
GenericFile<FTPFile> file) throws Exception {
// TODO Auto-generated method stub
System.out.println("****** ROLLBACK PROCESS ESTRATEGIA
***********");
try {
super.rollback(operations, endpoint, exchange, file);
}catch (Exception e){
System.out.println("Process Estrategia RollBack:"+
e.getCause());
System.out.println("Process Estrategia RollBack:"+
e.getMessage());
System.out.println("Process Estrategia RollBack:"+
file.getAbsoluteFilePath()+file.getFileName());
}
}
@Override
public void commit(GenericFileOperations<FTPFile> operations,
GenericFileEndpoint<FTPFile> endpoint, Exchange
exchange,
GenericFile<FTPFile> file) throws Exception {
// TODO Auto-generated method stub
System.out.println("****** COMMIT PROCESS ESTRATEGIA
***********");
try {
super.commit(operations, endpoint, exchange, file);
}catch (Exception e){
System.out.println("Process Estrategia Commit:"+
e.getCause());
System.out.println("Process Estrategia Commit:"+
e.getMessage());
System.out.println("Process Estrategia Commit:"+
file.getAbsoluteFilePath()+file.getFileName());
}
}
@Override
public void prepareOnStartup(GenericFileOperations<FTPFile> operations,
GenericFileEndpoint<FTPFile> endpoint) throws Exception
{
// TODO Auto-generated method stub
try {
super.prepareOnStartup(operations, endpoint);
//Necesario para que se muevan ("renombren") los
ficheros.
Expression moveExpression= new
SimpleExpression("${file:parent}/.done/${file:onlyname}");
GenericFileExpressionRenamer<FTPFile> renamer = new
GenericFileExpressionRenamer<FTPFile>();
renamer.setExpression(moveExpression);
setCommitRenamer(renamer);
}catch (Exception e){
System.out.println("Process Estrategia prepareOnStartup
:"+
e.getCause());
System.out.println("Process Estrategia
prepareOnStartup:"+
e.getMessage());
}
}
}
Thank you.
--
View this message in context:
http://camel.465427.n5.nabble.com/ExceptionHandler-in-a-ftp-Route-tp5451466p5453941.html
Sent from the Camel - Users mailing list archive at Nabble.com.