I have a Java client application that sends REST request to retrieve some data form a REST service.
I'm setting the client up like this:
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;
import org.glassfish.jersey.client.filter.EncodingFilter;
import org.glassfish.jersey.message.GZipEncoder;
SSLContext sslContext = SSLClientUtil.getSSLContext(getCertificate(keystore), keystorePassword);
this.client = ClientBuilder.newBuilder()
.sslContext(sslContext)
.hostnameVerifier(new TrustedHostnameVerifier())
.build();
client.register(GZipEncoder.class);
client.register(EncodingFilter.class);
this.webTarget = client.target("https://example.org:443/service/rest");
and in another method doing the actual request to the server
//Get Method
Response response = this.webTarget.request().get()
// Extract the content
response.close();
// return the content
When I run my application, the first time I run the Get-Method, the service returns the response and I get my response ... but after this first time. The request is not even sent to the server (I can see no network traffic on the eth interface of my client.
It seem like the client is somehow caching the response and is not sending the request again. I've seen that the server sends the response with the header Cache-Control: private. How can I convince my client to send the actual request once more (and if) do not use any cached response?
Note: I tried already in my client to set in the headers Cache-control directives ... but still the request is not sent with the method (this.webTarget.request().get()).
Update:
After some testing it seems to have something to do that the java client application is running as an javaws application. If started from debugger (without javaws) the behavior is as expected. Running it as javaws the request is cached.
This seems to be similar to the entry here where a javaws application is retrieving documents using URLConnection that are cached. There the connection can be set to not caching.
How can this be done for jakarta.ws.rs / jersey ?
