Giter Site home page Giter Site logo

javapns-jdk16's Introduction

DEPRECATED

This library uses the legacy Apple API. Please, consider moving to a more efficient HTTP-2/based API, by using another library (e.g. https://github.com/CleverTap/apns-http2).

I will stop mantaining this library, thanks everyone for your contributions.

javapns-jdk16

Apple Push Notification Service Provider for Java

Fork of JavaPNS to include Maven support - http://code.google.com/p/javapns/

Java1.6 compatible

Updates

Version 2.4.0 released!

2.4.0 Changes

  • Added support for the following fields:
  • category
  • mutable-content (iOS>=10)
  • title, subtitle (iOS>=10), title-loc-key, title-loc-args and launch-image

2.3.1 Changes

  • PushNotificationBigPayload complex and fromJson methods fixed
  • Fix to make trust store work on IBM JVM

2.3 Changes

  • iOS>=8 bigger notification payload support (2KB)
  • iOS>=7 Silent push notifications support ("content-available":1)

Installation through Central Maven Repository

javapns-jdk16 is available on the Central Maven Repository. To use javapns-jdk16 in your project, please add the following dependency to your pom.xml file:

<dependency>
	<groupId>com.github.fernandospr</groupId>
	<artifactId>javapns-jdk16</artifactId>
	<version>2.4.0</version>
</dependency>

Usage

You need to first construct the push notification payload.

PushNotificationBigPayload payload = ... // See Payload examples below

Then send it:

Push.payload(payload, p12File, password, isProduction, deviceTokens);

Payload examples

Based on Apple docs

Example 1

To send the following payload:

{
    "aps" : { "alert" : "Message received from Bob" },
    "acme2" : [ "bang",  "whiz" ]
}

You should code the following:

PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
payload.addAlert("Message received from Bob");
payload.addCustomDictionary("acme2", Arrays.asList("bang", "whiz"));

Example 2

To send the following payload:

{
    "aps" : {
        "alert" : {
            "title" : "Game Request",
            "body" : "Bob wants to play poker",
            "action-loc-key" : "PLAY"
        },
        "badge" : 5
    },
    "acme1" : "bar",
    "acme2" : [ "bang",  "whiz" ]
}

You should code the following:

PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
payload.addCustomAlertTitle("Game Request");
payload.addCustomAlertBody("Bob wants to play poker");
payload.addCustomAlertActionLocKey("PLAY");
payload.addBadge(5);
payload.addCustomDictionary("acme1", "bar");
payload.addCustomDictionary("acme2", Arrays.asList("bang", "whiz"));

Example 3

To send the following payload:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9,
        "sound" : "bingbong.aiff"
    },
    "acme1" : "bar",
    "acme2" : 42
}

You should code the following:

PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
payload.addCustomAlertBody("You got your emails.");
payload.addBadge(9);
payload.addSound("bingbong.aiff");
payload.addCustomDictionary("acme1", "bar");
payload.addCustomDictionary("acme2", 42);

Example 4

To send the following payload:

{
    "aps" : {
        "alert" : {
            "loc-key" : "GAME_PLAY_REQUEST_FORMAT",
            "loc-args" : [ "Jenna", "Frank"]
        },
        "sound" : "chime.aiff"
    },
    "acme" : "foo"
}

You should code the following:

PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
payload.addCustomAlertLocKey("GAME_PLAY_REQUEST_FORMAT");
payload.addCustomAlertLocArgs(Arrays.asList("Jenna", "Frank"));
payload.addSound("chime.aiff");
payload.addCustomDictionary("acme", "foo");

Example 5

To send the following payload:

{
    "aps" : {
        "content-available" : 1
    }, 
    "acme" : "foo"
}

You should code the following:

PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
payload.setContentAvailable(true);
payload.addCustomDictionary("acme", "foo");

Example 6

To send the following payload:

