cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Meeraj Kunnumpurath" <mkunnumpur...@googlemail.com>
Subject Could not find destination factory
Date Sat, 02 Jun 2007 10:51:00 GMT
Hi,

I have got a simple scenario where a service provisioned using CXF is
accessed from a client.

This is the interface of the service that is provisioned,

public interface Greeter {
    public abstract String greet(String name);
}

The server-side code looks like this,

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.fabric3.jetty.JettyServiceImpl;
import org.fabric3.jetty.TransportMonitor;

public class Server {

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        // This is a wrapper around embedded Jetty
        JettyServiceImpl jettyService = new JettyServiceImpl(new
TransportMonitor() {
            public void debug(String msg, Object... args) { }
            public void shutdown() { }
            public void started() { }
            public void warn(String msg, Object... args) { }
        });

        CXFServlet cxfServlet = new CXFServlet();
        jettyService.init();
        jettyService.registerMapping("/services/*", cxfServlet);
        InvocationHandler handler = new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
                return "Hello " + args[0];
            }
        };
        ClassLoader cl = Server.class.getClassLoader();
        Class<?>[] interfaces = {Greeter.class};
        Object implementor = Proxy.newProxyInstance(cl, interfaces,
handler);

        ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
        serverFactoryBean.setAddress("http://localhost:8080/hello");
        serverFactoryBean.setServiceClass(Greeter.class);
        serverFactoryBean.setServiceBean(implementor);

        serverFactoryBean.setBus(cxfServlet.getBus());
        serverFactoryBean.create();

    }
}

This is the client used to invoke the service,

import java.lang.reflect.Method;

import org.apache.cxf.frontend.ClientProxyFactoryBean;

public class Client {

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
        factory.setServiceClass(Greeter.class);
        factory.setAddress("http://localhost:8080/services/hello");
        Object proxy = factory.create();
        Method method = proxy.getClass().getDeclaredMethod("greet",
String.class);

        System.err.println(method.invoke(proxy, "Fred"));

    }
}

The server starts up fine, however, when I invoke the client, I get the
following exception

Caused by: java.lang.RuntimeException: Could not find destination factory
for transport http://schemas.xmlsoap.org/soap/http
    at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(
SoapTransportFactory.java:227)
    at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(
AbstractConduitSelector.java:73)
    at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(
UpfrontConduitSelector.java:62)
    at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(
ClientImpl.java:369)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:212)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at org.apache.cxf.frontend.ClientProxy.invoke(ClientProxy.java:68)
    at $Proxy37.greet(Unknown Source)

I am not sure whether I need to add anything more in the client code to
register the destination factory. BTW, the client works if I run it in the
same JVM as the server. However, when I try them in two JVMs I get the above
exception. Any help would be highly appreciated.

Many thanks
Meeraj

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message