Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache CXF Dynamic Client creation

Tags:

java

cxf

I am trying to use Apache CXF to talk to a unknown web service. I have followed the Dynamic Client example from Apache.

    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
    Client client = factory.createClient(wsdlURL.toExternalForm(), SERVICE_NAME);

This was working but now i am getting this exception when calling createClient():

    java.lang.IllegalStateException: Unable to create schema compiler
    Caused by:
     javax.xml.bind.JAXBException
     - with linked exception:
     [java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC]

This looks similar to an existing bug. I am using DOSGi singlebundle 1.2 which includes cxf-minimal-2.2.9.jar; meaning the bug should be fixed in the version I'm using. the jaxb-api is included in my Apache CXF distribution which upon inspection contains jaxb-xjc.

Can anybody provide me some insight as to what I'm doing wrong? I swear this used to work.

like image 651
mbumiller Avatar asked Oct 23 '12 21:10

mbumiller


People also ask

How do I create a CXF client?

Maven is used to integrate your generated Java CXF client code into an application development and deployment process. By setting up the pom. xml file, Maven can automatically generate the Java CXF client. Alternatively, you can directly use the WebClient APIs to develop a Java CXF client.

How CXF generate client from WSDL?

To create a client you used ClientProxyFactoryBean class from CXF library. In the WSDL-First approach, you used Endpoint class to publish the service at the desired URL and a specified implementor. You can now extend these techniques to integrate different protocols and transports.

What is CXF client?

CXF includes a Client interface which allows you to invoke operations and pass parameters for those operations. For instance: Client client = ....; Object[] result = client. invoke( "sayHi" , "Dan" );

What does wsdl2java generate?

wsdl2java takes a WSDL document and generates fully annotated Java code from which to implement a service. The WSDL document must have a valid portType element, but it does not need to contain a binding element or a service element.


2 Answers

"java.lang.ClassNotFoundException: com/sun/tools/ " is often occurs if you use JRE in your IDE intead of JDK. Make sure, you use JDK in IDE (e.g. eclipse)

like image 140
simbo Avatar answered Sep 18 '22 09:09

simbo


<dependency>
   <groupId>com.sun.xml.bind</groupId>
   <artifactId>jaxb-xjc</artifactId>
   <version>2.2.11</version>
</dependency>

resolved problem

like image 20
Abdullah Gürsu Avatar answered Sep 17 '22 09:09

Abdullah Gürsu