org.whispersystems.signalservice.api.push.exceptions.PushNetworkException Java Examples
The following examples show how to use
org.whispersystems.signalservice.api.push.exceptions.PushNetworkException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignalServiceMessageReceiver.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public ProfileAndCredential retrieveProfile(SignalServiceAddress address, Optional<ProfileKey> profileKey, Optional<UnidentifiedAccess> unidentifiedAccess, SignalServiceProfile.RequestType requestType) throws NonSuccessfulResponseCodeException, PushNetworkException, VerificationFailedException { Optional<UUID> uuid = address.getUuid(); if (uuid.isPresent() && profileKey.isPresent()) { if (requestType == SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL) { return socket.retrieveVersionedProfileAndCredential(uuid.get(), profileKey.get(), unidentifiedAccess); } else { return new ProfileAndCredential(socket.retrieveVersionedProfile(uuid.get(), profileKey.get(), unidentifiedAccess), SignalServiceProfile.RequestType.PROFILE, Optional.absent()); } } else { return new ProfileAndCredential(socket.retrieveProfile(address, unidentifiedAccess), SignalServiceProfile.RequestType.PROFILE, Optional.absent()); } }
Example #2
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public ProfileAndCredential retrieveVersionedProfileAndCredential(UUID target, ProfileKey profileKey, Optional<UnidentifiedAccess> unidentifiedAccess) throws NonSuccessfulResponseCodeException, PushNetworkException, VerificationFailedException { ProfileKeyVersion profileKeyIdentifier = profileKey.getProfileKeyVersion(target); ProfileKeyCredentialRequestContext requestContext = clientZkProfileOperations.createProfileKeyCredentialRequestContext(random, target, profileKey); ProfileKeyCredentialRequest request = requestContext.getRequest(); String version = profileKeyIdentifier.serialize(); String credentialRequest = Hex.toStringCondensed(request.serialize()); String subPath = String.format("%s/%s/%s", target, version, credentialRequest); String response = makeServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, NO_HEADERS, unidentifiedAccess); try { SignalServiceProfile signalServiceProfile = JsonUtil.fromJson(response, SignalServiceProfile.class); ProfileKeyCredential profileKeyCredential = signalServiceProfile.getProfileKeyCredentialResponse() != null ? clientZkProfileOperations.receiveProfileKeyCredential(requestContext, signalServiceProfile.getProfileKeyCredentialResponse()) : null; return new ProfileAndCredential(signalServiceProfile, SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL, Optional.fromNullable(profileKeyCredential)); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } }
Example #3
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public SignalServiceProfile retrieveVersionedProfile(UUID target, ProfileKey profileKey, Optional<UnidentifiedAccess> unidentifiedAccess) throws NonSuccessfulResponseCodeException, PushNetworkException { ProfileKeyVersion profileKeyIdentifier = profileKey.getProfileKeyVersion(target); String version = profileKeyIdentifier.serialize(); String subPath = String.format("%s/%s", target, version); String response = makeServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, NO_HEADERS, unidentifiedAccess); try { return JsonUtil.fromJson(response, SignalServiceProfile.class); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } }
Example #4
Source File: PushNotificationReceiveJob.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Override public void onRun() throws IOException { BackgroundMessageRetriever retriever = ApplicationDependencies.getBackgroundMessageRetriever(); boolean result = retriever.retrieveMessages(context, new RestStrategy()); if (result) { Log.i(TAG, "Successfully pulled messages."); } else { throw new PushNetworkException("Failed to pull messages."); } }
Example #5
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public AttachmentV2UploadAttributes getAttachmentV2UploadAttributes() throws NonSuccessfulResponseCodeException, PushNetworkException { String response = makeServiceRequest(ATTACHMENT_V2_PATH, "GET", null); try { return JsonUtil.fromJson(response, AttachmentV2UploadAttributes.class); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } }
Example #6
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
/** * @return The avatar URL path, if one was written. */ public Optional<String> writeProfile(SignalServiceProfileWrite signalServiceProfileWrite, ProfileAvatarData profileAvatar) throws NonSuccessfulResponseCodeException, PushNetworkException { String requestBody = JsonUtil.toJson(signalServiceProfileWrite); ProfileAvatarUploadAttributes formAttributes; String response = makeServiceRequest(String.format(PROFILE_PATH, ""), "PUT", requestBody); if (signalServiceProfileWrite.hasAvatar() && profileAvatar != null) { try { formAttributes = JsonUtil.fromJson(response, ProfileAvatarUploadAttributes.class); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } 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(); }
Example #7
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public Optional<String> setProfileAvatar(ProfileAvatarData profileAvatar) throws NonSuccessfulResponseCodeException, PushNetworkException { if (FeatureFlags.DISALLOW_OLD_PROFILE_SETTING) { throw new AssertionError(); } String response = makeServiceRequest(String.format(PROFILE_PATH, "form/avatar"), "GET", null); ProfileAvatarUploadAttributes formAttributes; try { formAttributes = JsonUtil.fromJson(response, ProfileAvatarUploadAttributes.class); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } if (profileAvatar != null) { 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(); }
Example #8
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void setProfileName(String name) throws NonSuccessfulResponseCodeException, PushNetworkException { if (FeatureFlags.DISALLOW_OLD_PROFILE_SETTING) { throw new AssertionError(); } makeServiceRequest(String.format(PROFILE_PATH, "name/" + (name == null ? "" : URLEncoder.encode(name))), "PUT", ""); }
Example #9
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void retrieveProfileAvatar(String path, File destination, long maxSizeBytes) throws NonSuccessfulResponseCodeException, PushNetworkException { try { downloadFromCdn(destination, 0, path, maxSizeBytes, null); } catch (MissingConfigurationException e) { throw new AssertionError(e); } }
Example #10
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public SignalServiceProfile retrieveProfileByUsername(String username, Optional<UnidentifiedAccess> unidentifiedAccess) throws NonSuccessfulResponseCodeException, PushNetworkException { String response = makeServiceRequest(String.format(PROFILE_USERNAME_PATH, username), "GET", null, NO_HEADERS, unidentifiedAccess); try { return JsonUtil.fromJson(response, SignalServiceProfile.class); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } }
Example #11
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public SignalServiceProfile retrieveProfile(SignalServiceAddress target, Optional<UnidentifiedAccess> unidentifiedAccess) throws NonSuccessfulResponseCodeException, PushNetworkException { String response = makeServiceRequest(String.format(PROFILE_PATH, target.getIdentifier()), "GET", null, NO_HEADERS, unidentifiedAccess); try { return JsonUtil.fromJson(response, SignalServiceProfile.class); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } }
Example #12
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public byte[] retrieveStickerManifest(byte[] packId) throws NonSuccessfulResponseCodeException, PushNetworkException { String hexPackId = Hex.toStringCondensed(packId); ByteArrayOutputStream output = new ByteArrayOutputStream(); try { downloadFromCdn(output, 0, 0, String.format(STICKER_MANIFEST_PATH, hexPackId), 1024 * 1024, null); } catch (MissingConfigurationException e) { throw new AssertionError(e); } return output.toByteArray(); }
Example #13
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public byte[] retrieveSticker(byte[] packId, int stickerId) throws NonSuccessfulResponseCodeException, PushNetworkException { String hexPackId = Hex.toStringCondensed(packId); ByteArrayOutputStream output = new ByteArrayOutputStream(); try { downloadFromCdn(output, 0, 0, String.format(Locale.US, STICKER_PATH, hexPackId, stickerId), 1024 * 1024, null); } catch (MissingConfigurationException e) { throw new AssertionError(e); } return output.toByteArray(); }
Example #14
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void retrieveAttachment(int cdnNumber, SignalServiceAttachmentRemoteId cdnPath, File destination, long maxSizeBytes, ProgressListener listener) throws NonSuccessfulResponseCodeException, PushNetworkException, MissingConfigurationException { final String path; if (cdnPath.getV2().isPresent()) { path = String.format(Locale.US, ATTACHMENT_ID_DOWNLOAD_PATH, cdnPath.getV2().get()); } else { path = String.format(Locale.US, ATTACHMENT_KEY_DOWNLOAD_PATH, cdnPath.getV3().get()); } downloadFromCdn(destination, cdnNumber, path, maxSizeBytes, listener); }
Example #15
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public List<ContactTokenDetails> retrieveDirectory(Set<String> contactTokens) throws NonSuccessfulResponseCodeException, PushNetworkException { try { ContactTokenList contactTokenList = new ContactTokenList(new LinkedList<>(contactTokens)); String response = makeServiceRequest(DIRECTORY_TOKENS_PATH, "PUT", JsonUtil.toJson(contactTokenList)); ContactTokenDetailsList activeTokens = JsonUtil.fromJson(response, ContactTokenDetailsList.class); return activeTokens.getContacts(); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } }
Example #16
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public AttachmentV3UploadAttributes getAttachmentV3UploadAttributes() throws NonSuccessfulResponseCodeException, PushNetworkException { String response = makeServiceRequest(ATTACHMENT_V3_PATH, "GET", null); try { return JsonUtil.fromJson(response, AttachmentV3UploadAttributes.class); } catch (IOException e) { Log.w(TAG, e); throw new NonSuccessfulResponseCodeException("Unable to parse entity"); } }
Example #17
Source File: RefreshPreKeysJob.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Override public boolean onShouldRetryThrowable(Exception exception) { if (exception instanceof NonSuccessfulResponseCodeException) return false; if (exception instanceof PushNetworkException) return true; return false; }
Example #18
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private String makeServiceRequest(String urlFragment, String method, String jsonBody, Map<String, String> headers, ResponseCodeHandler responseCodeHandler, Optional<UnidentifiedAccess> unidentifiedAccessKey) throws NonSuccessfulResponseCodeException, PushNetworkException { ResponseBody responseBody = makeServiceBodyRequest(urlFragment, method, jsonRequestBody(jsonBody), headers, responseCodeHandler, unidentifiedAccessKey); try { return responseBody.string(); } catch (IOException e) { throw new PushNetworkException(e); } }
Example #19
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
Response makeRequest(ClientSet clientSet, String authorization, List<String> cookies, String path, String method, String body) throws PushNetworkException, NonSuccessfulResponseCodeException { ConnectionHolder connectionHolder = getRandom(clientsFor(clientSet), random); return makeRequest(connectionHolder, authorization, cookies, path, method, body); }
Example #20
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
/** * Converts {@link IOException} on body byte reading to {@link PushNetworkException}. */ private static byte[] readBodyBytes(ResponseBody response) throws PushNetworkException { try { return response.bytes(); } catch (IOException e) { throw new PushNetworkException(e); } }
Example #21
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public void putNewGroupsV2Group(Group group, GroupsV2AuthorizationString authorization) throws NonSuccessfulResponseCodeException, PushNetworkException { makeStorageRequest(authorization.toString(), GROUPSV2_GROUP, "PUT", protobufRequestBody(group), GROUPS_V2_PUT_RESPONSE_HANDLER); }
Example #22
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public Group getGroupsV2Group(GroupsV2AuthorizationString authorization) throws NonSuccessfulResponseCodeException, PushNetworkException, InvalidProtocolBufferException { ResponseBody response = makeStorageRequest(authorization.toString(), GROUPSV2_GROUP, "GET", null, GROUPS_V2_GET_CURRENT_HANDLER); return Group.parseFrom(readBodyBytes(response)); }
Example #23
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public AvatarUploadAttributes getGroupsV2AvatarUploadForm(String authorization) throws NonSuccessfulResponseCodeException, PushNetworkException, InvalidProtocolBufferException { ResponseBody response = makeStorageRequest(authorization, GROUPSV2_AVATAR_REQUEST, "GET", null, NO_HANDLER); return AvatarUploadAttributes.parseFrom(readBodyBytes(response)); }
Example #24
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public GroupChange patchGroupsV2Group(GroupChange.Actions groupChange, String authorization) throws NonSuccessfulResponseCodeException, PushNetworkException, InvalidProtocolBufferException { ResponseBody response = makeStorageRequest(authorization, GROUPSV2_GROUP, "PATCH", protobufRequestBody(groupChange), GROUPS_V2_PATCH_RESPONSE_HANDLER); return GroupChange.parseFrom(readBodyBytes(response)); }
Example #25
Source File: PushServiceSocket.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public GroupChanges getGroupsV2GroupHistory(int fromVersion, GroupsV2AuthorizationString authorization) throws NonSuccessfulResponseCodeException, PushNetworkException, InvalidProtocolBufferException { ResponseBody response = makeStorageRequest(authorization.toString(), String.format(Locale.US, GROUPSV2_GROUP_CHANGES, fromVersion), "GET", null, GROUPS_V2_GET_LOGS_HANDLER); return GroupChanges.parseFrom(readBodyBytes(response)); }
Example #26
Source File: RefreshPreKeysJob.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
@Override public boolean onShouldRetry(@NonNull Exception exception) { if (exception instanceof NonSuccessfulResponseCodeException) return false; if (exception instanceof PushNetworkException) return true; return false; }
Example #27
Source File: SignalServiceMessageSender.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private SignalServiceAttachmentPointer uploadAttachmentV2(SignalServiceAttachmentStream attachment, byte[] attachmentKey, PushAttachmentData attachmentData) throws NonSuccessfulResponseCodeException, PushNetworkException { AttachmentV2UploadAttributes v2UploadAttributes = null; Optional<SignalServiceMessagePipe> localPipe = pipe.get(); if (localPipe.isPresent()) { Log.d(TAG, "Using pipe to retrieve attachment upload attributes..."); try { v2UploadAttributes = localPipe.get().getAttachmentV2UploadAttributes(); } catch (IOException e) { Log.w(TAG, "Failed to retrieve attachment upload attributes using pipe. Falling back..."); } } if (v2UploadAttributes == null) { Log.d(TAG, "Not using pipe to retrieve attachment upload attributes..."); v2UploadAttributes = socket.getAttachmentV2UploadAttributes(); } Pair<Long, byte[]> attachmentIdAndDigest = socket.uploadAttachment(attachmentData, v2UploadAttributes); return new SignalServiceAttachmentPointer(0, new SignalServiceAttachmentRemoteId(attachmentIdAndDigest.first()), attachment.getContentType(), attachmentKey, Optional.of(Util.toIntExact(attachment.getLength())), attachment.getPreview(), attachment.getWidth(), attachment.getHeight(), Optional.of(attachmentIdAndDigest.second()), attachment.getFileName(), attachment.getVoiceNote(), attachment.getCaption(), attachment.getBlurHash(), attachment.getUploadTimestamp()); }
Example #28
Source File: RotateProfileKeyJob.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
@Override protected boolean onShouldRetry(@NonNull Exception exception) { return exception instanceof PushNetworkException; }
Example #29
Source File: SendDeliveryReceiptJob.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
@Override public boolean onShouldRetry(@NonNull Exception e) { if (e instanceof PushNetworkException) return true; return false; }
Example #30
Source File: GroupV2UpdateSelfProfileKeyJob.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
@Override public boolean onShouldRetry(@NonNull Exception e) { return e instanceof PushNetworkException || e instanceof NoCredentialForRedemptionTimeException|| e instanceof GroupChangeBusyException; }