Skip to content

Commit

Permalink
Make the context propagation for HC5 mode elegant fix #954
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Mar 12, 2024
1 parent a9c0d5d commit fbd4496
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,8 @@ void customizers(
CXFRecorder recorder,
CxfFixedConfig config,
BuildProducer<RuntimeBusCustomizerBuildItem> customizers) {
final HTTPConduitImpl factory = HTTPConduitImpl.fromOptional(
config.httpConduitFactory(),
hc5Present(),
"quarkus.cxf.http-conduit-impl",
HTTPConduitImpl.QuarkusCXFDefault);
final HTTPConduitImpl factory = config.httpConduitFactory()
.orElse(hc5Present() ? HTTPConduitImpl.CXFDefault : HTTPConduitImpl.QuarkusCXFDefault);
switch (factory) {
case CXFDefault:
// nothing to do
Expand All @@ -507,7 +504,7 @@ void customizers(

static boolean hc5Present() {
try {
Class.forName("io.quarkiverse.cxf.transport.http.hc5.QuarkusAsyncHTTPConduitFactory");
Class.forName("io.quarkiverse.cxf.transport.http.hc5.QuarkusWorkQueueImpl");
return true;
} catch (ClassNotFoundException e) {
/* Fine, we can set the chosen ConduitFactory */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ public CXFClientInfo(CXFClientData other, CxfConfig cxfConfig, CxfClientConfig c
* In that case, the HTTPConduitFactory set on the Bus based on quarkus.cxf.http-conduit-impl
* should kick in.
*/
this.httpConduitImpl = HTTPConduitImpl.fromOptional(config.httpConduitFactory(), CXFRecorder.isHc5Present(),
"quarkus.cxf.client." + configKey + ".http-conduit-impl", null);
this.httpConduitImpl = config.httpConduitFactory().orElse(null);
this.configKey = configKey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,24 +488,6 @@ public enum HTTPConduitImpl {
HttpClientHTTPConduitFactory,
@ConfigDocEnumValue("URLConnectionHTTPConduitFactory")
URLConnectionHTTPConduitFactory;

public static HTTPConduitImpl fromOptional(Optional<HTTPConduitImpl> optional, boolean hc5Present, String key,
HTTPConduitImpl defaultValue) {
if (optional.isPresent() && optional.get() != HTTPConduitImpl.CXFDefault && hc5Present) {
/*
* This is bad: the user has to choose whether he wants URLConnectionHTTPConduitFactory or
* QuarkusAsyncHTTPConduitFactory
*/
throw new RuntimeException("You cannot use " + key + "=" + optional.get().name()
+ " and io.quarkiverse.cxf:quarkus-cxf-rt-transports-http-hc5 simultaneously." + " Either remove " + key
+ "=" + optional.get().name() + " from application.properties"
+ " or remove the io.quarkiverse.cxf:quarkus-cxf-rt-transports-http-hc5 dependency");
} else if (!optional.isPresent() && hc5Present) {
return HTTPConduitImpl.CXFDefault;
} else {
return optional.orElse(defaultValue);
}
}
}

public enum WellKnownHostnameVerifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public HTTPConduit createConduit(HTTPTransportFactory f, Bus b, EndpointInfo loc
if (httpConduitImpl == null) {
httpConduitImpl = cxFixedConfig.httpConduitFactory().orElse(null);
}
if (httpConduitImpl == HTTPConduitImpl.CXFDefault && hc5Present && busHTTPConduitFactory != null) {
if (httpConduitImpl == null && hc5Present && busHTTPConduitFactory != null) {
return configure(
busHTTPConduitFactory.createConduit(f, b, localInfo, target),
cxfClientInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduitFactory;
import org.apache.cxf.transport.http.asyncclient.hc5.AsyncHTTPConduit;
import org.apache.cxf.transport.http.asyncclient.hc5.AsyncHTTPConduitFactory;
import org.assertj.core.api.Assertions;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand All @@ -17,8 +19,6 @@
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkiverse.cxf.annotation.CXFClient;
import io.quarkiverse.cxf.transport.http.hc5.QuarkusAsyncHTTPConduit;
import io.quarkiverse.cxf.transport.http.hc5.QuarkusAsyncHTTPConduitFactory;
import io.quarkus.test.QuarkusUnitTest;

public class Hc5ConduitFactoryTest {
Expand All @@ -42,10 +42,10 @@ public class Hc5ConduitFactoryTest {
void conduitFactory() {
final Bus bus = BusFactory.getDefaultBus();
final HTTPConduitFactory factory = bus.getExtension(HTTPConduitFactory.class);
Assertions.assertThat(factory).isInstanceOf(QuarkusAsyncHTTPConduitFactory.class);
Assertions.assertThat(factory).isInstanceOf(AsyncHTTPConduitFactory.class);

final Client client = ClientProxy.getClient(helloService);
Assertions.assertThat(client.getConduit()).isInstanceOf(QuarkusAsyncHTTPConduit.class);
Assertions.assertThat(client.getConduit()).isInstanceOf(AsyncHTTPConduit.class);

/* ... and make sure that the alternative conduit works */
Assertions.assertThat(helloService.hello("Joe")).isEqualTo("Hello Joe");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.apache.cxf.Bus;
import org.apache.cxf.transport.http.HTTPConduitFactory;
import org.apache.cxf.transport.http.asyncclient.hc5.AsyncHttpResponseWrapperFactory;
import org.apache.cxf.workqueue.WorkQueueManager;
import org.eclipse.microprofile.context.ManagedExecutor;

Expand Down Expand Up @@ -31,7 +32,7 @@ public RuntimeValue<Consumer<Bus>> customizeBus() {
} else {
throw new IllegalStateException(ManagedExecutor.class.getName() + " not available in Arc");
}
bus.setExtension(new QuarkusAsyncHTTPConduitFactory(bus), HTTPConduitFactory.class);
bus.setExtension(new QuarkusAsyncHttpResponseWrapperFactory(), AsyncHttpResponseWrapperFactory.class);
});
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit fbd4496

Please sign in to comment.