Notas
Apache Camel - Copiado archivos
Conteúdo das notas (1)
Página 1
package org.apache.camel.example.jmstofile;
import org.apache.camel.CamelContext;import org.apache.camel.builder.RouteBuilder;import org.apache.camel.impl.DefaultCamelContext;
public class CamelHelloWorldExample { public static void main(String[] args) throws Exception { CamelContext context = new DefaultCamelContext(); try {// context.addComponent("activemq", ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false")); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { // Copiado sin borrar from("file:C:\\datafiles\\input?noop=true").to("file:C:\\datafiles\\output");
// Movido
from("file:C:\\datafiles\\input?delete=true").to("file:C:\\datafiles\\output");
// Files Copied from datafiles\input to datafiles\output and Original Files Moved to .camel Subdirectory
from("file:C:\\datafiles\\input?").to("file:C:\\datafiles\\output");
// Desde la ruta de Eclipse (Hay que añadirlos al Build Path como Folder Work)
from("file:src/data/inbox?noop=true").to("file:src/data/outbox");
// Copiar una archivo solo
from("file://C:/datafiles/input/?fileName=MyFile.txt&charset=utf-8&noop=true").to("file://C:/datafiles/output/?fileName=MyFile.txt&charset=utf-8");
// fileExist=Ignore : Si existe no los sobreescribe
from("file://C:/datafiles/input/?fileName=message1.xml&charset=utf-8&noop=true&fileExist=Ignore") .to("file://C:/datafiles/output/?");
// from("timer://myTimer?period=2000")// .setBody()// .simple("Hello World Camel fired at ${header.firedTime}")// .to("stream:out"); } }); // ProducerTemplate template = context.createProducerTemplate(); context.start(); // template.sendBody("activemq:test.queue", "Hello World"); Thread.sleep(2000); context.stop(); } finally { context.stop(); } }}
/ ** */
file:// + + ? + fileName= + + & +
For example, if the filename is C:\in\MyFile.txt, then the URI would look like one of these (both are valid):
file://C:/in/?fileName=MyFile.txt file://C:\\in\\?fileName=MyFile.txt
// Copia FTP
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.example.ftp;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.properties.PropertiesComponent;
/**
* Client route
*/
public class MyFtpClientRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
// configure properties component
PropertiesComponent pc = getContext().getComponent("properties", PropertiesComponent.class);
pc.setLocation("classpath:ftp.properties");
// lets shutdown faster in case of in-flight messages stack up
getContext().getShutdownStrategy().setTimeout(10);
// Copia todos los xml's desde el origen al destino
from("ftp://mingo@localhost:21?password=mingo")
.choice()
.when(simple("${in.header.CamelFileName} contains '.xml'"))
.to("file://C:\\Borrar\\TestFTP");
// use system out so it stand out
System.out.println("*********************************************************************************");
System.out.println("Camel will route files from target/upload directory to the FTP server: "
+ getContext().resolvePropertyPlaceholders("{{ftp.server}}"));
System.out.println("You can configure the location of the ftp server in the src/main/resources/ftp.properties file.");
System.out.println("If the file upload fails, then the file is moved to the target/error directory.");
System.out.println("Use ctrl + c to stop this application.");
System.out.println("*********************************************************************************");
}
}
Informações
- Descrição
- Copiado / Mover archivos
- Criado por
- Jose Antonio Vazquez
- Visualizações
- 147
- Tags
- Avaliação