Hello. Tell me in which direction to dig, where to look. The situation is as follows: if you log in under one user on your mobile phone (android, ios), send him a letter from the site, he will receive a message in the application in messages and also a push notification will come to the phone. If you make a logout on this phone and log in on another phone (no matter ios, android) under the same user account. If you send a message from the site, it will receive a message in the application in messages on the second phone and Push notification will also come there.
If you send it a certain number of times, the push notification will come to the first phone (to the one on which we did the logout).
I checked when the user logs in to the application, for him in the database in the user table (there is a deviceToken field) where the token is generated for the user. As soon as the user makes a logout, the token is deleted.
When sending messages from the site, I somtrel tomkata logs on the server (catalina.out): when the push comes to the correct phone, I see the correct token in the logs, but when the push comes to the phone where we logged off, I see a completely different token in the logs. Maybe he is caching somewhere, I do not understand?
My service to send push:
@Override public void sendPushNotifications(EventEntity event, Collection<UserEventDto> users) { PushNotificationData data = buildPushNotificationData(event, users); Set<Long> usersToAddEvent = new HashSet<>(); sendNotifications(data, usersToAddEvent); userDao.incrementUsers(new ArrayList<Long>(usersToAddEvent), event); } Next comes here (here the body is formed, etc.):
private PushNotificationData buildPushNotificationData(Object entity, Collection<UserEventDto> users) { PushNotificationData data = new PushNotificationData(); Date thresholdDate = new Date(UNREAD_NUMBER_TRACK_STARTED_TIMESTAMP); PayloadBuilder payload = null; Object dataAndroidString = null; Object notificationAndroidString = null; if (entity instanceof EventEntity) { EventEntity eventEntity = (EventEntity)entity; payload = buildApnsPayload(eventEntity); dataAndroidString = buildGCMData(eventEntity, eventEntity.getTitle()); // notificationAndroidString = buildGCMNotification(eventEntity.getTitle()); } if (entity instanceof MessageEntity) { MessageEntity messageEntity = (MessageEntity)entity; payload = buildApnsMessagePayload(messageEntity); dataAndroidString = buildGCMMessageData(messageEntity, messageEntity.getBody()); notificationAndroidString = buildGCMNotification(messageEntity.getBody()); } if (entity instanceof MyCheckListWebLinkEntity) { MyCheckListWebLinkEntity myCheckListWebLinkEntity = (MyCheckListWebLinkEntity)entity; payload = buildApnsReminderMessagePayload(myCheckListWebLinkEntity); dataAndroidString = buildGCMReminderMessageData(myCheckListWebLinkEntity); notificationAndroidString = buildGCMReminderMessageNotification(myCheckListWebLinkEntity); } data.setPayload(payload); data.setDataAndroidString(dataAndroidString); data.setNotificationAndroidString(notificationAndroidString); data.setThresholdDate(thresholdDate); data.setUsers(users); return data; } Further here (sending the push is happening here):
public void sendNotifications(PushNotificationData data, Set<Long> usersToAddEvent) { Set<String> androidUsers = new HashSet<>(); for (UserEventDto user : data.getUsers()) { try { int unreadNumber = 1; if (user.getClientAppVersion().after(data.getThresholdDate())) { unreadNumber += user.getUnreadNumber(); } String payloadString = data.getPayload().badge(unreadNumber).build(); if (PlatformType.ANDROID.equals(user.getPlatform())) { androidUsers.add(user.getDeviceToken()); } else { apnsServiceSingleton.push(user.getDeviceToken(), payloadString); } if (usersToAddEvent != null) { usersToAddEvent.add(user.getId()); } } catch (NetworkIOException e) { LOGGER.error("Exception while sending apns message: " + e.getMessage(), e); } } if (!androidUsers.isEmpty()) { try { androidPushService.push(new ArrayList<>(androidUsers), data.getDataAndroidString(), data.getNotificationAndroidString()); } catch (Exception e) { LOGGER.error("Exception while sending GSM message: " + e.getMessage(), e); } } } This is specifically for android:
private ResponseDto execute(RequestAndroidDto requestDto) { PostMethod postMethod = null; String response = null; ResponseDto e; try { postMethod = new PostMethod("/gcm/send"); postMethod.addRequestHeader("Content-Type", "application/json"); postMethod.addRequestHeader("Accept", "application/json"); postMethod.addRequestHeader("Authorization", "key=" + this.getKey()); postMethod.setRequestEntity(new StringRequestEntity(this.objectMapper.writeValueAsString(requestDto), "application/json", "utf-8")); LOGGER.warn(this.objectMapper.writeValueAsString(requestDto)); this.getClient().executeMethod(postMethod); response = postMethod.getResponseBodyAsString(); LOGGER.warn(response); e = (ResponseDto)this.objectMapper.readValue(response, ResponseDto.class); } catch (UnsupportedEncodingException var9) { LOGGER.warn("Exception while sending gcm push. " + response); throw new RuntimeException(var9); } catch (IOException var10) { LOGGER.warn("Exception while sending gcm push. " + response); throw new RuntimeException(var10); } finally { if(postMethod != null) { postMethod.releaseConnection(); } } return e; } public final boolean push(List<String> to, Object data, Object notification) { if (to.isEmpty()) { return false; } RequestAndroidDto requestDto = new RequestAndroidDto(); requestDto.registrationIds = to; requestDto.data = data; // requestDto.notification = notification; return this.execute(requestDto).success > 0L; } This is for ios:
private synchronized ApnsService getApnsService() { if (apnsService == null) { this.apnsService = new ApnsServiceBuilder() .withCert(filename, certPassword != null ? certPassword : "123softteco321") .asPool(15).withCacheLength(1000).withSandboxDestination().withDelegate(new ApnsLoggerDelegate()).build(); } return apnsService; } ApnsNotification push(final String deviceToken, final String payloadString) { return getApnsService().push(deviceToken, payloadString); } Map<String, Date> getInactiveDevices() { return getApnsService().getInactiveDevices(); } Please explain what affects this and how should I deal with it? I would be very grateful for the answer or hint in which direction I should look. Do not judge strictly, never worked with the like. Thanks in advance for your help!
userscome tosendPushNotifications- Anton Shchyrovuserscollection. If notifications do not arrive there, then eitherusersfilled with incorrect data, or thegetDeviceToken()/getId()methods return incorrect values - Anton Shchyrov