You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Daniel Lipofsky <Da...@bricsnet.com> on 2008/05/07 22:52:39 UTC

dynamic client code

We have the same method on many different services,
I am trying to find a nice generic way to invoke it

This works but is not what I really want because I still
have to import the PersonPortType:

    String portClassName = JAXWS_PACKAGE + serviceName + "PortType";
    Class<?> portClass = Class.forName(portClassName);
    ClientProxyFactoryBean factory = new ClientProxyFactoryBean(new
JaxWsClientFactoryBean());
    factory.setAddress("http://localhost/ws/services/" + serviceName);
    factory.setServiceClass(portClass);
    PersonPortType port = (PersonPortType) factory.create();

    Client client = factory.getClientFactoryBean().getClient();
    HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
    AuthorizationPolicy authorization = new AuthorizationPolicy();
    authorization.setUserName("...");
    authorization.setPassword("...");
    httpConduit.setAuthorization(authorization);

    byte[] ba = port.getObjects(new ArrayList<SearchTerm>(0), 0, 1);

this is more like what I want but it fails
(pretty much the same except for the last line):

    String portClassName = JAXWS_PACKAGE + serviceName + "PortType";
    Class<?> portClass = Class.forName(portClassName);
    ClientProxyFactoryBean factory = new ClientProxyFactoryBean(new
JaxWsClientFactoryBean());
    factory.setAddress("http://localhost/ws/services/" + serviceName);
    factory.setServiceClass(portClass);
    factory.create();

    Client client = factory.getClientFactoryBean().getClient();
    HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
    AuthorizationPolicy authorization = new AuthorizationPolicy();
    authorization.setUserName("...");
    authorization.setPassword("...");
    httpConduit.setAuthorization(authorization);

    Object[] results = client.invoke("getObjects", new
ArrayList<SearchTerm>(0), 0, 1);

I get

Exception in thread "main"
org.apache.cxf.common.i18n.UncheckedException: No operation was found
with the name {http://www.bricsnet.com/Person}getObjects.
    at
org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:212)
    at
org.apache.cxf.endpoint.ClientImpl.invokeWrapped(ClientImpl.java:206)
    at WSClientFactory.download2(WSClientFactory.java:173)
    at WSClientFactory.main(WSClientFactory.java:44)

I also tried invokeWrapped but it failed too.
Can anyone tell me the proper way to do this?

Thanks,
Dan