Reputation: 429
I am using resteasy client 3.0.6 and httpclient 4.5.2 and I got following warnings when performing a GET request:
Apr 19, 2018 12:40:18 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected [MY_COOKIE_IDENTITY="eyJhbGciOiJIUzI1NiIsImtpZCIgOiAiNzE5OTk3ZGQtNjVhZi00OTMwLTgwMjYtYWU3ZjIxZDYyYWI3In0.eyJqdGkiOiIyZjdh...", version:1, domain:psp208.fx.lan, path:/auth/210, expiry:null] Illegal 'path' attribute "/auth/210". Path of origin: "/auth/001"
Apr 19, 2018 12:40:18 PM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Cookie rejected [MY_COOKIE_SESSION="epos210/770a1a6f-1901-4985-8330-5aab4f9febe8/5f45c340-dfb6-466a-8f96-9d5a3cc51643", version:0, domain:psp208.fx.lan, path:/auth/210, expiry:Thu Apr 19 22:40:18 CEST 2018] Illegal 'path' attribute "/auth/210". Path of origin: "/auth/001"
but even if they are defined with an illegal path, I want to retrieve them programatically. Currently I am trying to use the following snippet:
ResteasyClient client = new ResteasyClientBuilder().connectionPoolSize(20).httpEngine(apacheHttpClient4Engine).build();
client.register(new ClientRequestFilter(){
@Override
public void filter(ClientRequestContext arg0) throws IOException {
cookies.putAll(arg0.getCookies());
}
});
but the filter is never invoked.
After looking HttpClient documentation I tried creating my own CookieSpecProvider:
Registry<CookieSpecProvider> r = RegistryBuilder.<CookieSpecProvider>create()
.register("easy", new CookieSpecProvider(){
@Override
public CookieSpec create(HttpContext arg0) {
return new BrowserCompatSpec(){
@Override
public void validate(org.apache.http.cookie.Cookie cookie, CookieOrigin origin)
throws MalformedCookieException {
// empty implementation
}
};
}
})
.build();
by using this implementation the ClientRequestFilter is invoked but it is returning an empty map of cookies.
My goal is to retrieve the two cookies I get from the response. How can I do it ?
thanks for any help
Upvotes: 2
Views: 1698
Reputation: 429
I solved by adding a cookie store
BasicCookieStore cookieStore = new BasicCookieStore();
CloseableHttpClient closableclient = HttpClients.custom()
.setDefaultRequestConfig(globalConfig)
.setDefaultCookieSpecRegistry(registry)
.setDefaultCookieStore(cookieStore)
.build();
In this way I can retrieve cookies without ClientRequestFilter.
Upvotes: 1