1212import com .azure .core .http .rest .Response ;
1313import com .azure .core .implementation .serializer .DefaultJsonSerializer ;
1414import com .azure .core .util .BinaryData ;
15+ import com .azure .core .util .Context ;
1516import com .azure .core .util .polling .implementation .PollingConstants ;
1617import com .azure .core .util .polling .implementation .PollingUtils ;
1718import com .azure .core .util .serializer .ObjectSerializer ;
@@ -37,6 +38,7 @@ public class OperationResourcePollingStrategy<T, U> implements PollingStrategy<T
3738 private final HttpPipeline httpPipeline ;
3839 private final ObjectSerializer serializer ;
3940 private final String operationLocationHeaderName ;
41+ private final Context context ;
4042
4143 /**
4244 * Creates an instance of the operation resource polling strategy using a JSON serializer and "Operation-Location"
@@ -45,24 +47,37 @@ public class OperationResourcePollingStrategy<T, U> implements PollingStrategy<T
4547 * @param httpPipeline an instance of {@link HttpPipeline} to send requests with
4648 */
4749 public OperationResourcePollingStrategy (HttpPipeline httpPipeline ) {
48- this (httpPipeline , new DefaultJsonSerializer (), DEFAULT_OPERATION_LOCATION_HEADER );
50+ this (httpPipeline , new DefaultJsonSerializer (), DEFAULT_OPERATION_LOCATION_HEADER , Context . NONE );
4951 }
5052
5153 /**
5254 * Creates an instance of the operation resource polling strategy.
53- *
5455 * @param httpPipeline an instance of {@link HttpPipeline} to send requests with
5556 * @param serializer a custom serializer for serializing and deserializing polling responses
5657 * @param operationLocationHeaderName a custom header for polling the long running operation
5758 */
5859 public OperationResourcePollingStrategy (HttpPipeline httpPipeline , ObjectSerializer serializer ,
5960 String operationLocationHeaderName ) {
61+ this (httpPipeline , serializer , operationLocationHeaderName , Context .NONE );
62+ }
63+
64+ /**
65+ * Creates an instance of the operation resource polling strategy.
66+ * @param httpPipeline an instance of {@link HttpPipeline} to send requests with
67+ * @param serializer a custom serializer for serializing and deserializing polling responses
68+ * @param operationLocationHeaderName a custom header for polling the long running operation
69+ * @param context an instance of {@link com.azure.core.util.Context}
70+ */
71+ public OperationResourcePollingStrategy (HttpPipeline httpPipeline , ObjectSerializer serializer ,
72+ String operationLocationHeaderName , Context context ) {
6073 this .httpPipeline = Objects .requireNonNull (httpPipeline , "'httpPipeline' cannot be null" );
6174 this .serializer = serializer != null ? serializer : new DefaultJsonSerializer ();
6275 this .operationLocationHeaderName = operationLocationHeaderName != null ? operationLocationHeaderName
6376 : DEFAULT_OPERATION_LOCATION_HEADER ;
77+ this .context = context ;
6478 }
6579
80+
6681 @ Override
6782 public Mono <Boolean > canPoll (Response <?> initialResponse ) {
6883 HttpHeader operationLocationHeader = initialResponse .getHeaders ().get (operationLocationHeaderName );
@@ -111,7 +126,7 @@ public Mono<PollResponse<T>> onInitialResponse(Response<?> response, PollingCont
111126 @ Override
112127 public Mono <PollResponse <T >> poll (PollingContext <T > pollingContext , TypeReference <T > pollResponseType ) {
113128 HttpRequest request = new HttpRequest (HttpMethod .GET , pollingContext .getData (operationLocationHeaderName ));
114- return httpPipeline .send (request ).flatMap (response -> response .getBodyAsByteArray ()
129+ return httpPipeline .send (request , this . context ).flatMap (response -> response .getBodyAsByteArray ()
115130 .map (BinaryData ::fromBytes )
116131 .flatMap (binaryData -> PollingUtils .deserializeResponse (
117132 binaryData , serializer , new TypeReference <PollResult >() { })
@@ -157,7 +172,7 @@ public Mono<U> getResult(PollingContext<T> pollingContext, TypeReference<U> resu
157172 return PollingUtils .deserializeResponse (BinaryData .fromString (latestResponseBody ), serializer , resultType );
158173 } else {
159174 HttpRequest request = new HttpRequest (HttpMethod .GET , finalGetUrl );
160- return httpPipeline .send (request )
175+ return httpPipeline .send (request , this . context )
161176 .flatMap (HttpResponse ::getBodyAsByteArray )
162177 .map (BinaryData ::fromBytes )
163178 .flatMap (binaryData -> PollingUtils .deserializeResponse (binaryData , serializer , resultType ));
0 commit comments