0

I want to save the content from a localhost(json data) Example:

"id": 1,
    "prename": "Noel",
    "surname": "Reyes",
    "dateOfBirth": "1988-09-07",
    "birthPlace": "Bad Ems",
    "gender": "M"}

) in a txt.file (C:\inputFolder in Example.txt). Thats my code:

from("timer://foo?period=5s")
  .to("http4://localhost:8091/customers/")
  .log("Test3 ${body}")
   .to("file:C:/inputFolder/Example.txt")

;

But: My route1 started and is consuming from localhost but it does not save it in the textfile.

main] DefaultCamelContext            INFO  Apache Camel 2.22.2 (CamelContext: camel-1) is starting
[                          main] ManagedManagementStrategy      INFO  JMX is enabled
[                          main] DefaultTypeConverter           INFO  Type converters loaded (core: 195, classpath: 15)
[                          main] HttpComponent                  INFO  Created ClientConnectionManager org.apache.http.impl.conn.PoolingHttpClientConnectionManager@24c4ddae
[                          main] DefaultCamelContext            INFO  StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[                          main] DefaultCamelContext            INFO  Route: route1 started and consuming from: timer://foo?period=5s
[                          main] DefaultCamelContext            INFO  Total 1 routes, of which 1 are started
[                          main] DefaultCamelContext            INFO  Apache Camel 2.22.2 (CamelContext: camel-1) started in 2.945 seconds

Process finished with exit code 0

Can you help me?

1 Answers1

0

I think all fine with you code. Might be this will be reason for not data is coming in text file. After http operation, you are logging the body and once logged body content is gone.

from("timer://foo?period=5s")
  .to("http4://localhost:8091/customers/")
   .convertBodyTo(String.class)
    .log("Test3 ${body}")
     .to("file:C:/inputFolder/Example.txt")

I think by converting body to string convertBodyTo(String.class) before logging will resolve this issue.

Lucifer
  • 784
  • 2
  • 7
  • 20