You have to start your route before you send a message via the producer
template.

Sent from a mobile device
Am 30.03.2013 08:41 schrieb "takidean" <takide...@hotmail.fr>:

> when i  use to select some rows from a database i get one error and this is
> my code:
>
>         public static void main(String[] args) throws Exception {
>
>                 // TODO Auto-generated method stub
>                 //DataSource dd;
>                  DriverManagerDataSource db = new
> DriverManagerDataSource();
>
>               db.setDriverClassName("com.mysql.jdbc.Driver");
>             db.setUrl("jdbc:mysql://localhost:3306/examen");
>             db.setUsername("root");
>             db.setPassword("");
>             SimpleRegistry re= new SimpleRegistry();
>         re.put("ds",db);
>             // JdbcComponent jd = new JdbcComponent();
> //jd.setDataSource(ds);
> //jd.createEndpoint("jdbc:mysql://localhost:3306/examen");
>         ConnectionFactory connectionFactory =new
> ActiveMQConnectionFactory("vm://localhost");
> CamelContext context = new DefaultCamelContext(re);
>
> context.addComponent("jms",JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
>
>  final Endpoint endpoint = context.getEndpoint("direct:hello");
>  Exchange exchange = endpoint.createExchange();
>  exchange.getIn().setBody("SELECT * FROM `examen`.`user` WHERE
> `user`.`name`
> = 'tt'");
>  ProducerTemplate template = context.createProducerTemplate();
>  Exchange out = template.send(endpoint, exchange);
> context.addRoutes(new RouteBuilder() {
>
>         @Override
>         public void configure() throws Exception {
>                 from("direct:hello")
>         .to("jdbc:ds");
>         }
> });
>
>
>
>
> ArrayList<HashMap&lt;String, Object>> data =
> out.getIn().getBody(ArrayList.class);
> /*assertNotNull("out body could not be converted to an ArrayList - was: "
> + out.getOut().getBody(), data);*/
> HashMap<String, Object> row = data.get(0);
> //assertEquals(2, data.size());
>               //HashMap<String, Object> row = data.get(0);
> System.out.println("le nom est "+row.get("lastname"));
> //assertEquals("cust1", row.get("ID"));
> //assertEquals("jstrachan", row.get("NAME"));
> //row = data.get(1);
> //assertEquals("cust2", row.get("ID"));
> //assertEquals("nsandhu", row.get("NAME"));
> context.start();
>
> Thread.sleep(10000);
> context.stop();
>
>
>         }
>
> }
>
>
>
> /*************************************errors***************/
> [                          main] DriverManagerDataSource        INFO
>  Loaded
> JDBC driver: com.mysql.jdbc.Driver
> [                          main] DefaultTypeConverter           INFO
>  Loaded
> 172 type converters
> [                          main] ManagementStrategyFactory      INFO  JMX
> enabled.
> [                          main] DirectProducer                 WARN  No
> consumers available on endpoint: Endpoint[direct://hello] to process:
> Exchange[Message: SELECT * FROM `examen`.`user` WHERE `user`.`name` = 'tt']
> Exception in thread "main" java.lang.NullPointerException
>         at taki.fin.Cntx.main(Cntx.java:101)
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/endpoint-without-consumer-tp5730093.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply via email to