use of com.azure.core.http.HttpRequest in project ApplicationInsights-Java by microsoft.
the class TelemetryChannel method internalSend.
/**
* Object can be a list of {@link ByteBuffer} or a raw byte array. Regular telemetries will be
* sent as {@code List<ByteBuffer>}. Persisted telemetries will be sent as byte[]
*/
private CompletableResultCode internalSend(List<ByteBuffer> byteBuffers, String instrumentationKey, Runnable onSuccess, Consumer<Boolean> onFailure, OperationLogger operationLogger) {
HttpRequest request = new HttpRequest(HttpMethod.POST, endpointUrl);
request.setBody(Flux.fromIterable(byteBuffers));
int contentLength = byteBuffers.stream().mapToInt(ByteBuffer::limit).sum();
request.setHeader("Content-Length", Integer.toString(contentLength));
// need to suppress the default User-Agent "ReactorNetty/dev", otherwise Breeze ingestion
// service will put that
// User-Agent header into the client_Browser field for all telemetry that doesn't explicitly set
// it's own
// UserAgent (ideally Breeze would only have this behavior for ingestion directly from browsers)
// TODO(trask)
// not setting User-Agent header at all would be a better option, but haven't figured out how
// to do that yet
request.setHeader("User-Agent", "");
request.setHeader("Content-Encoding", "gzip");
// TODO(trask) subscribe with listener
// * retry on first failure (may not need to worry about this if retry policy in pipeline
// already, see above)
// * write to disk on second failure
CompletableResultCode result = new CompletableResultCode();
final long startTime = System.currentTimeMillis();
// Add instrumentation key to context to use in redirectPolicy
Map<Object, Object> contextKeyValues = new HashMap<>();
contextKeyValues.put(RedirectPolicy.INSTRUMENTATION_KEY, instrumentationKey);
contextKeyValues.put(Tracer.DISABLE_TRACING_KEY, true);
pipeline.send(request, Context.of(contextKeyValues)).subscribe(responseHandler(instrumentationKey, startTime, () -> {
onSuccess.run();
result.succeed();
}, retryable -> {
onFailure.accept(retryable);
result.fail();
}, operationLogger), errorHandler(instrumentationKey, retryable -> {
onFailure.accept(retryable);
result.fail();
}, operationLogger));
return result;
}
use of com.azure.core.http.HttpRequest in project lowkey-vault by nagyesta.
the class ApacheHttpResponseTest method testConstructorShouldMapFieldsWhenCalled.
@Test
void testConstructorShouldMapFieldsWhenCalled() throws IOException {
// given
final HttpRequest request = mock(HttpRequest.class);
final HttpResponse response = responseMock();
// when
final ApacheHttpResponse actual = new ApacheHttpResponse(request, response);
// then
verifyResponse(actual);
}
use of com.azure.core.http.HttpRequest in project lowkey-vault by nagyesta.
the class LowkeyVaultManagementClientImpl method delete.
@Override
public boolean delete(@NonNull final URI baseUri) {
final URI uri = UriUtil.uriBuilderForPath(vaultUrl, MANAGEMENT_VAULT_PATH, Map.of(BASE_URI_QUERY_PARAM, baseUri.toString()));
final HttpRequest request = new HttpRequest(HttpMethod.DELETE, uri.toString()).setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
return sendAndProcess(request, r -> r.getResponseObject(Boolean.class));
}
use of com.azure.core.http.HttpRequest in project lowkey-vault by nagyesta.
the class LowkeyVaultManagementClientImpl method purge.
@Override
public boolean purge(@NonNull final URI baseUri) {
final Map<String, String> parameters = Map.of(BASE_URI_QUERY_PARAM, baseUri.toString());
final URI uri = UriUtil.uriBuilderForPath(vaultUrl, MANAGEMENT_VAULT_PURGE_PATH, parameters);
final HttpRequest request = new HttpRequest(HttpMethod.DELETE, uri.toString()).setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
return sendAndProcess(request, r -> r.getResponseObject(Boolean.class));
}
use of com.azure.core.http.HttpRequest in project lowkey-vault by nagyesta.
the class LowkeyVaultManagementClientImpl method createVault.
@Override
public VaultModel createVault(@NonNull final URI baseUri, @NonNull final RecoveryLevel recoveryLevel, @Nullable final Integer recoverableDays) {
final String body = vaultModelAsString(baseUri, recoveryLevel, recoverableDays);
final URI uri = UriUtil.uriBuilderForPath(vaultUrl, MANAGEMENT_VAULT_PATH);
final HttpRequest request = new HttpRequest(HttpMethod.POST, uri.toString()).setBody(body).setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
return sendAndProcess(request, r -> r.getResponseObject(VaultModel.class));
}
Aggregations