Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

spring boot - restTemplate BufferingClientHttpRequestFactory breaking cookies

I am calling another service using spring boot. When I have my configuration as follows, it does not add the jsessionid(cookie) returned from the service i am calling.

public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
    RestTemplate rt = restTemplateBuilder
        .rootUri(uri)
        .basicAuthentication(
                 username
                ,password)
        .additionalInterceptors(new RestTemplateInterceptor(stuff, stuff))
        .build();
    rt.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));

    return rt;          
}

when I call with this configuraiton it does add the jsessionid(cookie) from the service I call.

public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
    RestTemplate rt = restTemplateBuilder
        .rootUri(uri)
        .basicAuthentication(
                 username
                ,password)
        .build();
    
    return rt;          
}

My question is how can I get the BuffereingClientHttpRequestFactory to add the jsessionid(cookie) form previous calls to the service?

Thanks in advance


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

this seems to have solved my problem (look at HttpComponentsClientHttpRequestFactory)

public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
RestTemplate rt = restTemplateBuilder
    .rootUri(uri)
    .basicAuthentication(
             username
            ,password)
    .additionalInterceptors(new RestTemplateInterceptor(stuff, stuff))
    .build();
rt.setRequestFactory(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()));

return rt;          

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...