Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public class WebTargetImpl implements WebTarget {
private Configurable<WebTarget> configImpl;
private UriBuilder uriBuilder;
private WebClient targetClient;
private boolean threadSafeTargetClient;


public WebTargetImpl(UriBuilder uriBuilder,
Expand Down Expand Up @@ -310,7 +311,7 @@ public Builder request() {
cxfFeature.initialize(clientCfg, clientCfg.getBus());
}
// Start building the invocation
return new InvocationBuilderImpl(WebClient.fromClient(targetClient),
return new InvocationBuilderImpl(threadSafeTargetClient ? targetClient : WebClient.fromClient(targetClient),
getConfiguration());
}
private void setConnectionProperties(Map<String, Object> configProps, ClientConfiguration clientCfg) {
Expand Down Expand Up @@ -361,6 +362,7 @@ private void initTargetClientIfNeeded(Map<String, Object> configProps) {
}
}
targetClient = bean.createWebClient();
threadSafeTargetClient = threadSafe;
ClientImpl.this.baseClients.add(targetClient);
} else if (!targetClient.getCurrentURI().equals(uri)) {
targetClient.to(uri.toString(), false);
Expand Down Expand Up @@ -470,7 +472,7 @@ public WebTarget resolveTemplatesFromEncoded(Map<String, Object> templatesMap) {
private WebTarget newWebTarget(UriBuilder newBuilder) {
WebClient newClient;
if (targetClient != null) {
newClient = WebClient.fromClient(targetClient);
newClient = threadSafeTargetClient ? targetClient : WebClient.fromClient(targetClient);
} else {
newClient = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.ClientProperties;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
Expand Down Expand Up @@ -77,6 +80,18 @@ public void testSimpleWebClient() throws Exception {
runWebClients(client, 10, true, false);
}

@Test
public void testWebTargetGC() throws Exception {
WebTarget target = ClientBuilder.newClient().target("http://localhost:" + PORT + "/bookstore/booksecho")
.property(ClientProperties.THREAD_SAFE_CLIENT_PROP, true);

target.request().get().getStatus();

System.gc();

target.request().get().getStatus();
}

@Test
public void testSimpleProxy() throws Exception {
BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
Expand Down