Search in sources :

Example 6 with MalformedResponseException

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

the class PushServiceSocket method submitBoostReceiptCredentials.

public ReceiptCredentialResponse submitBoostReceiptCredentials(String paymentIntentId, ReceiptCredentialRequest receiptCredentialRequest) throws IOException {
    String payload = JsonUtil.toJson(new BoostReceiptCredentialRequestJson(paymentIntentId, receiptCredentialRequest));
    String response = makeServiceRequestWithoutAuthentication(BOOST_RECEIPT_CREDENTIALS, "POST", payload, (code, body) -> {
        if (code == 204)
            throw new NonSuccessfulResponseCodeException(204);
    });
    ReceiptCredentialResponseJson responseJson = JsonUtil.fromJson(response, ReceiptCredentialResponseJson.class);
    if (responseJson.getReceiptCredentialResponse() != null) {
        return responseJson.getReceiptCredentialResponse();
    } else {
        throw new MalformedResponseException("Unable to parse response");
    }
}
Also used : NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Example 7 with MalformedResponseException

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

the class PushServiceSocket method makeServiceRequest.

private Response makeServiceRequest(String urlFragment, String method, RequestBody body, Map<String, String> headers, ResponseCodeHandler responseCodeHandler, Optional<UnidentifiedAccess> unidentifiedAccessKey, boolean doNotAddAuthenticationOrUnidentifiedAccessKey) throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException {
    Response response = getServiceConnection(urlFragment, method, body, headers, unidentifiedAccessKey, doNotAddAuthenticationOrUnidentifiedAccessKey);
    ResponseBody responseBody = response.body();
    try {
        responseCodeHandler.handle(response.code(), responseBody);
        return validateServiceResponse(response);
    } catch (NonSuccessfulResponseCodeException | PushNetworkException | MalformedResponseException e) {
        if (responseBody != null) {
            responseBody.close();
        }
        throw e;
    }
}
Also used : 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) PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException) ResponseBody(okhttp3.ResponseBody)

Example 8 with MalformedResponseException

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

the class PushServiceSocket method writeProfile.

/**
 * @return The avatar URL path, if one was written.
 */
public Optional<String> writeProfile(SignalServiceProfileWrite signalServiceProfileWrite, ProfileAvatarData profileAvatar) throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException {
    String requestBody = JsonUtil.toJson(signalServiceProfileWrite);
    ProfileAvatarUploadAttributes formAttributes;
    String response = makeServiceRequest(String.format(PROFILE_PATH, ""), "PUT", requestBody, NO_HEADERS, PaymentsRegionException::responseCodeHandler, Optional.absent());
    if (signalServiceProfileWrite.hasAvatar() && profileAvatar != null) {
        try {
            formAttributes = JsonUtil.fromJson(response, ProfileAvatarUploadAttributes.class);
        } catch (IOException e) {
            Log.w(TAG, e);
            throw new MalformedResponseException("Unable to parse entity", e);
        }
        uploadToCdn0(AVATAR_UPLOAD_PATH, formAttributes.getAcl(), formAttributes.getKey(), formAttributes.getPolicy(), formAttributes.getAlgorithm(), formAttributes.getCredential(), formAttributes.getDate(), formAttributes.getSignature(), profileAvatar.getData(), profileAvatar.getContentType(), profileAvatar.getDataLength(), profileAvatar.getOutputStreamFactory(), null, null);
        return Optional.of(formAttributes.getKey());
    }
    return Optional.absent();
}
Also used : PaymentsRegionException(org.whispersystems.signalservice.internal.push.exceptions.PaymentsRegionException) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) IOException(java.io.IOException) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Example 9 with MalformedResponseException

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

the class PushServiceSocket method retrieveVersionedProfile.

public ListenableFuture<SignalServiceProfile> retrieveVersionedProfile(UUID target, ProfileKey profileKey, Optional<UnidentifiedAccess> unidentifiedAccess, Locale locale) {
    ProfileKeyVersion profileKeyIdentifier = profileKey.getProfileKeyVersion(target);
    String version = profileKeyIdentifier.serialize();
    String subPath = String.format("%s/%s", target, version);
    ListenableFuture<String> response = submitServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, AcceptLanguagesUtil.getHeadersWithAcceptLanguage(locale), unidentifiedAccess);
    return FutureTransformers.map(response, body -> {
        try {
            return JsonUtil.fromJson(body, SignalServiceProfile.class);
        } catch (IOException e) {
            Log.w(TAG, e);
            throw new MalformedResponseException("Unable to parse entity", e);
        }
    });
}
Also used : ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) IOException(java.io.IOException) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Example 10 with MalformedResponseException

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

the class PushServiceSocket method submitReceiptCredentials.

public ReceiptCredentialResponse submitReceiptCredentials(String subscriptionId, ReceiptCredentialRequest receiptCredentialRequest) throws IOException {
    String payload = JsonUtil.toJson(new ReceiptCredentialRequestJson(receiptCredentialRequest));
    String response = makeServiceRequestWithoutAuthentication(String.format(SUBSCRIPTION_RECEIPT_CREDENTIALS, subscriptionId), "POST", payload, (code, body) -> {
        if (code == 204)
            throw new NonSuccessfulResponseCodeException(204);
    });
    ReceiptCredentialResponseJson responseJson = JsonUtil.fromJson(response, ReceiptCredentialResponseJson.class);
    if (responseJson.getReceiptCredentialResponse() != null) {
        return responseJson.getReceiptCredentialResponse();
    } else {
        throw new MalformedResponseException("Unable to parse response");
    }
}
Also used : NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Aggregations

MalformedResponseException (org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)18 GroupsV2AuthorizationString (org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString)10 NonSuccessfulResponseCodeException (org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException)8 IOException (java.io.IOException)6 Response (okhttp3.Response)6 ResponseBody (okhttp3.ResponseBody)4 ProfileKeyCredentialResponse (org.signal.zkgroup.profiles.ProfileKeyCredentialResponse)4 ReceiptCredentialResponse (org.signal.zkgroup.receipts.ReceiptCredentialResponse)4 CredentialResponse (org.whispersystems.signalservice.api.groupsv2.CredentialResponse)4 CallingResponse (org.whispersystems.signalservice.api.messages.calls.CallingResponse)4 VerifyDeviceResponse (org.whispersystems.signalservice.api.messages.multidevice.VerifyDeviceResponse)4 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)4 StorageAuthResponse (org.whispersystems.signalservice.api.storage.StorageAuthResponse)4 DiscoveryResponse (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse)4 KeyBackupResponse (org.whispersystems.signalservice.internal.contacts.entities.KeyBackupResponse)4 MultiRemoteAttestationResponse (org.whispersystems.signalservice.internal.contacts.entities.MultiRemoteAttestationResponse)4 RemoteAttestationResponse (org.whispersystems.signalservice.internal.contacts.entities.RemoteAttestationResponse)4 TokenResponse (org.whispersystems.signalservice.internal.contacts.entities.TokenResponse)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2