{
  "aps": {
    "mutable-content":1,
    "alert":{
      "title": "Notification title",
      "subtitle": "Notification subtitle",
      "body": "Notification body"
    }
  },
  "media-attachment": "https://url/to/content.mpg"
}

You should code the following:

PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
payload.setMutableContent(true);
payload.addCustomAlertTitle("Notification title");
payload.addCustomAlertSubtitle("Notification subtitle");
payload.addCustomAlertBody("Notification body");
payload.addCustomDictionary("media-attachment", "https://url/to/content.mpg");

javapns-jdk16's People

Contributors

fernandospr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

javapns-jdk16's Issues

please remove log4j 1.2 dependencies

They cause issues with j2ee jars in gradle.

+--- com.github.fernandospr:javapns-jdk16:2.4.0
| --- log4j:log4j:1.2.12 -> 1.2.15
| +--- javax.mail:mail:1.4
| | --- javax.activation:activation:1.1
| +--- javax.jms:jms:1.1
| +--- com.sun.jdmk:jmxtools:1.2.1
| --- com.sun.jmx:jmxri:1.2.1

Using Credentials with Proxy Servers

I'm using your wonderful library and trying to add proxy server support into my code. JavaPNS seems to work fine against a proxy server that does not require authentication, but does not seem able to pass credentials to a proxy server that requires authentication.

I've searched around and found an instance of your ProxyManager that has the following method:
ProxyManager.setProxyBasicAuthorization(username, password);

The problem is that that appears only in a beta release.
https://github.com/azinman/javapns/blob/master/JavaPNS_2.3_Beta_2.jar?raw=true

I do not see that method on any release I find on the maven site. Was this functionality removed?

I have tried to do it manually in my code by setting the "javapns.communication.proxyAuthorization" System property, but it doesn't seem to make a difference.

What should I do to work with a proxy server that requires authentication?

-pat

Total payload size exceeds allowed limit

I thought this fork version of javapns would allow 2KB payloads? Is there a new way of sending push so it'll bypass the payload size?

I'm sending via:

PushNotificationPayload payload = PushNotificationPayload payload = PushNotificationBigPayload.complex();
payload.addAlert("...");
payload.addCustomDictionary("mydata", hugedata.toString());

Push.payload(payload, keystore, password, isProduction, threads, devices);

javapns.notification.exceptions.PayloadMaxSizeExceededException: Total payload size exceeds allowed limit (payload is 523 bytes, limit is 256)
at javapns.notification.Payload.validateMaximumPayloadSize(Payload.java:252)
at javapns.notification.Payload.getPayloadAsBytes(Payload.java:140)
at javapns.notification.PushNotificationManager.getMessage(PushNotificationManager.java:558)
at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:381)
at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:350)
at javapns.notification.transmission.NotificationThread.runList(NotificationThread.java:228)
at javapns.notification.transmission.NotificationThread.run(NotificationThread.java:199)
at java.lang.Thread.run(Thread.java:745)

Communication exception: java.net.SocketException: Network is unreachable

javapns working fine in the local system, but when I upload this file to virtual machine getting an error.

javapns.communication.exceptions.CommunicationException: Communication exception: java.net.SocketException: Network is unreachable
at javapns.communication.ConnectionToAppleServer.getSSLSocket(ConnectionToAppleServer.java:156)
at javapns.notification.PushNotificationManager.initializeConnection(PushNotificationManager.java:106)
at javapns.Push.sendPayload(Push.java:171)
at javapns.Push.payload(Push.java:149)
at apnPushNotification.processRequest(apnPushNotification.java:97)
at apnPushNotification.doGet(apnPushNotification.java:138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)

ExceptionInInitializerError - Caused By Malformed \uxxxx encoding

Thanks for the library! Things are working and able to push notifications to IOS devices.
But facing a strange issue when deployed in Weblogic Application Server running on AIX server.
Any suggestions for sorting this out!!

