You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Petr V." <gr...@yahoo.com> on 2008/11/10 19:11:05 UTC

New to CXF, Can't return simple DTO, hitting run time exception :-(

Hi All,

This is my first exposure and hello world example with CXF.

I can successfully call web service that is returning string but when I try to return my simple DTO, I am getting following exception at run time.

INFO: Creating Service {http://cxftest1.cp.mycomp.com/}IService1Service from class com.mycomp.cp.cxftest1.IService1
Nov 10, 2008 10:00:58 AM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: com.mycomp.cp.cxftest.dto.SampleDTO
������� at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:116)
������� at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
������� at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
������� at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
������� at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
������� at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:278)
������� at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:252)
������� at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)
������� at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
������� at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
������� at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
������� at org.mortbay.jetty.Server.handle(Server.java:324)
������� at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
������� at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842)
������� at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:730)
������� at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
������� at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
������� at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
������� at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)

Caused by: org.apache.cxf.interceptor.Fault: com.mycomp.cp.cxftest.dto.SampleDTO
������� at org.apache.cxf.jaxws.interceptors.WrapperHelper$ReflectWrapperHelper.createWrapperObject(WrapperHelper.java:311)
������� at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:102)
������� ... 18 more
Caused by: java.lang.InstantiationException: com.mycomp.cp.cxftest.dto.SampleDTO
������� at java.lang.Class.newInstance0(Class.java:340)
������� at java.lang.Class.newInstance(Class.java:308)
������� at org.apache.cxf.jaxws.interceptors.WrapperHelper$ReflectWrapperHelper.createWrapperObject(WrapperHelper.java:276)
������� ... 19 more


Here is my sample code , please have a look and let me know wat I am doin gwrong.

=============================================================

Service Interface 

@WebService
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL)
public interface� IService1 {

���� @WebMethod(operationName="getData") 
���� @ResponseWrapper(targetNamespace="http://cxftest1.cp.vmware.com/types",����� 
���������������������������������� className="com.vmware.cp.cxftest.dto.SampleDTO")

����� public SampleDTO getSampleDTO() ;
��� 
}


================================================

Service Class

@WebService(endpointInterface = "com.vmware.cp.cxftest1.IService1",
�������������������������������������������������� serviceName = "Service1")

public class Service1 implements IService1 {
��� 
��� private Manager mgr = new Manager();
��� 
��� public SampleDTO getSampleDTO() {
������� return new SampleDTO("XXXX" , 34) ;� 
��� } 
}

================================================

DTO

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SampleDTOInfo", propOrder = {"name","age"})

public class SampleDTO implements Serializable {
��� 
��� public SampleDTO(String name , int age) {
������� this.name = name;
������� this.age = age;
��� }
��� 
��� @XmlElement(name = "name")
��� public String name;
��� 
��� @XmlElement(name = "age")
��� public int age;�� 
��� 
��� public String getName() {
������� return name;
��� }
��� public void setName(String name) {
������� this.name = name;
��� }
��� public int getAge() {
������� return age;
��� }
��� public void setAge(int age) {
������� this.age = age;
��� }��� 
}

==========================================================

Styarting Service and Creating Client

public class Service1Test extends TestCase {
������ 
��� 
��� public void testApp() throws Exception{

������� String address = "http://localhost:9000/service1";
������� Service1 implementor = new Service1();
������� Endpoint myEndpoint = Endpoint.publish(address, implementor);
������ 
������� JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
������� factory.setAddress("http://localhost:9000/service1");
������� factory.setServiceClass(IService1.class);������� 
������� IService1 client = (IService1) factory.create();
������� client.getSampleDTO();
������� 
������� myEndpoint.stop();
��� }� 
}

=========================================================

When I started the service and accessed the http://localhost:9000/service1?wsdl then I got the wsdl which I have attached with this email. I do not see the definition of my DTO in it.







      

Re: New to CXF, Can't return simple DTO, hitting run time exception :-(

Posted by "Petr V." <gr...@yahoo.com>.
Thank you Ian for the response, That's what I did by starting from minimum code and figured it out. 

Petr

--- On Tue, 11/11/08, Ian Roberts <i....@dcs.shef.ac.uk> wrote:
From: Ian Roberts <i....@dcs.shef.ac.uk>
Subject: Re: New to CXF, Can't return simple DTO,  hitting run time exception :-(
To: users@cxf.apache.org
Date: Tuesday, November 11, 2008, 2:00 AM

Petr V. wrote:
> Hi All,
> 
> This is my first exposure and hello world example with CXF.
> 
> I can successfully call web service that is returning string but when I
> try to return my simple DTO, I am getting following exception at run time.
> 
...
> Caused by: java.lang.InstantiationException:
> com.mycomp.cp.cxftest.dto.SampleDTO
>         at java.lang.Class.newInstance0(Class.java:340)
>         at java.lang.Class.newInstance(Class.java:308)
>         at
>
org.apache.cxf.jaxws.interceptors.WrapperHelper$ReflectWrapperHelper.createWrapperObject(WrapperHelper.java:276)
>         ... 19 more

You need to add a no-argument constructor to your DTO class (which could
be in addition to the two-arg one, it doesn't have to be either/or).

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK



      

Re: New to CXF, Can't return simple DTO, hitting run time exception :-(

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Petr V. wrote:
> Hi All,
> 
> This is my first exposure and hello world example with CXF.
> 
> I can successfully call web service that is returning string but when I
> try to return my simple DTO, I am getting following exception at run time.
> 
...
> Caused by: java.lang.InstantiationException:
> com.mycomp.cp.cxftest.dto.SampleDTO
>         at java.lang.Class.newInstance0(Class.java:340)
>         at java.lang.Class.newInstance(Class.java:308)
>         at
> org.apache.cxf.jaxws.interceptors.WrapperHelper$ReflectWrapperHelper.createWrapperObject(WrapperHelper.java:276)
>         ... 19 more

You need to add a no-argument constructor to your DTO class (which could
be in addition to the two-arg one, it doesn't have to be either/or).

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK