Spring Framework
  1. Spring Framework
  2. SPR-7498

ResponseEntity headers do not show cookie

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 3.0.2
    • Fix Version/s: None
    • Component/s: Test
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      I am using RestTemplate to test my API. Headers from ResponseEntity seems to show only 'Set-Cookie' but for further requests it does not pull up the cookie in the header. Any particular reason why? I verified that response from the server do contain header cookie.

      ResponseEntity<String> response = restTemplate.exchange(uri.toString(), HttpMethod.PUT, requestEntity, String.class, new HashMap<String,String>());
      			
      HttpHeaders headers = response.getHeaders();
      Set<String> keys = headers.keySet();
      for (String header : keys) 
      {
      	System.out.println("Header: "+header);
      	List<String> values = headers.get(header);
      	for (String value : values) 
      	{
      		System.out.println("Header Value: "+ value);
      	}
      }
      

      Output showing 'Set-Cookie'

      Header: Server
      Header Value: Apache-Coyote/1.1
      Header: X-Powered-By
      Header Value: 
      Header: Set-Cookie
      Header Value: JSESSIONID=0B66BF319B5D6E236A5F9679F72459F5.dev37; Path=/; Secure
      Header: Content-Type
      Header Value: application/xml;charset=ISO-8859-1
      Header: Content-Language
      Header Value: en-US
      Header: Content-Length
      Header Value: 130
      Header: Date
      Header Value: Wed, 25 Aug 2010 22:55:16 GMT
      

      Output not showing Cookie in the header:

      Header: Server
      Header Value: Apache-Coyote/1.1
      Header: X-Powered-By
      Header Value: 
      Header: Content-Type
      Header Value: application/xml;charset=ISO-8859-1
      Header: Content-Language
      Header Value: en-US
      Header: Content-Length
      Header Value: 655
      Header: Date
      Header Value: Wed, 25 Aug 2010 23:00:19 GMT 
      

        Activity

        Hide
        praveenkumar kg added a comment -

        How does this system work? Do I need votes to get this fixed?

        Show
        praveenkumar kg added a comment - How does this system work? Do I need votes to get this fixed?
        Hide
        Arjen Poutsma added a comment -

        Added formatting

        Show
        Arjen Poutsma added a comment - Added formatting
        Hide
        Arjen Poutsma added a comment -

        RestTemplate does not have support for Cookies, or at least, there is no support for cookies in the RestTemplate code base. This is intentional: the RestTemplate is designed for programmatic HTTP access, not
        as a web browser substitute.

        You might be able to make cookies work by using the CommonsClientHttpRequestFactory rather than the default SimpleClientHttpRequestFactory as a RestTemplate constructor argument. See http://hc.apache.org/httpclient-3.x/cookies.html for more info.

        Show
        Arjen Poutsma added a comment - RestTemplate does not have support for Cookies, or at least, there is no support for cookies in the RestTemplate code base. This is intentional: the RestTemplate is designed for programmatic HTTP access, not as a web browser substitute. You might be able to make cookies work by using the CommonsClientHttpRequestFactory rather than the default SimpleClientHttpRequestFactory as a RestTemplate constructor argument. See http://hc.apache.org/httpclient-3.x/cookies.html for more info.

          People

          • Assignee:
            Arjen Poutsma
            Reporter:
            praveenkumar kg
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 33 weeks ago