我对HTTPBuilder的使用有疑问。使用下面的代码段使用JIRA API创建问题时,我收到以下错误:
托管API的服务器使用 TLSv1.2 ,这似乎是我的问题。
收到致命警报:handshake_failure
以下是我的一些成本/限制:
我知道升级Java版本有帮助。但是,我特别想了解 如何更改/重写HTTPBuilder 将帮助我解决此问题。
def http = new HTTPBuilder("https://jira.xxxxxxx.com/rest/api/2/issue")
if(projectKey=='Type1')
{
http.request(POST, JSON) { req ->
headers.'Authorization' = 'Basic xxxxxxxxxxxxxxxxxxxxxxxxxx'
headers.'Content-Type' = 'application/json'
body = [
fields: [
project : [
key: projectKey
],
issuetype : [
name: issueType
],
reporter : [
name: reporter
],
assignee : [
name: assignee
],
customfield_1 : [
value:'Some value1'
],
customfield_2 : [
value:'Some value2'
],
summary : summary,
description: description,
labels : labels
]
]
response.success = { resp, json ->
return json.key
}
任何帮助将不胜感激!!
答案 0 :(得分:0)
你试过这个:
用法:
TlsHttpBuilder tlsHttpBuilder = new TlsHttpBuilder(['TLSv1', 'TLSv1.1','TLSv1.2'])
class TlsHttpBuilder extends HTTPBuilder {
List sslProtocols
TlsHttpBuilder(List sslProtocols) {
super()
this.sslProtocols = sslProtocols
}
protected HttpClient createClient(HttpParams params) {
def sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, null, new SecureRandom())
def sf = new org.apache.http.conn.ssl.SSLSocketFactory(sslContext) {
protected void prepareSocket(final SSLSocket socket) throws IOException {
if (sslProtocols) {
log.debug("Setting protocols: ${sslProtocols}")
socket.setEnabledProtocols(sslProtocols as String[])
}
}
}
def schemeRegistry = SchemeRegistryFactory.createDefault()
schemeRegistry.register(new org.apache.http.conn.scheme.Scheme("https", sf, 443))
new DefaultHttpClient(new PoolingClientConnectionManager(schemeRegistry), params)
}
}
参考: https://gist.github.com/ptaylor/fb5a3abce5c455fbec87f6bfd6386814