- This topic has 16 replies, 4 voices, and was last updated 17 years, 5 months ago by chickenlips.
-
AuthorPosts
-
Lee HarringtonMemberOn to my next struggle. I created a webservice modeled after HelloWorld — which returns a string. All good.
Now I want to have it return a list. I received teh following error. The only change between the working code and the error was changing the method to return a list instead of a string.
The list is a java.util.List with two string members. I was just trying to take the next step toward my eventual goal which is:
Creaete a web service that queries a database and returns a result. I had thought I’d return a list — as my hibernate classes return a list. But before I got that far I hit a wall with a basic list.
Lee
SEVERE: Error initializing XFireServlet. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.codehaus.xfire.spring.ServiceBean' defined in class path resource [META-INF/xfire/services.xml]: Initialization of bean failed; nested exception is org.codehaus.xfire.XFireRuntimeException: Cannot create mapping for java.util.List, unspecified component type for return type of method example in interface com.att.nocem.IMaoMooService org.codehaus.xfire.XFireRuntimeException: Cannot create mapping for java.util.List, unspecified component type for return type of method example in interface com.att.nocem.IMaoMooService at org.codehaus.xfire.aegis.type.DefaultTypeCreator.createCollectionType(DefaultTypeCreator.java:43) at org.codehaus.xfire.aegis.type.java5.Java5TypeCreator.createCollectionType(Java5TypeCreator.java:138) at org.codehaus.xfire.aegis.type.XMLTypeCreator.createCollectionType(XMLTypeCreator.java:137) at org.codehaus.xfire.aegis.type.AbstractTypeCreator.createTypeForClass(AbstractTypeCreator.java:91) at org.codehaus.xfire.aegis.type.AbstractTypeCreator.createType(AbstractTypeCreator.java:334) at org.codehaus.xfire.aegis.AegisBindingProvider.getSuggestedName(AegisBindingProvider.java:226) at org.codehaus.xfire.service.binding.DefaultServiceConfiguration.getOutParameterName(DefaultServiceConfiguration.java:174) at org.codehaus.xfire.service.binding.ObjectServiceFactory.getOutParameterName(ObjectServiceFactory.java:1033) at org.codehaus.xfire.service.binding.ObjectServiceFactory.addOperation(ObjectServiceFactory.java:794) at org.codehaus.xfire.service.binding.ObjectServiceFactory.initializeOperations(ObjectServiceFactory.java:720) at org.codehaus.xfire.service.binding.ObjectServiceFactory.create(ObjectServiceFactory.java:418) at org.codehaus.xfire.spring.ServiceBean.afterPropertiesSet(ServiceBean.java:176) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:275) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320) at org.codehaus.xfire.spring.XFireConfigLoader.getXFireApplicationContext(XFireConfigLoader.java:107) at org.codehaus.xfire.spring.XFireConfigLoader.loadContext(XFireConfigLoader.java:41) at org.codehaus.xfire.transport.http.XFireConfigurableServlet.loadConfig(XFireConfigurableServlet.java:86) at org.codehaus.xfire.transport.http.XFireConfigurableServlet.createXFire(XFireConfigurableServlet.java:54) at org.codehaus.xfire.transport.http.XFireServlet.init(XFireServlet.java:45) at javax.servlet.GenericServlet.init(GenericServlet.java:256) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1044) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:712) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:186) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677) at java.lang.Thread.run(Thread.java:619)
Lee HarringtonMember@tomeksz wrote:
Perfect. As I’m now on Java5 — I can use the “Generics” in:
public List<String> example(String message) { List<String> resultList = new ArrayList<String>(); resultList.add("one"); resultList.add("two"); return resultList; }
Of course — as I’m using hibernate, I wanted a List of my database class — and that worked as well.
public List<NocemData> example(String message) { List<NocemData> resultList = new ArrayList<NocemData>(); NocemData data = new NocemData(); resultList.add(data); resultList.add(data); return resultList; }
Well, at least it compiles and runs without error. Have to put some guts behind the code to query data and retrieve it.
Lee
Lee HarringtonMemberI spoke too soon. I have my new webservice up and running, but when I to write the clien’t I’m getting a cast problem.
Server code:
public List<NocemData> example(String message) { List<NocemData> resultList = new ArrayList<NocemData>(); NocemData data = new NocemData(); data.setMetricNumber("1"); data.setMetricName("Metric One"); resultList.add(data); data.setMetricNumber("2"); data.setMetricName("Metric Two"); resultList.add(data); return resultList; }
Client code:
public static void main(String[] args) { MaoMooServiceClient client = new MaoMooServiceClient(); //create a default service endpoint MaoMooServicePortType service = client.getMaoMooServiceHttpPort(); //TODO: Add custom client code here // //service.yourServiceOperationHere(); List<NocemData> resultList = new ArrayList<NocemData>(); resultList = service.example("test"); System.out.println("test client completed"); System.exit(0); }
But the line
resultList = service.example("test");
won’t comile with error:
Type mismatch: cannont convert to ArrayOfNocemData from List<NocemData>
Putting in “Array” instead of List/ArrayList did not change anything.
The relevant type declaration from the WSDL is
<xsd:complexType name="ArrayOfNocemData"> - <xsd:sequence> <xsd:element maxOccurs="unbounded" minOccurs="0" name="NocemData" nillable="true" type="tns:NocemData" /> </xsd:sequence> </xsd:complexType> - <xsd:complexType name="NocemData"> - <xsd:sequence> <xsd:element minOccurs="0" name="dataType" nillable="true" type="xsd:string" /> <xsd:element minOccurs="0" name="decimals" nillable="true" type="xsd:short" /> <xsd:element minOccurs="0" name="lastModBy" nillable="true" type="xsd:string" /> <xsd:element minOccurs="0" name="lastModDate" nillable="true" type="xsd:dateTime" /> <xsd:element minOccurs="0" name="length" nillable="true" type="xsd:long" /> <xsd:element minOccurs="0" name="metricDescription" nillable="true" type="xsd:string" /> <xsd:element minOccurs="0" name="metricId" nillable="true" type="xsd:long" /> <xsd:element minOccurs="0" name="metricName" nillable="true" type="xsd:string" /> <xsd:element minOccurs="0" name="metricNumber" nillable="true" type="xsd:string" /> <xsd:element minOccurs="0" name="status" nillable="true" type="xsd:string" /> <xsd:element minOccurs="0" name="version" nillable="true" type="xsd:long" /> </xsd:sequence> </xsd:complexType>
I’m back to being stuck<sigh>
Lee
Lee HarringtonMemberOk….I woke up this morning with the answer — I love it when that happens. Wasn’t even thinking about it (conscienciously sp?) and it just hit me. The generated code should have the answer. And sure enough — the code generated a custom ArrayOfNocemData class for me.
public static void main(String[] args) { MaoMooServiceClient client = new MaoMooServiceClient(); //create a default service endpoint MaoMooServicePortType service = client.getMaoMooServiceHttpPort(); //TODO: Add custom client code here // //service.yourServiceOperationHere(); ArrayOfNocemData aResult = service.example("test"); System.out.println("test client completed: " + aResult.toString()); System.exit(0); }
Compiles and runs. Just have to figure out how to manipulate the custom class instance to get my data out 🙂
Lee
Lee HarringtonMemberI’m doing the happy dance. Bundled up a data set on my web server, and retrieved it on the client. Made one more mistake I’ll share to help any future folks.
My web service has a custome data class (created by the hibernate generator) called
NocemData
Knowing that I’d need the client to be able to receive data I copied the class into my client. I ended up with 2 versions of NocemData — as the web client generator generated it’s own version of NocemData — unnoticed by me. I was really confused by error messages like
can't cast between Iterator<NocemData> and Iterator<NocemData>
It took me a bit to realize I had ended up with two NocemData classes, though in different packages in the same project. So I deleted the NocemData class I had copied into the project, kept the NocemData class MyEclipse generated for me, and was able to write the following code:
public static void main(String[] args) { MaoMooServiceClient client = new MaoMooServiceClient(); //create a default service endpoint MaoMooServicePortType service = client.getMaoMooServiceHttpPort(); //TODO: Add custom client code here // //service.yourServiceOperationHere(); ArrayOfNocemData aResult = service.example("test"); NocemData currentData = new NocemData(); Iterator<NocemData> itr = aResult.getNocemData().iterator(); while (itr.hasNext()) { currentData = itr.next(); System.out.println("Metric Number: " + currentData.getMetricNumber().getValue() + " - MetricName: " + currentData.getMetricName().getValue()); } System.out.println("test client completed: " + aResult.toString()); System.exit(0); }
Fantastic! MyEclipse rocks! Oh — and it’s now a company standard product to boot!
Lee
tomekszMemberYeah, and XFire rocks too 😉
nvenkataraoMemberIf already existing class is there then why your generating again at client side your custom(ArrayOfNocemData) class this is overhead of others…
If List is there generate return type is list but why your generating your custom classes ..like ArrayOfString……Is there any way that is generating as it is ..like what ever we mentioned in the same as server side component…..
Lee HarringtonMember@nvenkatarao wrote:
If already existing class is there then why your generating again at client side your custom(ArrayOfNocemData) class this is overhead of others…
A good question. The real answer is “I didn’t know what MyEclipse was generating”. However the story goes beyond this.
In my example I am developing both the web service and the web client. And I’m developing both of them in Java. The whole purpose of SOAP and web services is to allow different platforms and development environements to work together.
As such the client should be able to be developed completely independantly of the web service. I wouldn’t be able to simply hand off my data class to the “client team” which might very well be working in a different programming language.
The beauty of XFire and the MyEclipse generated code is that the client developer need only the WSDL — and all the java code is generated — including the custom data class.
At least, that’s the way I understand it.
Lee
nvenkataraoMemberHi Lee,
Your correct in the sense The purpose of SOAP and web services is to allow different platforms and development environments to work together.
My just little bit question here is …now how you are generating your WSDL file from Java classes……
If possible please let me know….
tomekszMemberIf you want to use Java client for your Java webservice then you don’t need to generate client code. All you need is java service interface and objects used as params and result, XFire just use this interface to connect to remote servis.
Lee HarringtonMember@tomeksz wrote:
If you want to use Java client for your Java webservice then you don’t need to generate client code. All you need is java service interface and objects used as params and result, XFire just use this interface to connect to remote servis.
I hear you. There will be a remote client calling the webservice I’m developing. But in order to test the web service I’m creating — I’ve created my own web client 🙂
Lee
Lee HarringtonMember@nvenkatarao wrote:
My just little bit question here is …now how you are generating your WSDL file from Java classes……
If possible please let me know….
There is a tutorials and demo’s page: http://www.myeclipseide.com/ContentExpress-display-ceid-16.html
And the particular one for how to develop a web client from a WSDL is: http://www.myeclipseide.com/images/tutorials/demos/terra_server_client/tutorial.html
Lee
chickenlipsMemberLee or anybody,
I have update your code to show how you query the DB, but I am getting an exception from org.hibernate.SessionFactory: Cannot create mapping for java.util.Set, unspecified component type for interface java.util.Set
public List<NocemData> example(List<NocemDataDAO> dao) {
Transaction t = dao.get(0).getSession().beginTransaction();
List resultList = d.get(0).getSession().createQuery(“from MyTable”).list();
t.commit();return resultList;
}What could be the problem?
chickenlipsMemberThe complete exception:
15:14:10,953 ERROR [XFireServletController] Couldn’t invoke servlet request.
org.codehaus.xfire.XFireRuntimeException: Couldn’t create type for property definedFilterNames on interface org.hibernate.SessionFactory: Cannot create mapping for java.util.Set, unspecified component type for interface java.util.Set
at org.codehaus.xfire.aegis.type.DefaultTypeCreator.createCollectionType(DefaultTypeCreator.java:43)
at org.codehaus.xfire.aegis.type.java5.Java5TypeCreator.createCollectionType(Java5TypeCreator.java:139)
at org.codehaus.xfire.aegis.type.XMLTypeCreator.createCollectionType(XMLTypeCreator.java:116)
at org.codehaus.xfire.aegis.type.AbstractTypeCreator.createTypeForClass(AbstractTypeCreator.java:113)
at org.codehaus.xfire.aegis.type.AbstractTypeCreator.createType(AbstractTypeCreator.java:396)
at org.codehaus.xfire.aegis.type.XMLTypeCreator.createTypeFromGeneric(XMLTypeCreator.java:325)
at org.codehaus.xfire.aegis.type.XMLTypeCreator.getOrCreateGenericType(XMLTypeCreator.java:312)
at org.codehaus.xfire.aegis.type.AbstractTypeCreator.createCollectionTypeFromGeneric(AbstractTypeCreator.java:227)
at org.codehaus.xfire.aegis.type.XMLTypeCreator.createCollectionType(XMLTypeCreator.java:113)
at org.codehaus.xfire.aegis.type.AbstractTypeCreator.createTypeForClass(AbstractTypeCreator.java:113)
at org.codehaus.xfire.aegis.type.AbstractTypeCreator.createType(AbstractTypeCreator.java:376)
at org.codehaus.xfire.aegis.type.basic.BeanTypeInfo.getType(BeanTypeInfo.java:205)
at org.codehaus.xfire.aegis.type.basic.BeanType.getType(BeanType.java:609)
at org.codehaus.xfire.aegis.type.basic.BeanType.writeSchema(BeanType.java:530)
at org.codehaus.xfire.wsdl.AbstractWSDL.addDependency(AbstractWSDL.java:230)
at org.codehaus.xfire.wsdl.AbstractWSDL.addDependency(AbstractWSDL.java:239)
at org.codehaus.xfire.wsdl.AbstractWSDL.addDependency(AbstractWSDL.java:239)
at org.codehaus.xfire.wsdl.AbstractWSDL.addDependency(AbstractWSDL.java:239)
at org.codehaus.xfire.wsdl11.builder.WSDLBuilder.writeParametersSchema(WSDLBuilder.java:638)
at org.codehaus.xfire.wsdl11.builder.WSDLBuilder.createDocumentType(WSDLBuilder.java:612)
at org.codehaus.xfire.wsdl11.builder.WSDLBuilder.createWrappedInputParts(WSDLBuilder.java:580)
at org.codehaus.xfire.wsdl11.builder.WSDLBuilder.createInputMessage(WSDLBuilder.java:371)
at org.codehaus.xfire.wsdl11.builder.WSDLBuilder.createAbstractInterface(WSDLBuilder.java:234)
at org.codehaus.xfire.wsdl11.builder.WSDLBuilder.write(WSDLBuilder.java:161)
at org.codehaus.xfire.wsdl11.builder.WSDLBuilderAdapter.write(WSDLBuilderAdapter.java:40)
at org.codehaus.xfire.DefaultXFire.generateWSDL(DefaultXFire.java:104)
at org.codehaus.xfire.transport.http.XFireServletController.generateWSDL(XFireServletController.java:380)
at org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:125)
at org.codehaus.xfire.transport.http.XFireServlet.doGet(XFireServlet.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595) -
AuthorPosts