Push notification not working

Please provide the following:

  1. SDK Version:33
  2. Platforms(Android/iOS/web/all): all

Hi there, I’m having a problem handling push notifications as an array, in result we send individual notifications (using a for sentence basically) we got multiple errors (see below) in both ways.

HttpMessageNotReadableException: JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens

On the other hand using this way to handle notifications is not efficient and every time we try to send more than 10 (individual) fails.

Also if the application is closed the notification doesn’t show.

Cheers.

1 Like

Hey @seba07,

Can you share the exact code you’ve implemented to deliver notifications?

Cheers,
Adam

This is the code that we are using:

public class PushNotification {

private String to;
private String title;
private String body;
private Object data;

// getters and setters ....

}

//…
private HttpEntity makeDataRequest(Object data) {
MultiValueMap<String,String> httpHeaders = new LinkedMultiValueMap();
httpHeaders.add(“host”, “expo.host”);
httpHeaders.add(“accept”, “application/json”);
httpHeaders.add(“accept-encoding”, “gzip, deflate”);
httpHeaders.add(“content-type”, “application/json”);
HttpEntity httpRequest = new HttpEntity(data, httpHeaders);
return httpRequest;
}
/// …

private boolean sendPushNotifications(List<PushNotification> pushNotifications) {
    logger.info("intentando enviar {} notificaciones", pushNotifications.size());

    HttpEntity httpRequest = this.makeDataRequest(pushNotifications);
    ResponseEntity<Map> response = null;

    try {
        response = restTemplate.postForEntity(this.uriPushNotificaciones, httpRequest, Map.class);
    }
    catch (HttpClientErrorException e){
        logger.error("Error al enviar Notificacion Push: {} ", e.getResponseBodyAsString(), e);
        sendSingleNotifications(pushNotifications);
    }
    catch (Exception e) {
        logger.error("Error al enviar Notificacion Push. ", e);
        sendSingleNotifications(pushNotifications);
    }

    return response != null && response.getStatusCode() == HttpStatus.OK;
}

What does “data” contain?
What is HttpEntity?
What does the HTTP request actually look like (e.g. if you capture it with a packet sniffer or log it using a proxy server)?
The error message implies that the request is not valid JSON.

Hi, “data” contains a Map (HasMap) mainly.
We already solved our issue, effectively the error is when the response is parsed, We were sending the Http header “Accpet: gzip”, but we did not expect the compressed response.

Thanks for your help!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.