Search in sources :

Example 6 with UrlBuilder

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());
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) UrlBuilder(com.azure.android.core.http.util.UrlBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with UrlBuilder

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());
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) UrlBuilder(com.azure.android.core.http.util.UrlBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with UrlBuilder

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);
        }
    });
}
Also used : HashMap(java.util.HashMap) HttpResponse(com.azure.android.core.http.HttpResponse) NetworkCallRecord(com.azure.android.core.test.models.NetworkCallRecord) UrlBuilder(com.azure.android.core.http.util.UrlBuilder) NextPolicyCallback(com.azure.android.core.http.NextPolicyCallback) HashMap(java.util.HashMap) Map(java.util.Map) PolicyCompleter(com.azure.android.core.http.PolicyCompleter) NetworkCallError(com.azure.android.core.test.models.NetworkCallError)

Aggregations

UrlBuilder (com.azure.android.core.http.util.UrlBuilder)8 HttpRequest (com.azure.android.core.http.HttpRequest)4 JacksonSerder (com.azure.android.core.serde.jackson.JacksonSerder)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 HttpHeaders (com.azure.android.core.http.HttpHeaders)1 HttpResponse (com.azure.android.core.http.HttpResponse)1 NextPolicyCallback (com.azure.android.core.http.NextPolicyCallback)1 PolicyCompleter (com.azure.android.core.http.PolicyCompleter)1 NetworkCallError (com.azure.android.core.test.models.NetworkCallError)1 NetworkCallRecord (com.azure.android.core.test.models.NetworkCallRecord)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1