Package org.switchyard.component.camel.common.composer

Examples of org.switchyard.component.camel.common.composer.CamelBindingData


public class GetFlightConnectionDetailMessageComposer extends CamelMessageComposer {
    private static final Logger LOG = LoggerFactory.getLogger(GetFlightConnectionDetailMessageComposer.class);
   
    @Override
    public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception {
        CamelBindingData response = super.decompose(exchange, target);

        // Get BAPI_FLCONN_GETLIST SAP Response object.
        Structure flightConnectionGetListResponse = exchange.getMessage().getContent(Structure.class);

        if (flightConnectionGetListResponse == null) {
            throw new Exception("No Flight Connection Get List Response.");
        }

        // Get the list of matching flight connections in response object.
        @SuppressWarnings("unchecked")
        Table<? extends Structure> connectionList = flightConnectionGetListResponse.get("FLIGHT_CONNECTION_LIST", Table.class);
        if (connectionList == null || connectionList.size() == 0) {
            throw new Exception("No Flight Connections");
        }

        // Select the first connection.
        Structure connection = connectionList.get(0);

        // Create SAP Request object from target endpoint.
        SAPEndpoint endpoint = response.getMessage().getExchange().getContext().getEndpoint("sap:destination:nplDest:BAPI_FLCONN_GETDETAIL", SAPEndpoint.class);
        Structure request = endpoint.getRequest();

        // Copy connection number of matching connection into request.
        String connectionNumber = connection.get("FLIGHTCONN", String.class);
        if (connectionNumber != null) {
            request.put("CONNECTIONNUMBER", connectionNumber);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Added CONNECTIONNUMBER = '{}' to request", connectionNumber);
            }
        } else {
            throw new Exception("No Flight Connection Number");
        }

        // Copy agency number of matching connection into request.
        String travelAgencyNumber = connection.get("AGENCYNUM", String.class);
        if (travelAgencyNumber != null) {
            request.put("TRAVELAGENCYNUMBER", travelAgencyNumber);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Added TRAVELAGENCYNUMBER = '{}' to request", travelAgencyNumber);
            }
        } else {
            throw new Exception("No Agency Number");
        }

        // Copy flight date of matching connection into request.
        Date flightDate = connection.get("FLIGHTDATE", Date.class);
        if (flightDate != null) {
            request.put("FLIGHTDATE", flightDate);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Added FLIGHTDATE = '{}' to request", flightDate);
            }
        } else {
            throw new Exception("No Flight Date");
        }

        // Include availability data in RFC response.
        request.put("NO_AVAILIBILITY", "");

        // Put request object into body of exchange message.
        response.getMessage().setBody(request);
        return response;
    }
View Full Code Here

TOP

Related Classes of org.switchyard.component.camel.common.composer.CamelBindingData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.