sarbogast / grails-apns

Grails Apple Push Notification Service integration
http://grails.org/plugin/apns
GNU General Public License v3.0
7 stars 11 forks source link

Certificate not found #1

Open dlorch opened 12 years ago

dlorch commented 12 years ago

Error

    Ambiguous method overloading for method com.notnoop.apns.ApnsServiceBuilder#withCert. Cannot resolve which method to invoke for [null, class java.lang.String] due to overlapping prototypes between: [class java.io.InputStream, class java.lang.String] [class java.lang.String, class java.lang.String]

    Around line 24 of ApnsFactoryBean.groovy
    21:    Object getObject() {
    22:        def apnsService = APNS.newService()
    23:        if(certificateResourcePath){
    24:            apnsService = apnsService.withCert(this.getClass().getResourceAsStream(certificateResourcePath), password)
    25:        } else if(pathToCertificate){
    26:            apnsService = apnsService.withCert(pathToCertificate, password)
    27:        } else {

Solution

Adding getClassLoader() to the following line in org/epseelon/grails/apns/ApnsFactoryBean.groovy solved the problem for me:

    if(certificateResourcePath){
        apnsService = apnsService.withCert(this.getClass().getClassLoader().getResourceAsStream(certificateResourcePath), password)
    } else if(pathToCertificate){
    ...

My Configuration

File apns-dev.p12 in src/java, the following lines in Config

 environments {
     development {
         apns {
                         certificateResourcePath = "apns-dev.p12"
                         password = "secret"
             environment = "sandbox"
         }
     }
     test {
         apns {
                         pathToCertificate = "apns-dev.p12"
                         password = "secret"
             environment = "sandbox"
         }
     }

     production {
         apns {
                         pathToCertificate = "apns-dev.p12"
                         password = "secret"
             environment = "production"
         }
     }
 }

My Setup

$ grails --version Grails version: 2.0.4

$ java -version java version "1.6.0_29" Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-10M3527) Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

robinpercy commented 11 years ago

Another workaround for this is just to preface your paths with a /. Eg, pathToCertificate = "/apns-dev.p12"