Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

To use CXF 3.x as your restful interface, use the following dependency.


To use CXF 3.x as your rest client, use the following dependency.


January 13th, 2016

Posted In: CXF, Java, java ninja, Javaninja, json

Tags: , , , ,

Leave a Comment

Creating a SOAP client for a SOAP web service is very straight forward when using CXF. Given a WSDL url or a WSDL file, create a project with a pom.xml containing the following:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""




When you run mvn compile, it will generate classes in the generated-sources/cxf directory.

The next step is to use the service client. The normal usage pattern is below. The service is instantiated, then the port is retrieved.


import org.junit.Test;

import javax.xml.datatype.XMLGregorianCalendar;
import java.util.List;

import static org.junit.Assert.assertNotNull;

 * @author norris.shelton
public class TestRightNowSyncService {

    public void testName() throws Exception {
        RightNowSyncService rightNowSyncService = new RightNowSyncService();
        RightNowSyncPort rightNowSyncPort = rightNowSyncService.getRightNowSyncPort();

        XMLGregorianCalendar metaDataLastChangeTime = rightNowSyncPort.getMetaDataLastChangeTime();

        List<MetaDataClass> metaDataClasses = rightNowSyncPort.getMetaData();


April 1st, 2015

Posted In: CXF, Java, java ninja, Javaninja, Maven, SOAP

Tags: , , , , ,


UPDATE: THANKS to attel in the comments below, THIS NOW WORKS. I was using the response context object, when I should have been using the request context.

I have a case where the test system is going to be different than the production system. I started with the following in my Springframework config file:

     Define a cxf endpoint based on client stub generated from a wsdl. It
     is important to provide serviceName and endpointName so the wsdl is
     not needed at runtime. As far as I know the serviceName and
     endpointName do not have to have a special convention but it is good
     practice to use the service namespace and Service Interface name in
     the names
<jaxws:client id="justiceXchangeService"
              serviceName="namespace:service name"
              endpointName="namespace:endpoint name"
              address="my test service address"
        <!--all validation is turned off-->
        <entry key="set-jaxb-validation-event-handler" value="false"/>

This would allow me to inject the client by:

    private ServiceClass serviceClass;

This worked until I had to dynamically specify the service address. I found some documentation that said I should do it like:

        BindingProvider bindingProvider = (BindingProvider) serviceClass;
                       .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "different service address");

UPDATE: THANKS to attel in the comments below, THIS NOW WORKS. I was using the response context object, when I should have been using the request context.

Unfortunately when I checked my logs, I saw that the address in the original request was still the address declared in the spring config file. Changing the binding didn’t work.

I finally ran across using a proxy. Now my spring context looks like:

This caused some changes in my code. The client is now injected via:

    private JaxWsProxyFactoryBean jaxWsProxyFactoryBean;

The dynamic service is address is specifyied and the proxy used by:

        ServiceClass serviceClass = (serviceClass) jaxWsProxyFactoryBean.create();

August 15th, 2012

Posted In: CXF, Java, JAXB, SOAP, Spring

Tags: , , , , ,


WP to LinkedIn Auto Publish Powered By :