Results 1 to 5 of 5

Thread: Support for using RestTemplate with https and cookies

  1. #1
    Join Date
    May 2012
    Posts
    2

    Default Support for using RestTemplate with https and cookies

    Hello!

    I got an impression that 1.0.0.RC1 should add the support through access to HttpContext as mentioned in Android-58 (https://jira.springsource.org/browse/ANDROID-58), however this seems not to be the case as I could not find createHttpContext method from HttpComponentsClientHttpRequestFactory.

    Any updates when the support will be added?

    Thanks!

  2. #2
    Join Date
    May 2012
    Posts
    10

    Default

    Hi,

    I think it is fully ported. However, createHttpContext is protected, both in spring-framework and spring-android.

    For more information how you can use it in Spring, check here:

    http://www.baeldung.com/2012/04/16/h...in-spring-3-1/

    Hope this helps.

    Cheers

  3. #3
    Join Date
    Nov 2010
    Posts
    175

    Default

    For clarity, that link discusses making HTTP Basic Auth requests in RestTemplate, and Spring for Android now has support for Basic Auth included.
    Roy Clarkson
    Spring Mobile Projects Lead

  4. #4
    Join Date
    May 2012
    Posts
    2

    Default

    I'm sorry, I'm not sure what you mean Roy.

    In the referred page it says like this:
    "Now, this HttpContext needs to be hooked up to the RestTemplate, so that requests created via the template can benefit from the Basic Authentication support. As mentioned before, this is not an easy as it should be – the entire HttpComponentsClientHttpRequestFactory needs to be subclassed and the createHttpContext method overridden:"

    To me this looks like a workaround solution so are there plans to make accessing HttpContext easier so that cookie can be easily set?

    Maybe in a similar fashion as here (you can pass context as a parameter to execute -method):
    http://hc.apache.org/httpcomponents-...ttpClient.html

    Thanks!

  5. #5
    Join Date
    Nov 2010
    Posts
    175

    Default

    In this case it is not a workaround. There are two schools of thought going on here, which may help clarify things. RestTemplate, as with many components in Spring Framework, is designed around a templating concept. If you need more functionality than the "basic" template classes provide, then you should subclass and override/implement the functionality you need in that subclass. In this specific case, createHttpContext(...) is one of those template methods, which has no use outside of subclassing.

    The alternative school of thought, would be to implement and expose all the functionality we can in the Spring classes. This would be beneficial in this case, because you would not need to subclass. The potential downside is that those who want to subclass are then left with "baggage" from the template class in the form of functionality they don't need, or worse conflicts.

    The main thing to keep in mind is that RestTemplate is a REST framework. REST by definition is supposed to be stateless. This is contradictory to the use of HttpContext, which is probably one reason it was exposed as a subclass hook, and not a public setter method. From the HttpContext javadoc:

    The primary purpose of the HTTP context is to facilitate information sharing among various logically related components. HTTP context can be used to store a processing state for one message or several consecutive messages. Multiple logically related messages can participate in a logical session if the same context is reused between consecutive messages.
    Roy Clarkson
    Spring Mobile Projects Lead

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •