0

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.

Jaydeep Patel
  • 2,394
  • 1
  • 21
  • 27
  • http://blog.swwomm.com/2011/01/groovy-httpbuilder-cookies.html – moskiteau Jul 05 '12 at 14:59
  • @stesteau this link does not answer the question. I looked at this link while writing the code but it don't have any reference what to do in case of issue mentioned above. – Jaydeep Patel Jul 05 '12 at 15:45

1 Answers1

0

In your first code snippet you are setting Cookie, but the header is actually Set-Cookie.

TarekZ
  • 19
  • 3