微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法在 Groovy 中使用 JKS Keystore 或 Truststore 为 HTTP 调用实现 SSL?

如何解决有没有办法在 Groovy 中使用 JKS Keystore 或 Truststore 为 HTTP 调用实现 SSL?

我编写了一个通过 Nifi 的 ExecuteGroovyScript 处理器运行的 groovy 脚本。它运行良好。但是,我想知道是否有办法使用 SSL 来实现这一点?

我的 unix 服务器上有 JKS Keystore 和 Truststore JKS 文件

下面是我写的代码

def flowFile = session.get()

def postResult=''
def url = new URL("https://xxx.xxx.xxx/sample?key=8B4B4565-313E-462D-8160-175F6F456773")
HttpURLConnection connection = (HttpURLConnection) url.openConnection()
connection.setRequestMethod("GET")
// connection.setConnectTimeout(10000)
connection.connect()
if (connection.responseCode == 200 || connection.responseCode == 201) {
    flowFile = session.putAttribute(flowFile,'api_responce_code',connection.responseCode.toString())
    flowFile = session.write(flowFile,{outputStream -> outputStream.write(connection.content.getBytes())} as OutputStreamCallback)
    session.transfer(flowFile,REL_SUCCESS)
} else {
    flowFile = session.putAttribute(flowFile,connection.responseCode.toString())
    flowFile = session.putAttribute(flowFile,'api_responce_error',connection.getErrorStream().toString())
    session.transfer(flowFile,REL_FAILURE)
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。