use of org.apache.camel.component.quickfixj.examples.transform.QuickfixjMessageJsonTransformer in project camel by apache.
the class RequestReplyExample method run.
public void run() throws Exception {
final CamelContext context = new DefaultCamelContext();
final CountDownLatch logonLatch = new CountDownLatch(1);
final String orderStatusServiceUrl = "http://localhost:9123/order/status";
RouteBuilder routes = new RouteBuilder() {
@Override
public void configure() throws Exception {
// Synchronize the logon so we don't start sending status requests too early
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).bean(new CountDownLatchDecrementer("logon", logonLatch));
// Incoming status requests are passed to the order status service and afterwards we print out that
// order status being delivered using the json printer.
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER&exchangePattern=InOut").filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.ORDER_STATUS_REQUEST)).to("log://OrderStatusRequestLog?showAll=true&showOut=true&multiline=true").bean(new MarketOrderStatusService()).bean(new QuickfixjMessageJsonPrinter());
from("jetty:" + orderStatusServiceUrl).bean(new OrderStatusRequestTransformer()).routingSlip(method(FixSessionRouter.class, "route")).bean(new QuickfixjMessageJsonTransformer(), "transform(${body})");
}
};
context.addRoutes(routes);
LOG.info("Starting Camel context");
context.start();
if (!logonLatch.await(5L, TimeUnit.SECONDS)) {
throw new IllegalStateException("Logon did not succeed");
}
// Send a request to the order status web service.
// Verify that the response is a JSON response.
URL orderStatusUrl = new URL(orderStatusServiceUrl + "?sessionID=FIX.4.2:TRADER->MARKET&orderID=abc");
URLConnection connection = orderStatusUrl.openConnection();
BufferedReader orderStatusReply = IOHelper.buffered(new InputStreamReader(connection.getInputStream()));
String line = orderStatusReply.readLine();
if (!line.equals("\"message\": {")) {
throw new Exception("Don't appear to be a JSON response");
} else {
StringBuilder sb = new StringBuilder();
while (line != null) {
sb.append(line);
sb.append('\n');
line = orderStatusReply.readLine();
}
LOG.info("Web reply:\n" + sb);
}
orderStatusReply.close();
LOG.info("Shutting down Camel context");
context.stop();
LOG.info("Example complete");
}
Aggregations