use of com.azure.android.core.http.util.UrlBuilder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method querySubstitution.
@ParameterizedTest
@MethodSource("querySubstitutionSupplier")
public void querySubstitution(Method method, Object[] arguments, String expectedUrl) {
HttpRequestMapper mapper = new HttpRequestMapper("https://raw.host.com", method, new JacksonSerder());
UrlBuilder urlBuilder = UrlBuilder.parse("https://raw.host.com");
mapper.applyQueryMappings(arguments, urlBuilder);
assertEquals(expectedUrl, urlBuilder.toString());
}
use of com.azure.android.core.http.util.UrlBuilder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method schemeSubstitution.
@ParameterizedTest
@MethodSource("schemeSubstitutionSupplier")
public void schemeSubstitution(Method method, String rawHost, Object[] arguments, String expectedUrl) {
HttpRequestMapper mapper = new HttpRequestMapper(rawHost, method, new JacksonSerder());
UrlBuilder urlBuilder = new UrlBuilder();
mapper.applySchemeAndHostMapping(arguments, urlBuilder);
assertEquals(expectedUrl, urlBuilder.toString());
}
use of com.azure.android.core.http.util.UrlBuilder in project azure-sdk-for-android by Azure.
the class RecordNetworkCallPolicy method process.
@Override
public void process(HttpPipelinePolicyChain chain) {
final NetworkCallRecord networkCallRecord = new NetworkCallRecord();
Map<String, String> headers = new HashMap<>();
captureRequestHeaders(chain.getRequest().getHeaders(), headers, X_MS_CLIENT_REQUEST_ID, CONTENT_TYPE, X_MS_VERSION, USER_AGENT);
networkCallRecord.setHeaders(headers);
networkCallRecord.setMethod(chain.getRequest().getHttpMethod().toString());
// Remove sensitive information such as SAS token signatures from the recording.
UrlBuilder urlBuilder = UrlBuilder.parse(chain.getRequest().getUrl());
redactedAccountName(urlBuilder);
if (urlBuilder.getQuery().containsKey(SIG)) {
urlBuilder.setQueryParameter(SIG, "REDACTED");
}
networkCallRecord.setUri(urlBuilder.toString().replaceAll("\\?$", ""));
chain.processNextPolicy(chain.getRequest(), new NextPolicyCallback() {
@Override
public PolicyCompleter.CompletionState onSuccess(HttpResponse response, PolicyCompleter completer) {
final HttpResponse bufferedResponse = response.buffer();
Map<String, String> responseData = extractResponseData(bufferedResponse);
networkCallRecord.setResponse(responseData);
String body = responseData.get(BODY);
// Remove pre-added header if this is a waiting or redirection
if (body != null && body.contains("<Status>InProgress</Status>") || Integer.parseInt(responseData.get(STATUS_CODE)) == HttpURLConnection.HTTP_MOVED_TEMP) {
logger.info("Waiting for a response or redirection.");
} else {
recordedData.addNetworkCall(networkCallRecord);
}
return completer.completed(bufferedResponse);
}
@Override
public PolicyCompleter.CompletionState onError(Throwable error, PolicyCompleter completer) {
networkCallRecord.setException(new NetworkCallError(error));
recordedData.addNetworkCall(networkCallRecord);
return completer.completedError(error);
}
});
}
Aggregations