我正在尝试使用Groovy创建一个使用SSL的HttpServer,但我无法使其工作,我找不到一个好的代码示例或有关它的文档。
这是我到目前为止所做的代码库
Map options = new HashMap()
options.put("tcpKeepAlive",true)
options.put("verifyHost", true)
options.put("trustAll", false)
options.put("keyCertOptions", new JksOptions().setPath("keystore.jks").setPassword("CosPassword123"))
options.put("ssl", true)
vertx.createHttpServer(options).requestHandler(router.&accept).listen(9000, { response ->
if (response.succeeded()) {
startFuture.complete()
} else {
startFuture.fail(response.cause())
}
})
当我运行它时,我收到异常
io.vertx.core.VertxException: io.vertx.core.VertxException: Key/certificate is mandatory for SSL
at io.vertx.core.net.impl.SSLHelper.createContext(SSLHelper.java:303)
at io.vertx.core.net.impl.SSLHelper.getContext(SSLHelper.java:458)
at io.vertx.core.net.impl.SSLHelper.validate(SSLHelper.java:472)
at io.vertx.core.http.impl.HttpServerImpl.listen(HttpServerImpl.java:219)
at io.vertx.core.http.impl.HttpServerImpl.listen(HttpServerImpl.java:191)
at io.vertx.groovy.core.http.HttpServer.listen(HttpServer.groovy:178)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrap.invoke(PogoMetaMethodSite.java:190)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at com.tesco.price.mocks.identity.IdentityMock.startServer(IdentityMock.groovy:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
at com.tesco.price.mocks.identity.IdentityMock.start(IdentityMock.groovy:29)
at io.vertx.lang.groovy.GroovyVerticle$1.start(GroovyVerticle.groovy:93)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:434)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:359)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:339)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:393)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:0)
“keyCertOptions”是一个Java密钥。 在Groovy中,您应该使用“keyStoreOptions”:
def options = [
ssl:true,
keyStoreOptions:[
path:"keystore.jks",
password:"CosPassword123"
]
]
vertx.createHttpServer(options).requestHandler(router.&accept).listen(9000, { response ->
if (response.succeeded()) {
//startFuture.complete()
} else {
//startFuture.fail(response.cause())
}
})
请参阅此内容以获取更多信息: http://vertx.io/docs/vertx-core/groovy/#ssl