camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From somemightsay <euanbeg...@hotmail.com>
Subject CSV Reporting with Java and XML
Date Thu, 19 Aug 2010 19:50:10 GMT

Camel 2.4 
Spring 3.0.3 

I apologise in advance if this is asking to much but I've been looking for
help with this for a long time and still cannot find an answer. 

I have a program which pulls data from a database and reports it to a CSV
file. Simple enough. 

I have the database info defined in a Camel-Context.xml file and a java
class holds the routes code. The sql query and database login info are in
external properties files. 

The program was inicially from a camel example and was fully in the XML
file, including the sql query etc. That originally ran with the 'Main' class
in org.apache.camel.spring and after all these changes it still runs
correctly as the run configuration with that class. 

But when I'm putting it into a JAR it does not, and complains about not
being able to find the class in the manifest. If I run this java class as
the run config it only outputs the sql query and the logging (which i have
removed, to save space below) and does not interact with the XML file at
all. I think the best way to fix this would be to make the java class pull
the defined data it needs from the XML file but I do not know how to do
this. 

It's rather annoying that it works so perfectly using the Main class in
eclipse but not in a jar. 

Thanks. 

JAVA CLASS 

package com.test.vprtacticalreports.routes; 

import java.io.FileInputStream; 
import java.util.Properties; 
import org.apache.log4j.Logger; 
import org.apache.camel.builder.RouteBuilder; 
import org.apache.camel.dataformat.csv.CsvDataFormat; 

public class Camelroutes extends RouteBuilder { 

        public void configure() throws Exception { 
                String query; 
                Properties props = new Properties(); 

                try { 
                        props.load(new
FileInputStream("../vpr-tactical-report/src/main/resources/testquery.properties")); 
                        query = props.getProperty("query"); 
                        
                       
from("reportInputDir").startupOrder(1).to("reportOutputDir"); 
                                
                        CsvDataFormat csv = new CsvDataFormat(); 

                        from("cronSchedule") 
                        .startupOrder(2) 
                        .setBody(constant(query)) 
                        .to("jdbc:vprsitdb") 
                        .marshal(csv) 
                        .to("reportTargetDir"); 
                        System.out.println(query); 
                } 
                catch (Exception e) { 
                } 

        } 
        public static void main(String[] args){ 
                try { 
                        new Camelroutes().configure(); 
                } catch (Exception e) { 
                        e.printStackTrace(); 
                } 
        } 

} 


XML FILE 


<?xml version="1.0" encoding="UTF-8"?> 
        <beans xmlns="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd"> 

        <bean 
               
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
                <property name="ignoreUnresolvablePlaceholders" value="true"
/> 
                <property name="locations"> 
                        <list> 
                               
<value>classpath:application.properties</value> 
                               
<value>classpath:database-sit.properties</value> 
                        </list> 
                </property> 
        </bean> 
        
        
        <camelContext id="camel" trace="true" 
                xmlns="http://camel.apache.org/schema/spring"> 
                
                <packageScan> 
      <package>com.test.vprtacticalreports.routes</package> 
      </packageScan> 
                
                
                <endpoint id="reportInputDir"
uri="file://csv/input/?noop=true" /> 
                <endpoint id="reportOutputDir" uri="file://csv/output" /> 
                <endpoint id="reportArchiveDir" 
                       
uri="file://csv/archive/?fileName=${date:now:yyyyMMdd_kkmmss}_${reportName}"
/> 
                <endpoint id="cronSchedule"
uri="quartz://report?cron=${cronSchedule}" /> 
                <endpoint id="reportTargetDir" 
                       
uri="file://csv/output/?fileExist=Append&fileName=${reportName}"/> 
        
    </camelContext> 
        
        <bean id="vprsitdb" 
               
class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
                <property name="driverClassName" value="${driverClassName}"
/> 
                <property name="url" value="${url}" /> 
                <property name="username" value="${username}" /> 
                <property name="password" value="${password}" /> 
        </bean> 

        <bean id="vprdevdb" 
               
class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
                <property name="driverClassName" value="${driverClassName}"
/> 
                <property name="url" value="${url}" /> 
                <property name="username" value="${username}" /> 
                <property name="password" value="${password}" /> 
        </bean> 
        
</beans>
-- 
View this message in context: http://camel.465427.n5.nabble.com/CSV-Reporting-with-Java-and-XML-tp2641453p2641453.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message