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");
}
}
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;
}
}
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();
}
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);
}
});
}
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");
}
}
Aggregations