/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.component.olingo2;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import org.apache.camel.Processor;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.olingo2.api.Olingo2ResponseHandler;
import org.apache.camel.component.olingo2.internal.Olingo2ApiName;
import org.apache.camel.support.component.AbstractApiConsumer;
import org.apache.camel.support.component.ApiConsumerHelper;

/**
 * The Olingo2 consumer.
 */
public class Olingo2Consumer extends AbstractApiConsumer<Olingo2ApiName, Olingo2Configuration> {

    public Olingo2Consumer(Olingo2Endpoint endpoint, Processor processor) {
        super(endpoint, processor);
    }

    @Override
    protected int poll() throws Exception {
        // invoke the consumer method
        final Map<String, Object> args = new HashMap<>();
        args.putAll(endpoint.getEndpointProperties());

        // let the endpoint and the Consumer intercept properties
        endpoint.interceptProperties(args);
        interceptProperties(args);

        try {
            // create responseHandler
            final CountDownLatch latch = new CountDownLatch(1);
            final Object[] result = new Object[1];
            final Exception[] error = new Exception[1];

            args.put(Olingo2Endpoint.RESPONSE_HANDLER_PROPERTY, new Olingo2ResponseHandler<Object>() {
                @Override
                public void onResponse(Object response, Map<String, String> responseHeaders) {
                    result[0] = response;
                    latch.countDown();
                }

                @Override
                public void onException(Exception ex) {
                    error[0] = ex;
                    latch.countDown();
                }

                @Override
                public void onCanceled() {
                    error[0] = new RuntimeCamelException("OData HTTP Request cancelled");
                    latch.countDown();
                }
            });

            doInvokeMethod(args);

            // guaranteed to return, since an exception on timeout is expected!!!
            latch.await();

            if (error[0] != null) {
                throw error[0];
            }

            return ApiConsumerHelper.getResultsProcessed(this, result[0], isSplitResult());

        } catch (Throwable t) {
            throw RuntimeCamelException.wrapRuntimeCamelException(t);
        }
    }

}

@@ -934,17 +934,16 @@
 nLatch;%0A
-%0A
 import o
@@ -1276,16 +1276,71 @@
 rHelper;
+%0Aimport org.apache.olingo.odata2.api.ep.feed.ODataFeed;
 %0A%0A/**%0A *
@@ -3135,22 +3135,305 @@
         
-return
+//%0A            // Allow consumer idle properties to properly handle an empty polling response%0A            //%0A            if (result%5B0%5D instanceof ODataFeed && (((ODataFeed) result%5B0%5D).getEntries().isEmpty())) %7B%0A                return 0;%0A            %7D else %7B%0A                int processed =
  ApiCons
@@ -3493,24 +3493,72 @@
 itResult());
+%0A                return processed;%0A            %7D
 %0A%0A        %7D 

Fix polling return for empty OData ODataFeeds (#2719) Closes #2732