Repository: olingo-odata4 Updated Branches: refs/heads/master 149c51c7a -> 96b8cd96a
[OLINGO-248] provided callback support for V4 async requests Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/96b8cd96 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/96b8cd96 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/96b8cd96 Branch: refs/heads/master Commit: 96b8cd96aebc6e18e8846d25e6244303ee2bbda3 Parents: 149c51c Author: fmartelli <[email protected]> Authored: Thu Apr 24 17:49:05 2014 +0200 Committer: fmartelli <[email protected]> Committed: Thu Apr 24 17:49:05 2014 +0200 ---------------------------------------------------------------------- .../request/v4/AsyncRequestWrapper.java | 15 +++++++++++++++ .../request/v4/AsyncRequestWrapperImpl.java | 7 +++++++ .../olingo/client/core/it/v4/AsyncTestITCase.java | 2 ++ 3 files changed, 24 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96b8cd96/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestWrapper.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestWrapper.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestWrapper.java index 7c57b69..4645ff7 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestWrapper.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/v4/AsyncRequestWrapper.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.client.api.communication.request.v4; +import java.net.URI; import org.apache.olingo.client.api.communication.response.ODataResponse; import org.apache.olingo.client.api.communication.response.v4.AsyncResponseWrapper; @@ -32,6 +33,20 @@ public interface AsyncRequestWrapper<R extends ODataResponse> { AsyncRequestWrapper<R> wait(int waitInSeconds); /** + * The odata.callback preference MUST include the parameter url whose value is the URL of a callback endpoint to be + * invoked by the OData service when data is available. The syntax of the odata.callback preference is specified in + * [OData-ABNF]. + * <br /> + * For HTTP based callbacks, the OData service executes an HTTP GET request against the specified URL. + * <br/> + * Services that support odata.callback SHOULD support notifying the client through HTTP. + * + * @param url callback URL + * @return the current AsyncRequestWrapper instance. + */ + AsyncRequestWrapper<R> callback(final URI url); + + /** * execute the request for the first time. * * @return http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96b8cd96/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java index 1460ff5..c9fb23d 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java @@ -109,6 +109,13 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe return this; } + @Override + public AsyncRequestWrapper<R> callback(URI url) { + extendHeader(HeaderName.prefer.toString(), + new ODataPreferences(ODataServiceVersion.V40).callback(url.toASCIIString())); + return this; + } + private void extendHeader(final String headerName, final String headerValue) { final StringBuilder extended = new StringBuilder(); if (this.odataRequest.getHeaderNames().contains(headerName)) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96b8cd96/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java index a6f52a3..815d077 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java @@ -18,6 +18,7 @@ */ package org.apache.olingo.client.core.it.v4; +import java.net.URI; import java.util.List; import java.util.concurrent.ExecutionException; @@ -129,6 +130,7 @@ public class AsyncTestITCase extends AbstractTestITCase { final AsyncRequestWrapper<ODataRetrieveResponse<ODataEntitySet>> async = client.getAsyncRequestFactory().<ODataRetrieveResponse<ODataEntitySet>>getAsyncRequestWrapper(req); + async.callback(URI.create("http://client.service.it/callback/endpoint")); final AsyncResponseWrapper<ODataRetrieveResponse<ODataEntitySet>> responseWrapper = async.execute();
