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.
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="Service1" targetNamespace="http://cxftest1.cp.mycomp.com/" xmlns:ns1="http://schemas.xmlsoap.org/wsdl/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://cxftest1.cp.mycomp.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://cxftest1.cp.mycomp.com/" xmlns:tns="http://cxftest1.cp.mycomp.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="getData" type="tns:getData" />
<xsd:complexType name="getData">
<xsd:sequence />
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getData">
<wsdl:part element="tns:getData" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getDataResponse">
<wsdl:part name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="IService1">
<wsdl:operation name="getData">
<wsdl:input message="tns:getData" name="getData">
</wsdl:input>
<wsdl:output message="tns:getDataResponse" name="getDataResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Service1SoapBinding" type="tns:IService1">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getData">
<soap:operation soapAction="" style="document" />
<wsdl:input name="getData">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="getDataResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service1">
<wsdl:port binding="tns:Service1SoapBinding" name="Service1Port">
<soap:address location="http://localhost:9000/service1" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>