Grails 中的 SSL 验证错误
我想在 Grails 中发布带有 SSL 验证的 url。 我已导入证书,并生成了 jks 文件。 但 Grails 似乎没有找到那些 jks 文件。 下面是我正在执行的代码(它位于 Grails 服务类中):
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))
错误是 “无法在空对象上调用 withInputStream() 方法” 所以 getResource() 方法不起作用,并返回 null。
我看到这段代码在功能测试类中运行良好。
有人知道我该如何解决这个问题吗?
谢谢!!!!!!!
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!!!!!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是来自
grails-app/services
的非源文件不会复制到类路径中。src/java
是这种情况,但src/groovy
不是这种情况。 grails-app/conf 也是如此,但这是唯一发生这种情况的 grails-app 文件夹,因为它是配置文件文件夹。因此,最好的选择是将文件移动到 grails-app/conf 并使用
The problem is that non-source files from
grails-app/services
aren't copied into the classpath. This is the case forsrc/java
though, but notsrc/groovy
. It's also the case forgrails-app/conf
, but that's the onlygrails-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