cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rafael Ribeiro" <rafae...@gmail.com>
Subject problem serializing class hierarchy
Date Sun, 20 Apr 2008 16:36:27 GMT
Hi all,

 I have an webmethod that returns an arbitrary class. The problem is, on
some of its executions it might return some subclass of the class that is
expressed on the method signature. Instead of getting the actual class that
was serialized from the webservice the client is getting the class that is
expressed on the method. Do I have to specify anything on the classes that I
need to serialize or on the method in order for it to correct serialize the
expected class?
I am sending a sample I did to reproduce the problem described above (it is
deployed on tomcat using CXFNonSpringServlet and service is registered using
an startupservlet):

-------------------------------- IFake.java
-------------------------------------

package fake;

import javax.jws.WebService;

@WebService
public interface IFake {
    public Foo fooOp();
}

-------------------------------- FakeImpl.java
-------------------------------------

package fake;

public class FakeImpl implements IFake {

    public Foo fooOp() {
        return new FooBar();
    }

}


-------------------------------- FakeCli.java
-------------------------------------

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import fake.IFake;

public class FakeCli {
    private static IFake fakeClient;

    public static void main(String[] args) {
        System.out.println(getFakeClient().fooOp());
    }

    public static IFake getFakeClient() {
        if (fakeClient == null) {
            JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
            factory.setServiceClass(IFake.class);
            factory
                    .setAddress("
http://localhost:8080/mywebapp/services/fake");
            fakeClient = (IFake) factory.create();
        }
        return fakeClient;
    }
}

-------------------------------- Foo.java
-------------------------------------

package fake;

public class Foo {
    private String foo;

    public String getFoo() {
        return foo;
    }

    public void setFoo(String foo) {
        this.foo = foo;
    }

}

-------------------------------- FooBar.java
-------------------------------------

package fake;

public class FooBar extends Foo {
    private String fooBar;

    public String getFooBar() {
        return fooBar;
    }

    public void setFooBar(String fooBar) {
        this.fooBar = fooBar;
    }

}

------------------------------------------------------------------------

 This webservice is registered by this call on the startupservlet:
        Endpoint.publish("/fake", new FakeImpl());

and the result of the execution of FakeCli is something like:
fake.Foo@6210fb

If I try to cast it to FooBar I get a ClassCastException, as expected since
this class was really instantiated as Foo instead of FooBar

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