use of com.reprezen.kaizen.oasparser.model3.RequestBody in project edx-app-android by openedx.
the class GzipRequestInterceptor method gzip.
private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override
public MediaType contentType() {
return body.contentType();
}
@Override
public long contentLength() {
// We don't know the compressed length in advance!
return -1;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project java-sdk by dapr.
the class DaprHttp method doInvokeApi.
/**
* Invokes an API that returns a text payload.
*
* @param method HTTP method.
* @param pathSegments Array of path segments (/a/b/c -> ["a", "b", "c"]).
* @param urlParameters Parameters in the URL
* @param content payload to be posted.
* @param headers HTTP headers.
* @param context OpenTelemetry's Context.
* @return CompletableFuture for Response.
*/
private CompletableFuture<Response> doInvokeApi(String method, String[] pathSegments, Map<String, List<String>> urlParameters, byte[] content, Map<String, String> headers, Context context) {
final String requestId = UUID.randomUUID().toString();
RequestBody body;
String contentType = headers != null ? headers.get(Metadata.CONTENT_TYPE) : null;
MediaType mediaType = contentType == null ? MEDIA_TYPE_APPLICATION_JSON : MediaType.get(contentType);
if (content == null) {
body = mediaType.equals(MEDIA_TYPE_APPLICATION_JSON) ? REQUEST_BODY_EMPTY_JSON : RequestBody.Companion.create(new byte[0], mediaType);
} else {
body = RequestBody.Companion.create(content, mediaType);
}
HttpUrl.Builder urlBuilder = new HttpUrl.Builder();
urlBuilder.scheme(DEFAULT_HTTP_SCHEME).host(this.hostname).port(this.port);
for (String pathSegment : pathSegments) {
urlBuilder.addPathSegment(pathSegment);
}
Optional.ofNullable(urlParameters).orElse(Collections.emptyMap()).entrySet().stream().forEach(urlParameter -> Optional.ofNullable(urlParameter.getValue()).orElse(Collections.emptyList()).stream().forEach(urlParameterValue -> urlBuilder.addQueryParameter(urlParameter.getKey(), urlParameterValue)));
Request.Builder requestBuilder = new Request.Builder().url(urlBuilder.build()).addHeader(HEADER_DAPR_REQUEST_ID, requestId);
if (context != null) {
context.stream().filter(entry -> ALLOWED_CONTEXT_IN_HEADERS.contains(entry.getKey().toString().toLowerCase())).forEach(entry -> requestBuilder.addHeader(entry.getKey().toString(), entry.getValue().toString()));
}
if (HttpMethods.GET.name().equals(method)) {
requestBuilder.get();
} else if (HttpMethods.DELETE.name().equals(method)) {
requestBuilder.delete();
} else {
requestBuilder.method(method, body);
}
String daprApiToken = Properties.API_TOKEN.get();
if (daprApiToken != null) {
requestBuilder.addHeader(Headers.DAPR_API_TOKEN, daprApiToken);
}
if (headers != null) {
Optional.ofNullable(headers.entrySet()).orElse(Collections.emptySet()).stream().forEach(header -> {
requestBuilder.addHeader(header.getKey(), header.getValue());
});
}
Request request = requestBuilder.build();
CompletableFuture<Response> future = new CompletableFuture<>();
this.httpClient.newCall(request).enqueue(new ResponseFutureCallback(future));
return future;
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project teamscale-jacoco-agent by cqse.
the class AzureFileStorageUploader method fillFile.
/**
* Fills the file defined by the name with the given data. Should be used with {@link #createFile(File, String)},
* because the request only writes exactly the length of the given data, so the file should be exactly as big as the
* data, otherwise it will be partially filled or is not big enough.
*/
private Response<ResponseBody> fillFile(File zipFile, String fileName) throws IOException, UploaderException {
String filePath = uploadUrl.url().getPath() + fileName;
String range = "bytes=0-" + (zipFile.length() - 1);
String contentType = "application/octet-stream";
Map<String, String> headers = AzureFileStorageHttpUtils.getBaseHeaders();
headers.put(X_MS_WRITE, "update");
headers.put(X_MS_RANGE, range);
headers.put(CONTENT_LENGTH, "" + zipFile.length());
headers.put(CONTENT_TYPE, contentType);
Map<String, String> queryParameters = new HashMap<>();
queryParameters.put("comp", "range");
String auth = AzureFileStorageHttpUtils.getAuthorizationString(PUT, account, accessKey, filePath, headers, queryParameters);
headers.put(AUTHORIZATION, auth);
RequestBody content = RequestBody.create(MediaType.parse(contentType), zipFile);
return getApi().putData(filePath, headers, queryParameters, content).execute();
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project teamscale-jacoco-agent by cqse.
the class IHttpUploadApi method uploadCoverageZip.
/**
* Convenience method to perform an {@link #upload(okhttp3.MultipartBody.Part)} call for a coverage zip.
*/
public default Response<ResponseBody> uploadCoverageZip(File data) throws IOException {
RequestBody body = RequestBody.create(MediaType.parse("application/zip"), data);
MultipartBody.Part part = MultipartBody.Part.createFormData("file", "coverage.zip", body);
return upload(part).execute();
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project teamscale-jacoco-agent by cqse.
the class TeamscaleClient method uploadReport.
/**
* Uploads one in-memory report to Teamscale.
*/
public void uploadReport(EReportFormat reportFormat, String report, CommitDescriptor commitDescriptor, String revision, String partition, String message) throws IOException {
RequestBody requestBody = RequestBody.create(MultipartBody.FORM, report);
service.uploadReport(projectId, commitDescriptor, revision, partition, reportFormat, message, requestBody);
}
Aggregations