Search in sources :

Example 6 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project athena-java-sdk by uniubi-uface.

the class DefaultUniUbiHttpClient method buildRequest.

private Request buildRequest(String url, Object requestBody, Map<String, String> headers) {
    // 创建请求header
    Headers.Builder headerBuilder = new Headers.Builder();
    if (headers != null) {
        headers.forEach(headerBuilder::add);
    }
    Headers header = headerBuilder.build();
    // 创建请求参数内容
    String bodyContent = requestConverter.converter(requestBody);
    RequestBody body = RequestBody.create(SDK_UNIFY_CONTENT_TYPE, bodyContent);
    // 创建请求对象
    return new Request.Builder().url(url).post(body).headers(header).build();
}
Also used : Headers(okhttp3.Headers) RequestBody(okhttp3.RequestBody)

Example 7 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project files-sdk-java by Files-com.

the class FilesOkHttpApi method putBufferedInputStream.

@Override
public long putBufferedInputStream(String url, HttpMethods.RequestMethods requestType, String name, BufferedInputStream inputStream) throws IOException {
    String uri = ModelUtils.forceMandatoryUriEncode(url);
    MediaType type = MediaType.parse("application/octet-stream");
    Request.Builder request = new Request.Builder();
    request.addHeader("Content-type", "application/octet-stream");
    request.url(uri);
    RequestBody body = create(type, inputStream);
    updateRequestWithHttpMethod(request, body, requestType);
    Response response = FilesHttpClient.getHttpClient().newCall(request.build()).execute();
    return 0;
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) MediaType(okhttp3.MediaType) RequestBody(okhttp3.RequestBody)

Example 8 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project mollyim-android by mollyim.

the class PushServiceSocket method uploadToCdn0.

private byte[] uploadToCdn0(String path, String acl, String key, String policy, String algorithm, String credential, String date, String signature, InputStream data, String contentType, long length, OutputStreamFactory outputStreamFactory, ProgressListener progressListener, CancelationSignal cancelationSignal) throws PushNetworkException, NonSuccessfulResponseCodeException {
    ConnectionHolder connectionHolder = getRandom(cdnClientsMap.get(0), random);
    OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
    DigestingRequestBody file = new DigestingRequestBody(data, outputStreamFactory, contentType, length, progressListener, cancelationSignal, 0);
    RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("acl", acl).addFormDataPart("key", key).addFormDataPart("policy", policy).addFormDataPart("Content-Type", contentType).addFormDataPart("x-amz-algorithm", algorithm).addFormDataPart("x-amz-credential", credential).addFormDataPart("x-amz-date", date).addFormDataPart("x-amz-signature", signature).addFormDataPart("file", "file", file).build();
    Request.Builder request = new Request.Builder().url(connectionHolder.getUrl() + "/" + path).post(requestBody);
    if (connectionHolder.getHostHeader().isPresent()) {
        request.addHeader("Host", connectionHolder.getHostHeader().get());
    }
    Call call = okHttpClient.newCall(request.build());
    synchronized (connections) {
        connections.add(call);
    }
    try {
        Response response;
        try {
            response = call.execute();
        } catch (IOException e) {
            throw new PushNetworkException(e);
        }
        if (response.isSuccessful())
            return file.getTransmittedDigest();
        else
            throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
    } finally {
        synchronized (connections) {
            connections.remove(call);
        }
    }
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) DigestingRequestBody(org.whispersystems.signalservice.internal.push.http.DigestingRequestBody) ReceiptCredentialRequest(org.signal.zkgroup.receipts.ReceiptCredentialRequest) Request(okhttp3.Request) ChangePhoneNumberRequest(org.whispersystems.signalservice.api.account.ChangePhoneNumberRequest) DiscoveryRequest(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest) KeyBackupRequest(org.whispersystems.signalservice.internal.contacts.entities.KeyBackupRequest) ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) IOException(java.io.IOException) CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) Response(okhttp3.Response) KeyBackupResponse(org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse) ReceiptCredentialResponse(org.signal.zkgroup.receipts.ReceiptCredentialResponse) CredentialResponse(org.whispersystems.signalservice.api.groupsv2.CredentialResponse) StorageAuthResponse(org.whispersystems.signalservice.api.storage.StorageAuthResponse) VerifyDeviceResponse(org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse) DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) ProfileKeyCredentialResponse(org.signal.zkgroup.profiles.ProfileKeyCredentialResponse) TokenResponse(org.whispersystems.signalservice.internal.contacts.entities.TokenResponse) MultipartBody(okhttp3.MultipartBody) DigestingRequestBody(org.whispersystems.signalservice.internal.push.http.DigestingRequestBody) RequestBody(okhttp3.RequestBody)

