41 lines
1.4 KiB
Plaintext
41 lines
1.4 KiB
Plaintext
|
//import ch.nevis.esauth.util.httpclient.api.HttpClient;
|
||
|
//import ch.nevis.esauth.util.httpclient.api.HttpClients;
|
||
|
//import ch.nevis.esauth.util.httpclient.api.Http;
|
||
|
|
||
|
def url = parameters.get('url')
|
||
|
//def payload = parameters.get('json')
|
||
|
//def url = "https://me.agov-d.azure.adnovum.net:48081/utility/api/v1/email/031"
|
||
|
def email = inargs['email']
|
||
|
def language = session['ch.nevis.session.user.language'] ?: 'en'
|
||
|
def payload = '{ "email": "' + email + '", "language": "' + language + '"}'
|
||
|
|
||
|
try {
|
||
|
def httpClient = HttpClients.create(parameters)
|
||
|
def httpResponse = Http.post()
|
||
|
.url(url)
|
||
|
.header("Accept", "application/json")
|
||
|
.entity(Http.entity()
|
||
|
.content(payload)
|
||
|
.contentType("application/json")
|
||
|
// .charSet("utf-8")
|
||
|
.build())
|
||
|
.build()
|
||
|
.send(httpClient)
|
||
|
|
||
|
LOG.info('Response Message: ' + httpResponse.reasonPhrase())
|
||
|
LOG.info('Response Status Code: ' + httpResponse.code())
|
||
|
LOG.info('Response: ' + httpResponse.bodyAsString())
|
||
|
|
||
|
if (httpResponse.code() == 200) {
|
||
|
response.setResult('ok')
|
||
|
} else {
|
||
|
LOG.error('Unexcpected HTTP response code: ' + httpResponse.code())
|
||
|
response.setResult('error')
|
||
|
response.setError(1, 'Unexpected HTTP reponse')
|
||
|
}
|
||
|
} catch (all) {
|
||
|
// Handle exception and set the transition
|
||
|
LOG.error('error: ' + all, all)
|
||
|
response.setResult('error')
|
||
|
response.setError(1, 'Exception during HTTP call')
|
||
|
}
|