So, I've found a thread where someone is doing the same:
http://www.nabble.com/Client-from-ClientFactoryBean-as-a-generic-soap-client--td17700799.html
However, when I try the same it seems to fail because of no service class in
the endpoint:
NullPointerException:
at
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.checkServiceClassAnnotations(ReflectionServiceFactoryBean.java:2156)
at
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.setServiceClass(ReflectionServiceFactoryBean.java:2153)
at
org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.initializeServiceFactory(AbstractWSDLBasedEndpointFactory.java:227)
at
org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:99)
at
org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:52)
My code is trying to invoke a method (by name method), with one String
argument (message), and it allows for a String to be returned. Note, I don't
have the WSDL, I am assuming the method exists as described!
ClientFactoryBean cfb = new ClientFactoryBean();
cfb.setAddress(endPoint);
if (username != null)
{
AuthorizationPolicy authPolicy = new AuthorizationPolicy();
authPolicy.setUserName(username);
authPolicy.setPassword(password);
Map<String,Object> props = new HashMap<String,Object>();
props.put(AuthorizationPolicy.class.getName(), authPolicy);
cfb.setProperties(props);
}
Client client = cfb.create();
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
String ret = null;
logger.debug("Invoking call ... ");
Object[] v = client.invoke(new QName(method), new Object[] {
message } );
if (v != null && v.length>0)
ret = v[0].toString();
Thoughts most welcome!