Apache CXF + JavaFX No conduit initiators found for namespace

I am trying to start a JavaFX Rest client using CXF. A very simple test. When I try to get the url I get org.apache.cxf.BusException: No channel initiators found for the namespace http://cxf.apache.org/transports/http . I've looked at some related questions here but no luck. Any help would be greatly appreciated. Then only the maven dependency I added was cxf-rt-rs-client 3.1.0 Code:

WebClient client = WebClient.create("http://www.stackoverflow.com"); client.type("text/html").accept("text/html"); System.out.println(client.get());

StackTrace:

Caused by: org.apache.cxf.BusException: No conduit initiator was found for the namespace http://cxf.apache.org/transports/http.
at org.apache.cxf.bus.managers.ConduitInitiatorManagerImpl.getConduitInitiator(ConduitInitiatorManagerImpl.java:110)
at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:104)
at org.apache.cxf.endpoint.UpfrontConduitSelector.selectConduit(UpfrontConduitSelector.java:77)
at org.apache.cxf.message.ExchangeImpl.getConduit(ExchangeImpl.java:159)
at org.apache.cxf.interceptor.MessageSenderInterceptor.getConduit(MessageSenderInterceptor.java:71)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:624)
at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1100)

      

+3


source to share


3 answers


Shading overwrites the bus-extension.txt file. You can programmatically fix this by initializing it.

void initializeCxf() {
    final Bus defaultBus = BusFactory.getDefaultBus();
    final ConduitInitiatorManager extension = defaultBus.getExtension(ConduitInitiatorManager.class);
    extension.registerConduitInitiator("http://cxf.apache.org/transports/http", new HTTPTransportFactory());
}

      



Based on @ hba comment you can also try the following if above doesn't work

extension.registerConduitInitiator("http://cxf.apache.org/transports/http", new HTTPTransportFactory(defaultBus));

      

+4


source


You are fine with your Maven dependencies.

The client design looks a bit in line with the CXF 3.x guides, which support JAX-RS 2.0.

See AX-RS 2.0 Client API .

Try this code:

    WebTarget target = ClientBuilder.newClient().target("http://stackoverflow.com/");

    Response response = target.request().get();
    System.out.println(response.getEntity().getClass().getName());

      

Using this code, you will know that the response object is an input stream. the character sequence is the HTML content on the StackOverflow home page.

If you are feeling adventurous and demonstrating that I am not a quack, add the following dependency to your POM:



<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-io</artifactId>
    <version>1.3.2</version>
</dependency> 

      

and then follow these steps:

    WebTarget target = ClientBuilder.newClient().target("http://stackoverflow.com/");
    System.out.println(IOUtils.toString((InputStream) target.request().get().getEntity(), "UTF-8"));

      

You will be rewarded with text rendering (on standard output) of the StackOverflow home page, which is equivalent to performing a view operation in your browser.

I don't know what your ultimate goal is, but if you are trying to build something useful from the StackExchange network information, I suggest using their APIs, documented here .

Good luck!

0


source


I have the same exception when using Apache CXF REST client in a JavaFX project. Code below:

MyClass rest = (MyClass) JAXRSClientFactory.create(endpoint, MyClass.class, Collections.singletonList(new JacksonJsonProvider()));
System.out.println("Service health: " + rest.health()); 

      

A test with a simple Java project works great with the same code and the same dependencies. This appears to be a conflict between JavaFX and Apache CXF. I'm trying to figure out why.

If you guys have already resolved this issue, it should be great to update this thread, which is the only Google search result.

Updated solution: After a while, I found that the default Maven project does not contain enough dependencies in the "maven-dependency-plugin" plugin. I tried adding more packages to the list but still doesn't work. So, the final solution in this thread is: How to package an Apache CXF application into a monolithic JAR using the Maven shadow plugin . The shadow plugin is much better and works.

0


source







All Articles