Example 9 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project mollyim-android by mollyim.

the class PushServiceSocket method makeCallingRequest.

public CallingResponse makeCallingRequest(long requestId, String url, String httpMethod, List<Pair<String, String>> headers, byte[] body) {
    ConnectionHolder connectionHolder = getRandom(serviceClients, random);
    OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().followRedirects(false).connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
    RequestBody requestBody = body != null ? RequestBody.create(null, body) : null;
    Request.Builder builder = new Request.Builder().url(url).method(httpMethod, requestBody);
    if (headers != null) {
        for (Pair<String, String> header : headers) {
            builder.addHeader(header.first(), header.second());
        }
    }
    Request request = builder.build();
    for (int i = 0; i < MAX_FOLLOW_UPS; i++) {
        try (Response response = okHttpClient.newCall(request).execute()) {
            int responseStatus = response.code();
            if (responseStatus != 307) {
                return new CallingResponse.Success(requestId, responseStatus, response.body() != null ? response.body().bytes() : new byte[0]);
            }
            String location = response.header("Location");
            HttpUrl newUrl = location != null ? request.url().resolve(location) : null;
            if (newUrl != null) {
                request = request.newBuilder().url(newUrl).build();
            } else {
                return new CallingResponse.Error(requestId, new IOException("Received redirect without a valid Location header"));
            }
        } catch (IOException e) {
            Log.w(TAG, "Exception during ringrtc http call.", e);
            return new CallingResponse.Error(requestId, e);
        }
    }
    Log.w(TAG, "Calling request max redirects exceeded");
    return new CallingResponse.Error(requestId, new IOException("Redirect limit exceeded"));
}
Also used : CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) OkHttpClient(okhttp3.OkHttpClient) ReceiptCredentialRequest(org.signal.zkgroup.receipts.ReceiptCredentialRequest) Request(okhttp3.Request) ChangePhoneNumberRequest(org.whispersystems.signalservice.api.account.ChangePhoneNumberRequest) DiscoveryRequest(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest) KeyBackupRequest(org.whispersystems.signalservice.internal.contacts.entities.KeyBackupRequest) ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) IOException(java.io.IOException) HttpUrl(okhttp3.HttpUrl) CallingResponse(org.whispersystems.signalservice.api.messages.calls.CallingResponse) Response(okhttp3.Response) KeyBackupResponse(org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse) ReceiptCredentialResponse(org.signal.zkgroup.receipts.ReceiptCredentialResponse) CredentialResponse(org.whispersystems.signalservice.api.groupsv2.CredentialResponse) StorageAuthResponse(org.whispersystems.signalservice.api.storage.StorageAuthResponse) VerifyDeviceResponse(org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse) DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) ProfileKeyCredentialResponse(org.signal.zkgroup.profiles.ProfileKeyCredentialResponse) TokenResponse(org.whispersystems.signalservice.internal.contacts.entities.TokenResponse) DigestingRequestBody(org.whispersystems.signalservice.internal.push.http.DigestingRequestBody) RequestBody(okhttp3.RequestBody)

Example 10 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project Stundenplaner.FHE_EAH by avinotec.

the class NetworkHandler method registerTimeTableChanges.

/**
 * @param json
 * @param _Callback
 */
public void registerTimeTableChanges(final String json, final Callback<ResponseModel> _Callback) {
    Assert.assertTrue(mApi != null);
    final RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));
    mApi.registerTimeTableChanges(body).enqueue(_Callback);
}
Also used : RequestBody(okhttp3.RequestBody)

Aggregations

RequestBody (okhttp3.RequestBody)1358 Request (okhttp3.Request)785 Response (okhttp3.Response)598 IOException (java.io.IOException)420 Test (org.junit.Test)235 OkHttpClient (okhttp3.OkHttpClient)216 MultipartBody (okhttp3.MultipartBody)213 MediaType (okhttp3.MediaType)204 Call (okhttp3.Call)198 JSONObject (org.json.JSONObject)183 ResponseBody (okhttp3.ResponseBody)177 Callback (okhttp3.Callback)115 FormBody (okhttp3.FormBody)106 Buffer (okio.Buffer)98 File (java.io.File)92 Map (java.util.Map)90 JsonObject (io.vertx.core.json.JsonObject)89 Headers (okhttp3.Headers)88 HashMap (java.util.HashMap)83 HttpUrl (okhttp3.HttpUrl)80