java - Camel: keep a file to folder depended on response -
i have dsl this:
from("file:data/inbox?noop=true") .marshal() .string("utf-8") .setheader(exchange.content_type,constant("application/json")) .to("http://www.a-service.com") .choice() .when(new predicate() { @override public boolean matches(exchange exchange) { message in = exchange.getin(); string msg = in.getbody(string.class); system.out.println(" response: " + msg); if(msg.contains("\"status\":\"ok\"")){ return true; }else{ return false; } } }) // ok!!! .to("file:data/outbox_success") .otherwise() // not ok !!! .to("file:data/outbox_fail");
i expected if http response has "status":"ok", files go "data/outbox_success". otherwise, go "data/outbox_fail".
but not expected: yes, files has been copied "outbox_xxx" but there no content in files.
i guess because "in" message has been changed http response.
so, how can copy file folder depended on response of 'http' ?
try storing body in header later use:
from("file:data/inbox?noop=true") .marshal() .string("utf-8") .setheader(exchange.content_type,constant("application/json")) .setheader("filebody", simple(${body})) .to("http://www.a-service.0com") .setheader("webresponse", simple(${body})) //store response http call .setbody(simple(${header.filebody})) //reset body original file body .choice() .when(new predicate() { @override public boolean matches(exchange exchange) { message in = exchange.getin(); string msg = in.getheader("webresponse"); system.out.println(" response: " + msg); if(msg.contains("\"status\":\"ok\"")){ return true; }else{ return false; } } }) // ok!!! .to("file:data/outbox_success") .otherwise() // not ok !!! .to("file:data/outbox_fail");
Comments
Post a Comment