I am trying to call a Restful JSON service using RestTemplate and Jackson json convertor. Now in order to call the service I need to pass in a Security cookie. I can achiev
You can access the underlying HttpURLConnection
used by RestTemplate
by wiring your RestTemplate
up with a custom ClientHttpRequestFactory, which lets you access the underlying connection to set headers, properties, etc. The ClientHttpRequestFactory
is used by RestTemplate
when creating new connections.
In particular, you can extend the SimpleClientHttpRequestFactory implementation and override the prepareConnection()
method:
public class YourClientHttpRequestFactory extends SimpleClientHttpRequestFactory {
@Override
protected void prepareConnection(HttpURLConnection connection, String httpMethod) {
connection.setRequestProperty("SecurityCookie", ssocookie.getValue());
}
}