Caused By: java.lang.IllegalArgumentException: Malformed \uxxxx encoding.

   at java.util.Properties.loadConvert(Properties.java:618)

   at java.util.Properties.load0(Properties.java:435)

   at java.util.Properties.load(Properties.java:364)

   at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:433)

   at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:468)

   at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)

   at org.apache.log4j.Logger.getLogger(Logger.java:117)

   at javapns.notification.Payload.<clinit>(Payload.java:25)

   at javapns.Push.alert(Push.java:47)

why some payload‘s sending take time so long?

PushNotificationManager.sendNotification(PushedNotification notification, boolean closeAfter)
tw1 = System.currentTimeMillis();//add this
this.socket.getOutputStream().write(bytes);
tw2 = System.currentTimeMillis();//add this

my issue:
mostly tw2 - tw1 is very small when sending fast,but some time tw2 - tw1 is very big。

when this.socket.getOutputStream().write(bytes) take time too long
tcpdump:
13:26:46.984748 IP 17.188.139.28.2195 > BJ104-12.WOMAI-INC.COM.46631: Flags [.], ack 13624, win 542, options [nop,nop,TS val 3653840026 ecr 3582219148,nop,nop,sack 2 {19096:20464}{14992:17728}], length 0
13:26:46.984765 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 20464:23200, ack 3331, win 137, options [nop,nop,TS val 3582219344 ecr 3653840026], length 2736
13:26:47.563153 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582219923 ecr 3653840026], length 1368
13:26:48.721143 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582221081 ecr 3653840026], length 1368
13:26:51.037145 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582223397 ecr 3653840026], length 1368
13:26:55.669160 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582228029 ecr 3653840026], length 1368
13:27:04.933145 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582237293 ecr 3653840026], length 1368
13:27:23.461194 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582255821 ecr 3653840026], length 1368
13:28:00.517174 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582292877 ecr 3653840026], length 1368
13:29:14.629507 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582366989 ecr 3653840026], length 1368
13:31:14.629253 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582486989 ecr 3653840026], length 1368
13:33:14.629155 IP BJ104-12.WOMAI-INC.COM.46631 > 17.188.139.28.2195: Flags [.], seq 13624:14992, ack 3331, win 137, options [nop,nop,TS val 3582606989 ecr 3653840026], length 1368
13:33:14.825406 IP 17.188.139.28.2195 > BJ104-12.WOMAI-INC.COM.46631: Flags [.], ack 17728, win 563, options [nop,nop,TS val 3654227811 ecr 3582606989,nop,nop,sack 1 {19096:20464}], length 0
it seems i cant recieve server's ack and resend my data...

Do not receive notifications

I try this:

try {
            if(token != null && !token.isEmpty()) {
                System.out.println("send push");
                PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
                payload.addCustomAlertTitle(title);
                payload.addCustomAlertBody(mgs);
                payload.addCustomAlertActionLocKey("PLAY");
                payload.addBadge(1);
                payload.addSound("default");
                Push.payload(payload, new FileInputStream(getServletContext().getRealPath("")+"push.p12"), "", true, token);
            } else {
                System.out.println("token empty");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (KeystoreException e) {
            e.printStackTrace();
        } catch (CommunicationException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

But notification not received. Errors there are no.

javapns-jdk16-2.4.0

Thanks.

org.json.JSONException: Expected a ',' or '}' at character 179

Even though my JSON seems to be perfectly valid , i am getting this exception when i try to construct a PushNotificationBigPayload . Any pointers on the issue would be very helpful .

org.json.JSONException: Expected a ',' or '}' at character 179
at org.json.JSONTokener.syntaxError(JSONTokener.java:413)
at org.json.JSONObject.(JSONObject.java:222)
at org.json.JSONTokener.nextValue(JSONTokener.java:347)
at org.json.JSONObject.(JSONObject.java:205)
at org.json.JSONTokener.nextValue(JSONTokener.java:347)
at org.json.JSONObject.(JSONObject.java:205)

------------------------------------------------- My JSON------------------------------

{"data":{"registrationId":null,"recordLocator":"ROTTIG","operatingCarrierCode":null,"flightNumber":"2496","departureAirport":"DFW","payloadVersion":"2.0"},"aps":{"alert":{"title":"GIG","body":"2496 departs at 15:45 PM"},"sound":"default","category":"4HourFlightUpdate","content-available":"0"}}

Total payload size exceeds allowed limit (payload is 1135 bytes, limit is 256)

I downloaded the new javapns-jdk16-2.3.jar
When I try to push new notification I always receive the error regarding the size limit although it less than 2KB. We are targeting ios 8 and above I not sure if the error is produced by your library or its a response from apple APN.
We also switch from IOS7 to IOS8 but I didnt change the certificate p.12 (I am not sure if i need to create/revoke a new one if I want to support ios8 payload change) .

           JSONObject payload = createPayloadIos(message, payloadObject, clientOpcode);
            PushNotificationPayload payloadMY = PushNotificationPayload.fromJSON(payload.toString());
            String certificatePath = Thread.currentThread().getContextClassLoader().getResource("Certificates1.p12").getPath();
            String certificatePassword = "XXX";
            List<PushedNotification> notifications = Push.payload(payloadMY, certificatePath, certificatePassword, false, notificationToken);
            deleteDeviceTokenFromDataBase(notifications);

Will really appreciate our advice for that issue?

Same message received as Multiple Notifications in Single device.

While sending same message to group of devices, in particular scenario few devices got multiple Notifications.

Assume that using following method, the application send same payload to 100 devices.

public PushedNotifications sendNotifications(Payload payload, List<Device> devices) throws CommunicationException, KeystoreException {
        PushedNotifications notifications = new PushedNotifications();
        for (Device device : devices)
            notifications.add(sendNotification(device, payload, false, SEQUENTIAL_IDENTIFIER));
        stopConnection();
        return notifications;
    }

After sending message to 50 devices, assume that 51st message is failed and breached the retry attempts; This will set transmissionCompleted as false for 51st Notification. From 52nd message onwards everything goes proper upto 100. Before closing the connection via stopConnection method, processed failed notifications method is called. Once response received from APNS, it will iterate through LinkedHashMap pushedNotifications and see which one is unsuccessful. Since the transmissionCompleted is false for 51st message, following check will be satisfied if (foundFirstFail || !notification.isSuccessful()) {, it will skip the 51st Message and from 52nd message onwards it will do the retry. This will send the same message to the devices from 52nd to 100.

Solution - There are various ways to fix this. Simple way is PushedNotification Object should not be considered in pushedNotifications hashMap, once it is failed in sending the message.

Async send in Web Application JavaEE

I'm having trouble sending notifications. I use your library in the Web application. The problem is that I'm forced to wait for the time until the notification goes. In the send parameters, I specified numberOfThreads, but it did not work.

Prompt please that I not so do?

Increase limit for Apple message payload to 4K

Hello,

with the introduction of iOS 9 the payload size for push messages has been increased to 4K. According to the official Apple documentation: "The body content of your message is the JSON dictionary object containing the notification data. The body data must not be compressed and its maximum size is 4KB (4096 bytes)."

I understand that the current payload limit supported by this library is 2K (from version 2.3). Is there any chance for this limit to be uplifted to 4K any time soon?

Invalid token

[[1] transmitted {"aps":{"sound":"default","alert":{"body":"Hello, world22222222222!","action":"Open","Aid":22},"badge":2}} on first attempt to token a4cad..4dfb3 APNS: [1] Invalid token javapns.notification.exceptions.ErrorResponsePacketReceivedException: An error response packet was received from the APNS server: APNS: [1] Invalid token, [2] transmitted {"aps":{"sound":"default","alert":{"body":"Hello, world22222222222!","action":"Open","Aid":22},"badge":2}} on first attempt to token c018a..9256e APNS: [2] Invalid token javapns.notification.exceptions.ErrorResponsePacketReceivedException: An error response packet was received from the APNS server: APNS: [2] Invalid token]

我是这样写的,但是推送感觉有点慢。

import javapns.Push;
import javapns.notification.PushNotificationBigPayload;

public class CopyOfMain {
/** [email protected] /
/
APNs Server Host /
private static final String HOST = "gateway.sandbox.push.apple.com";
/
APNs Port */
private static final int PORT = 2195;

    public static void sendNotification() {
       try {
    	   String p12FilePath = "dev4Push.p12";
           String p12Password = "123654";	                  
           String tokenArray = "6e6d1850eeb233d65595471e783155458ce8c5c0a802bfd1dee0721cc1c1d166";
	           PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
	           payload.addSound("default");
	           payload.addBadge(9);
	           payload.setMutableContent(true);
	           payload.setContentAvailable(true);
	           payload.addCustomAlertTitle("最美壁纸");
	           payload.addCustomAlertSubtitle("周杰伦新歌");
	           payload.addCustomAlertBody("这个是一张周杰伦的美照,喜欢吗");
	           payload.addCustomDictionary("mutable-content", "1");
	           payload.addCustomDictionary("image", "https://img1.doubanio.com/img/musician/large/22817.jpg");
	           payload.addCustomDictionary("url", "http://www. baidu.com/?tp=4");
	           payload.addCustomDictionary("id", "1007");		                    
	           Push.payload(payload, p12FilePath, p12Password, false, tokenArray);
          System.out.print("推送成功");
       } 
       catch (Exception e) {
           e.printStackTrace();
       }   
    }
    public static void main(String[] args) {
		try 
		{
			CopyOfMain.sendNotification();
		} catch (Exception e) {				
			e.printStackTrace();
		}
	}

}

Notification not working after certificate renew

Hi,

As my certificate expire in a month, a make a new one. But this one not working, I didn't receive notifications (but it working with the old certificate). I try with the .cer format and it works.
Am I the only one to have this problem ?

APNS Push Notification Feedback Service Connection Timeout

Hi,
I have used java APNS sdk version 2.3.1 to send push notification & getting feedback from APNS.
We have two environment i.e. Local(Personal Machine) & Development(Linux Virtual Machine installed on AWS Cloud), in which we are using same APNS certificate & key (Sandbox).
Push Notification working properly in both environment but Push Feedback is working only in Local Environment but not working in Development environment.
Error:
Communication exception: java.net.ConnectException: Connection timed out occur while using Feedback service in Development environment.

Code is given below to use Feedback service.
try { List devices = Push.feedback(externalCredentials.getKeyStore(), externalCredentials.getProperty(APNS_SECRET_KEY), false);
if(devices != null && devices.size() != 0){
System.out.println("feedback service");
}
}
catch (Exception e) { log.error("Exception "+ e.getMessage());
}

Please give a suggestion.

about proxy server

What proxy server do you use?
I tested several proxy servers and none of the proxy servers could connect to APNs server except for SS5。
Would you recommend some?

Is the code written like this

import javapns.Push;

import javapns.notification.PushNotificationBigPayload;

public class MainApnsSend {

public static void main(String[] args) throws Exception {
   
	 try {

         
    	   int N = 1;
           String tokenArray[] = new String[N];	           
           tokenArray[0] = "d065aaf2d65e16a9b46b919168a173466bde8c3bfed4aa8e38825ee1a4750611";
           String deviceID = "ipod touch";	      
           for(int i=0; i<N; i++) {
        	   deviceID = deviceID + i;
        	   PushNotificationBigPayload payload = PushNotificationBigPayload.complex();
        	   payload.setMutableContent(true);
        	   
        	   payload.addCustomAlertTitle("Notification title");
        	   payload.addBadge(9);
        	   payload.addSound("bingbong.aiff");
        	   payload.addCustomAlertSubtitle("Notification subtitle");
        	   payload.addCustomAlertBody("Notification body");
        	   payload.addCustomDictionary("media-attachment", "https://url/to/content.mpg");
	           String p12FilePath = "ts.p12";
	           String p12Password = "123654";
	           String token = tokenArray[i];
	           Push.payload(payload, p12FilePath, p12Password,true, token);
	           System.out.print("push");
	           
           }  
       } 
       catch (Exception e) {
           e.printStackTrace();
       }   
}

}

some push msg failed

when i send 1000 or more msgs to apn server, some failed,but i send 100 or less msgs,it goes succeed!

public static void pushSimplePayloadUsingThreads(String keystore, String password, boolean production, String token, boolean simulation, int devices, int threads) {}

when 1000 devices, about 200 succeed;
when 100 devices ,almost all succeed.

why?

java.lang.StringIndexOutOfBoundsException: String index out of range: 64

This harmful implementation gives OOB exception on short token like simulator generated by iOS IDE
`
public String toString() {
StringBuilder msg = new StringBuilder();
msg.append("[" + this.identifier + "]");
msg.append(this.transmissionCompleted?" transmitted " + this.payload + " on " + this.getLatestTransmissionAttempt():" not transmitted");
msg.append(" to token " + this.device.getToken().substring(0, 5) + ".." + this.device.getToken().substring(59, 64));
if(this.response != null) {
msg.append(" " + this.response.getMessage());
}

        if(this.exception != null) {
            msg.append("  " + this.exception);
        }

        return msg.toString();
    }

`

Invalid keystore format! Make sure it is PKCS12...

Hi,
I need to use javaapns loop to push the message,The first message is a success。Later there will be a mistake。What should I do to avoid these?

look my code:

Test main

ApnsTest apnsTest = new ApnsTest(); List<String> devices = new ArrayList<String>(); devices.add("3b9fc52cf1df226e9aeb2ae90b6e94c4ef8144f0de2418ec170d5ee96ea3a3da"); for (int i = 0; i < 3; i++) { apnsTest.send(devices, keystore, password, true); }

ApnsTest

`public void send (List devices, Object keystore, String password, boolean production) {
PushNotificationPayload payload = PushNotificationPayload.complex();
try {
payload.addAlert("Hello World!");
payload.addSound("defult");
payload.addCustomDictionary("url", "http://www.baidu.com");
payload.addCustomDictionary("type", "Url"); // etc.
payload.addCustomDictionary("pushId",111); // etc.
payload.addCustomDictionary("forumkey","sadasds"); // etc.
List notifications = Push.payload(payload, keystore, password, production, devices);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
System.out.println("Push notification sent successfully to: " + notification.getDevice().getToken());
} else {
String invalidToken = notification.getDevice().getToken();

                        System.out.println("invalidToken :"+invalidToken);
                        ResponsePacket theErrorResponse = notification.getResponse();
                        if (theErrorResponse != null) {
                            System.out.println(theErrorResponse.getMessage());
                        }
                    }
            }


    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (CommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (KeystoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    }   `

error:
`Push notification sent successfully to: 3b9fc52cf1df226e9aeb2ae90b6e94c4ef8144f0de2418ec170d5ee96ea3a3da
javapns.communication.exceptions.InvalidKeystoreFormatException: Invalid keystore format! Make sure it is PKCS12...
at javapns.communication.KeystoreManager.wrapKeystoreException(KeystoreManager.java:172)
at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:66)
at javapns.communication.KeystoreManager.ensureReusableKeystore(KeystoreManager.java:87)
at javapns.communication.AppleServerBasicImpl.(AppleServerBasicImpl.java:37)
at javapns.notification.AppleNotificationServerBasicImpl.(AppleNotificationServerBasicImpl.java:57)
at javapns.notification.AppleNotificationServerBasicImpl.(AppleNotificationServerBasicImpl.java:42)
at javapns.notification.AppleNotificationServerBasicImpl.(AppleNotificationServerBasicImpl.java:28)
at javapns.Push.sendPayload(Push.java:170)
at javapns.Push.payload(Push.java:149)
at com.goyoo.test.ApnsTest.send(ApnsTest.java:71)
at com.goyoo.test.ApnsTest.main(ApnsTest.java:53)
javapns.communication.exceptions.InvalidKeystoreFormatException: Invalid keystore format! Make sure it is PKCS12...
at javapns.communication.KeystoreManager.wrapKeystoreException(KeystoreManager.java:172)
at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:66)
at javapns.communication.KeystoreManager.ensureReusableKeystore(KeystoreManager.java:87)
at javapns.communication.AppleServerBasicImpl.(AppleServerBasicImpl.java:37)
at javapns.notification.AppleNotificationServerBasicImpl.(AppleNotificationServerBasicImpl.java:57)
at javapns.notification.AppleNotificationServerBasicImpl.(AppleNotificationServerBasicImpl.java:42)
at javapns.notification.AppleNotificationServerBasicImpl.(AppleNotificationServerBasicImpl.java:28)
at javapns.Push.sendPayload(Push.java:170)
at javapns.Push.payload(Push.java:149)
at com.goyoo.test.ApnsTest.send(ApnsTest.java:71)

at com.goyoo.test.ApnsTest.main(ApnsTest.java:53)`

thank

InvalidKeystorePasswordException: Invalid keystore password! Verify settings for connecting to Apple...

Hi Fernando

I'm getting this issue while trying to use a PROD certificate.

javapns.communication.exceptions.InvalidKeystorePasswordException: Invalid keystore password!  Verify settings for connecting to Apple...
at javapns.communication.KeystoreManager.wrapKeystoreException(KeystoreManager.java:169) ~[javapns-jdk16-2.3.1.jar:?]
at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:66) ~[javapns-jdk16-2.3.1.jar:?]
at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:42) ~[javapns-jdk16-2.3.1.jar:?]
at javapns.communication.KeystoreManager.loadKeystore(KeystoreManager.java:29) ~[javapns-jdk16-2.3.1.jar:?]
at javapns.communication.ConnectionToAppleServer.<init>(ConnectionToAppleServer.java:52) ~[javapns-jdk16-2.3.1.jar:?]
at javapns.notification.ConnectionToNotificationServer.<init>(ConnectionToNotificationServer.java:16) ~[javapns-jdk16-2.3.1.jar:?]
at javapns.notification.PushNotificationManager.initializeConnection(PushNotificationManager.java:105) ~[javapns-jdk16-2.3.1.jar:?]
at javapns.Push.sendPayload(Push.java:171) ~[javapns-jdk16-2.3.1.jar:?]
at javapns.Push.payload(Push.java:149) ~[javapns-jdk16-2.3.1.jar:?]

This is a really weird because it is only happening in my PORD server, but if I try to use it locally it works

I'm using it like this:

PushNotificationPayload payload = new PushNotificationPayload();
payload.addAlert("Hello push!!");
payload.addSound("push.aiff");
payload.addBadge(1);
Push.payload(payload, "path/to/pfx/certificate", "password", true, deviceId);

Believe me "password" and "path/to/pfx/certificate", are correct both, locally and in prod, and I did a diff between the pfx certificates and they are identical.

As I could see in the code, this error is thrown here:

if (msg.contains("javax.crypto.BadPaddingException")) {
    return new InvalidKeystorePasswordException();
}

So, any idea of what could be going wrong??

Note: I'm pretty sure the password is the correct one, I could verify it also with openssl:

$ openssl pkcs12 -in path/to/pfx/certificate -nocerts -nokeys -passin pass:password
MAC verified OK

Thanks in advance
Gervasio

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.