Skip to end of metadata
Go to start of metadata


To consume SOAP web service in java. We had a use case to consume SOAP services developed in ABAP in Java for our UI applications. To generate Java clients from WSDL, Apache CXF is used.


  1. Download Eclipse IDE for JEE developers.( )
  2. Download Apache CXF.( (Binary distribution .ZIP file))
  3.  Download Apache Tomcat. ( )
  4.  Download and install JDK.(
  5. Configure Installed JDK in Eclipse.
    To configure installed JDK in eclipse, go to Windows->Preferences->Java->Installed JRE, Click  'Add' button, choose 'Standard VM' in Add JRE window and click next. In the next screen, select the path where JDK was installed using 'Directory' button

  6. The Apache Tomcat server, which will host the web service, needs to be configured in the Eclipse IDE.
    To configure tomcat in eclipse, select Windows->Preferences->Server->Runtime Environments. Click 'Add' button, choose relevant Apache Tomcat server and select the Tomcat installation directory and select finish.

  7. The Eclipse IDE needs to be configured to use the Apache CXF web service framework for creating and communicating with web services.

     To configure Apache CXF,Select  Window –>Preferences –>Web Services –>CXF 2.x Preferences. Under “CXF Runtime” select “Add” and select the CXF installation directory and click finish.

  8. Finally, select “Server and Runtime” under “Web Services” and set the Server Runtime to Tomcat 7.0 and the Web Service Runtime as Apache CXF 2.x.

Steps to create Java client from WSDL

  1. Download the WSDL file from service provider.
  2. Create dynamic web project in eclipse by selecting File->New->Dynamic Web project.

    In the wizard, select Target runtime as 'Apache Tomcat 7.0', Dynamic web module version as '3.0' and Configuration as 'Default Configuration for Apache Tomcat v7.0'. Click next button, again click next and in web module window check option 'Generate web.xml deployment descriptor' and click finish.

  3. Copy downloaded WSDL file to web-inf  folder under Web Content folder. Right click on wsdl file, choose web service-> Generate Client option

  4. In the Web service client wizard select client type as 'Java Proxy' and make sure under configurations for Server runtime  'Tomcat v7.0 server' is selected and for Web service runtime 'Apache CXF 2.X' is selected. Move the slider bar to 'Develop client'. Click next button and in next window, make sure there is no '-' (hypen in the package name (as '-' is not supported in java namespace) and click finish.

  5. Check java classes got generated in Java Resources->src->(package_name) under the dynamic web project.

    If you are using JDK1.8.0 and while generating java client if you face the following exception, "org.xml.sax.SAXParseException; schema_reference: Failed to read schema document 'xml.xsd', because 'file' access is not allowed due to restriction set by the accessExternalSchema property".

    Create a file named (if it doesn't exist) under /path/to/jdk1.8.0/jre/lib and then write this line in it:

    javax.xml.accessExternalSchema = all 

  6. In the generated client java class, add the following code in main() method at the beginning.

    org.apache.cxf.jaxws.JaxWsProxyFactoryBean factory = new org.apache.cxf.jaxws.JaxWsProxyFactoryBean();

    factory.getInInterceptors().add(new LoggingInInterceptor());

    factory.getOutInterceptors().add(new LoggingOutInterceptor());

     // Utilize the class which was auto-generated by Apache CXF wsdl2java for service interface


    // Use the endpoint URL for your web service





    org.apache.cxf.endpoint.Client client = org.apache.cxf.frontend.ClientProxy.getClient(obj);

    org.apache.cxf.transport.http.HTTPConduit httpConduit = (org.apache.cxf.transport.http.HTTPConduit) client.getConduit(); authorization = httpConduit.getAuthorization();



    long timeout = 10000L;

    org.apache.cxf.transports.http.configuration.HTTPClientPolicy policy = new org.apache.cxf.transports.http.configuration.HTTPClientPolicy();





  7. Do the mapping to send the request to web service and call the method by



  8. Run the client class as java application.

    If the server certificate is not installed in your system, you would get following exception PKIX path building failed:
    .certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

     In that case do the following

    Get a file from


     Run, with your hostname and https port, and press “1” when ask for input in command prompt. It will add your hostname as a trusted keystore, and generate a file named “jssecacerts“.

     This application was originally written for Java 5 / Java 6. While this solution still works, when you try to run this application through Java 7 or above, you will get an additional error message like this: java.lang.UnsupportedOperationException.

    To avoid this error, you will need to change how accepted issuers are returned in your java class "". The original code threw an exception for this method. The Java 7 implementation calls this method, which was not the case with earlier versions of Java. The solution to this problem is to simply return an empty array like this:


    public X509Certificate[] getAcceptedIssuers() {

        return new X509Certificate[0];

        // throw new UnsupportedOperationException();


     Copy the generated “jssecacerts” file to your “$JAVA_HOME\jre\lib\security” folder.


    Run your web service client again, it should be working now.

  • No labels


  1. Very helpful article Ashok!

  2. Great article! Simple to understand and do hands on!