@Override
public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception {
CamelBindingData response = super.decompose(exchange, target);
// Get BOOK_FLIGHT Request JAXB Bean object.
BookFlightRequest bookFlightRequest = exchange.getMessage().getContent(BookFlightRequest.class);
// Create SAP Request object from target endpoint.
SAPEndpoint endpoint = response.getMessage().getExchange().getContext().getEndpoint("sap:destination:nplDest:BAPI_FLCONN_GETLIST", SAPEndpoint.class);
Structure request = endpoint.getRequest();
// Add Travel Agency Number to request if set
if (bookFlightRequest.getTravelAgencyNumber() != null && bookFlightRequest.getTravelAgencyNumber().length() > 0) {
request.put("TRAVELAGENCY", bookFlightRequest.getTravelAgencyNumber());
if (LOG.isDebugEnabled()) {
LOG.debug("Added TRAVELAGENCY = '{}' to request", bookFlightRequest.getTravelAgencyNumber());
}
} else {
throw new Exception("No Travel Agency Number");
}
// Add Flight Date to request if set
if (bookFlightRequest.getFlightDate() != null) {
@SuppressWarnings("unchecked")
Table<Structure> table = request.get("DATE_RANGE", Table.class);
Structure date_range = table.add();
date_range.put("SIGN", "I");
date_range.put("OPTION", "EQ");
Date date = bookFlightRequest.getFlightDate();
date_range.put("LOW", date);
if (LOG.isDebugEnabled()) {
LOG.debug("Added DATE_RANGE = '{}' to request", RfcUtil.marshal(table));
}
} else {
throw new Exception("No Flight Date");
}
// Add Start Destination if set
if (bookFlightRequest.getStartAirportCode() != null && bookFlightRequest.getStartAirportCode().length() > 0) {
Structure destination_from = request.get("DESTINATION_FROM", Structure.class);
destination_from.put("AIRPORTID", bookFlightRequest.getStartAirportCode());
if (LOG.isDebugEnabled()) {
LOG.debug("Added DESTINATION_FROM = '{}' to request", RfcUtil.marshal(destination_from));
}
} else {
throw new Exception("No Start Destination");
}
// Add End Destination if set
if (bookFlightRequest.getEndAirportCode() != null && bookFlightRequest.getEndAirportCode().length() > 0) {
Structure destination_to = request.get("DESTINATION_TO", Structure.class);
destination_to.put("AIRPORTID", bookFlightRequest.getEndAirportCode());
if (LOG.isDebugEnabled()) {
LOG.debug("Added DESTINATION_TO = '{}' to request", RfcUtil.marshal(destination_to));
}
} else {
throw new Exception("No End Destination");