Search in sources :

Example 1 with ContactManifestMismatchException

use of org.whispersystems.signalservice.api.push.exceptions.ContactManifestMismatchException in project Signal-Android by signalapp.

the class PushServiceSocket method makeStorageRequestResponse.

private Response makeStorageRequestResponse(String authorization, String path, String method, RequestBody body, ResponseCodeHandler responseCodeHandler) throws PushNetworkException, NonSuccessfulResponseCodeException {
    ConnectionHolder connectionHolder = getRandom(storageClients, random);
    OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
    // Log.d(TAG, "Opening URL: " + connectionHolder.getUrl());
    Request.Builder request = new Request.Builder().url(connectionHolder.getUrl() + path);
    request.method(method, body);
    if (connectionHolder.getHostHeader().isPresent()) {
        request.addHeader("Host", connectionHolder.getHostHeader().get());
    }
    if (authorization != null) {
        request.addHeader("Authorization", authorization);
    }
    Call call = okHttpClient.newCall(request.build());
    synchronized (connections) {
        connections.add(call);
    }
    Response response;
    try {
        response = call.execute();
        if (response.isSuccessful() && response.code() != 204) {
            return response;
        }
    } catch (IOException e) {
        throw new PushNetworkException(e);
    } finally {
        synchronized (connections) {
            connections.remove(call);
        }
    }
    ResponseBody responseBody = response.body();
    try {
        responseCodeHandler.handle(response.code(), responseBody);
        switch(response.code()) {
            case 204:
                throw new NoContentException("No content!");
            case 401:
            case 403:
                throw new AuthorizationFailedException(response.code(), "Authorization failed!");
            case 404:
                throw new NotFoundException("Not found");
            case 409:
                if (responseBody != null) {
                    throw new ContactManifestMismatchException(readBodyBytes(responseBody));
                } else {
                    throw new ConflictException();
                }
            case 429:
                throw new RateLimitException("Rate limit exceeded: " + response.code());
            case 499:
                throw new DeprecatedVersionException();
        }
        throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
    } catch (NonSuccessfulResponseCodeException | PushNetworkException e) {
        if (responseBody != null) {
            responseBody.close();
        }
        throw e;
    }
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) RateLimitException(org.whispersystems.signalservice.api.push.exceptions.RateLimitException) DeprecatedVersionException(org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException) ConflictException(org.whispersystems.signalservice.api.push.exceptions.ConflictException) 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) GroupNotFoundException(org.whispersystems.signalservice.internal.push.exceptions.GroupNotFoundException) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) IOException(java.io.IOException) NoContentException(org.whispersystems.signalservice.api.push.exceptions.NoContentException) ResponseBody(okhttp3.ResponseBody) 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) AuthorizationFailedException(org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException) ContactManifestMismatchException(org.whispersystems.signalservice.api.push.exceptions.ContactManifestMismatchException)

Example 2 with ContactManifestMismatchException

use of org.whispersystems.signalservice.api.push.exceptions.ContactManifestMismatchException in project Signal-Android by WhisperSystems.

the class PushServiceSocket method makeStorageRequestResponse.

private Response makeStorageRequestResponse(String authorization, String path, String method, RequestBody body, ResponseCodeHandler responseCodeHandler) throws PushNetworkException, NonSuccessfulResponseCodeException {
    ConnectionHolder connectionHolder = getRandom(storageClients, random);
    OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
    // Log.d(TAG, "Opening URL: " + connectionHolder.getUrl());
    Request.Builder request = new Request.Builder().url(connectionHolder.getUrl() + path);
    request.method(method, body);
    if (connectionHolder.getHostHeader().isPresent()) {
        request.addHeader("Host", connectionHolder.getHostHeader().get());
    }
    if (authorization != null) {
        request.addHeader("Authorization", authorization);
    }
    Call call = okHttpClient.newCall(request.build());
    synchronized (connections) {
        connections.add(call);
    }
    Response response;
    try {
        response = call.execute();
        if (response.isSuccessful() && response.code() != 204) {
            return response;
        }
    } catch (IOException e) {
        throw new PushNetworkException(e);
    } finally {
        synchronized (connections) {
            connections.remove(call);
        }
    }
    ResponseBody responseBody = response.body();
    try {
        responseCodeHandler.handle(response.code(), responseBody);
        switch(response.code()) {
            case 204:
                throw new NoContentException("No content!");
            case 401:
            case 403:
                throw new AuthorizationFailedException(response.code(), "Authorization failed!");
            case 404:
                throw new NotFoundException("Not found");
            case 409:
                if (responseBody != null) {
                    throw new ContactManifestMismatchException(readBodyBytes(responseBody));
                } else {
                    throw new ConflictException();
                }
            case 429:
                throw new RateLimitException("Rate limit exceeded: " + response.code());
            case 499:
                throw new DeprecatedVersionException();
        }
        throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
    } catch (NonSuccessfulResponseCodeException | PushNetworkException e) {
        if (responseBody != null) {
            responseBody.close();
        }
        throw e;
    }
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) RateLimitException(org.whispersystems.signalservice.api.push.exceptions.RateLimitException) DeprecatedVersionException(org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException) ConflictException(org.whispersystems.signalservice.api.push.exceptions.ConflictException) 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) GroupNotFoundException(org.whispersystems.signalservice.internal.push.exceptions.GroupNotFoundException) NotFoundException(org.whispersystems.signalservice.api.push.exceptions.NotFoundException) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) IOException(java.io.IOException) NoContentException(org.whispersystems.signalservice.api.push.exceptions.NoContentException) ResponseBody(okhttp3.ResponseBody) 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) AuthorizationFailedException(org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException) ContactManifestMismatchException(org.whispersystems.signalservice.api.push.exceptions.ContactManifestMismatchException)

Aggregations

IOException (java.io.IOException)2 Call (okhttp3.Call)2 OkHttpClient (okhttp3.OkHttpClient)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 ResponseBody (okhttp3.ResponseBody)2 ProfileKeyCredentialRequest (org.signal.zkgroup.profiles.ProfileKeyCredentialRequest)2 ProfileKeyCredentialResponse (org.signal.zkgroup.profiles.ProfileKeyCredentialResponse)2 ReceiptCredentialRequest (org.signal.zkgroup.receipts.ReceiptCredentialRequest)2 ReceiptCredentialResponse (org.signal.zkgroup.receipts.ReceiptCredentialResponse)2 ChangePhoneNumberRequest (org.whispersystems.signalservice.api.account.ChangePhoneNumberRequest)2 CredentialResponse (org.whispersystems.signalservice.api.groupsv2.CredentialResponse)2 CallingResponse (org.whispersystems.signalservice.api.messages.calls.CallingResponse)2 VerifyDeviceResponse (org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse)2 AuthorizationFailedException (org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException)2 ConflictException (org.whispersystems.signalservice.api.push.exceptions.ConflictException)2 ContactManifestMismatchException (org.whispersystems.signalservice.api.push.exceptions.ContactManifestMismatchException)2 DeprecatedVersionException (org.whispersystems.signalservice.api.push.exceptions.DeprecatedVersionException)2 NoContentException (org.whispersystems.signalservice.api.push.exceptions.NoContentException)2 NonSuccessfulResponseCodeException (org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException)2