I want to invoke authenticated URL on server which is SSO authenticated. For this, I am coping cookies which are there in request to HTTPClient. Below code works fine.
def cookies = []
request.getCookies().each {
def cookie = new BasicClientCookie(it.name, it.value)
cookie['domain'] = it.domain
cookie['path'] = it.path
cookie.secure = true
cookies.add(cookie)
}
// **** Setting cookies using header *****
def output = withHttp(uri: "https://testserver.com") {
def builder = delegate;
def html = get(path : '/testactoin.do',
headers:['Cookie':cookies.collect{it.name+"="+it.value}.join("; ")],
contentType : ContentType.XML,
query :
[
query: params.query,
count: params.count,
cacheName: 'contentStoreCityState',
filterString: 'address.country=CA,GB,US'
]
)
return html
}
However, if I try to set cookies using api it does not work. See code snippet below:
def cookies = []
request.getCookies().each {
def cookie = new BasicClientCookie(it.name, it.value)
cookie['domain'] = it.domain
cookie['path'] = it.path
cookie.secure = true
cookies.add(cookie)
}
def output = withHttp(uri: "https://testserver.com") {
def builder = delegate;
// **** Setting cookies using api call *****
cookies.each {
builder.client.cookieStore.addCookie(it)
}
def html = get(path : '/testactoin.do',
contentType : ContentType.XML,
query :
[
query: params.query,
count: params.count,
cacheName: 'contentStoreCityState',
filterString: 'address.country=CA,GB,US'
]
)
return html
}
What is issue in setting cookies using addCookie method? Neither it generate any exception nor any warning message.