Apache CXF Clients : null result when using bad client factory
09/04/2009
Just a quick note to show that the client factory choice is important with Apache CXF 2.1.4.
The service interface definition :
package org.ow2.petals.usecase.soapaddressing.server; import javax.jws.WebMethod; import javax.jws.WebService; /** * @author chamerling - eBM WebSourcing * */ @WebService public interface AddressingService { /** * Get the local information * * @return */ @WebMethod String getInfo(); }
The client with the bad client factory :
package org.ow2.petals.usecase.soapaddressing.client; import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.ow2.petals.usecase.soapaddressing.server.AddressingService; /** * @author chamerling - eBM WebSourcing * */ public class BadFactory { /** * @param args */ public static void main(String[] args) { ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); factory.setServiceClass(AddressingService.class); factory.setAddress("http://localhost:8084/petals/services/Service01"); AddressingService client = (AddressingService) factory.create(); String info = client.getInfo(); System.out.println(info); } }
With that client code, the Web Service is really invoked, but the result of the getInfo operation is null. So, let’s do it with the right client factory…
The client with the good client factory :
package org.ow2.petals.usecase.soapaddressing.client; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.ow2.petals.usecase.soapaddressing.server.AddressingService; /** * @author chamerling - eBM WebSourcing * */ public class GoodFactory { /** * @param args */ public static void main(String[] args) { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(AddressingService.class); factory.setAddress("http://localhost:8084/petals/services/Service01"); AddressingService client = (AddressingService) factory.create(); String info = client.getInfo(); System.out.println(info); } }
This time the result is not null and is really the one expected…
Hi,
Greats that you mention it.
But using the ‘JaxWsProxyFactoryBean’ is also helpful for the WebParam definition.
If you use the ‘bad’ ClientWsProxyFactoryBean, your client will not recognize the name of your specified ‘WebParam’ name, it will use the default convention : arg0 (if there’s only one parameter)
example.
@WebService(name=”myClass”)
public interface myClass {
@WebMethod(operationName=”myMethod”)
public String myMethod(@WebParam(“myArg”) String myArg);
}
This will result in a triggering a Fault.