开发者

Errors with SSL validation in Grails

I want to make a post to an url with SSL validation in Grails. I've imported the certificates, and I've generated the jks files. But it seems Grails does not found those jks files. Below is the code I'm executing (it's in a Grails Service Class):

def certificate = "mycert.jks"

def http = new HTTPBuilder(url)

def keyStore = KeyStore.getInstance(KeyStore.defaultType)
getClass().getResource(certificate).withInputStream {
    keyStore.load(it, "test1234".toCharArray())
}

http.client.connectionManager.schemeRegistry.register(new Scheme("https", new SSLSocketFactory(keyStore), 443))

The error is "Cannot invoke method withInputStream() on开发者_开发技巧 null object" so the method getResource() is not working, and returns null.

I saw that this code, in a functionalTest Class, works fine.

Anyone knows how can I solve this problem?

Thanks!!!!!!!


The problem is that non-source files from grails-app/services aren't copied into the classpath. This is the case for src/java though, but not src/groovy. It's also the case for grails-app/conf, but that's the only grails-app folder that this happens for, since it's the configuration file folder.

So your best bet is to move the file to grails-app/conf and use

Thread.currentThread().contextClassLoader.getResource(certificate).withInputStream {
    keyStore.load(it, "test1234".toCharArray())
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