Search in sources :

Example 1 with BookFlightRequest

use of org.switchyard.quickstarts.camel.sap.binding.jaxb.BookFlightRequest in project quickstarts by jboss-switchyard.

the class FlightCustomerInfoMessageComposer method decompose.

@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.
    SapSynchronousRfcDestinationEndpoint endpoint = target.getMessage().getExchange().getContext().getEndpoint("sap-srfc-destination:nplDest:BAPI_FLCUST_GETLIST", SapSynchronousRfcDestinationEndpoint.class);
    Structure request = endpoint.createRequest();
    // Add Customer Name to request if set
    if (bookFlightRequest.getCustomerName() != null && bookFlightRequest.getCustomerName().length() > 0) {
        request.put("CUSTOMER_NAME", bookFlightRequest.getCustomerName());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Added CUSTOMER_NAME = '{}' to request", bookFlightRequest.getCustomerName());
        }
    } else {
        throw new Exception("No Customer Name");
    }
    // Put request object into body of exchange message.
    response.getMessage().setBody(request);
    return response;
}
Also used : BookFlightRequest(org.switchyard.quickstarts.camel.sap.binding.jaxb.BookFlightRequest) SapSynchronousRfcDestinationEndpoint(org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint) Structure(org.fusesource.camel.component.sap.model.rfc.Structure) CamelBindingData(org.switchyard.component.camel.common.composer.CamelBindingData)

Example 2 with BookFlightRequest

use of org.switchyard.quickstarts.camel.sap.binding.jaxb.BookFlightRequest in project quickstarts by jboss-switchyard.

the class GetFlightConnectionListMessageComposer method decompose.

@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.
    SapSynchronousRfcDestinationEndpoint endpoint = response.getMessage().getExchange().getContext().getEndpoint("sap-srfc-destination:nplDest:BAPI_FLCONN_GETLIST", SapSynchronousRfcDestinationEndpoint.class);
    Structure request = endpoint.createRequest();
    // 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");
    }
    // Put request object into body of exchange message.
    response.getMessage().setBody(request);
    return response;
}
Also used : BookFlightRequest(org.switchyard.quickstarts.camel.sap.binding.jaxb.BookFlightRequest) SapSynchronousRfcDestinationEndpoint(org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint) Structure(org.fusesource.camel.component.sap.model.rfc.Structure) CamelBindingData(org.switchyard.component.camel.common.composer.CamelBindingData) Date(java.util.Date)

Aggregations

SapSynchronousRfcDestinationEndpoint (org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint)2 Structure (org.fusesource.camel.component.sap.model.rfc.Structure)2 CamelBindingData (org.switchyard.component.camel.common.composer.CamelBindingData)2 BookFlightRequest (org.switchyard.quickstarts.camel.sap.binding.jaxb.BookFlightRequest)2 Date (java.util.Date)1