- This topic has 2 replies, 2 voices, and was last updated 14 years, 10 months ago by davemeurer.
-
AuthorPosts
-
DennisParticipantI created a webservice for the Customer table using the instructions provided in the help. I cannot get the client to work. Here is my code and the error. If I create my own client not using the generated one, it works fine.
I created a main method in the generated client (which I had renamed):
public static void main(String[] args) {
CustomerServiceClient client = new CustomerServiceClient(CustomerServiceClient.WSDL_LOCATION, CustomerServiceClient.SERVICE);
Set<Customer> custs = client.getService().loadCustomers();
System.out.println(“Custs size = “+custs.size());The service returns an ArrayLIst and not a Set; errors listed below:
2010-02-22 09:48:19,250 INFO [main] AbstractApplicationContext – Refreshing org.apache.cxf.bus.spring.BusApplicationContext@10da5eb: display name [org.apache.cxf.bus.spring.BusApplicationContext@10da5eb]; startup date [Mon Feb 22 09:48:19 CST 2010]; root of context hierarchy
Feb 22, 2010 9:48:19 AM org.apache.cxf.bus.spring.BusApplicationContext getConfigResources
INFO: No cxf.xml configuration file detected, relying on defaults.
2010-02-22 09:48:20,421 INFO [main] AbstractApplicationContext – Bean factory for application context [org.apache.cxf.bus.spring.BusApplicationContext@10da5eb]: org.springframework.beans.factory.support.DefaultListableBeanFactory@13f210f
Exception in thread “main” java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Set
at $Proxy51.loadCustomers(Unknown Source)
at org.myapp.service.jaxws.CustomerServiceClient.main(CustomerServiceClient.java:149)
davemeurerMemberHello,
The default Collection types in MyEclipse for Spring is Set, so I’m curious why the service is returning an ArrayList.
If your project was initialized with Spring DSL Generation Capabilities, in the Project Explorer > Spring DSL (double click) > Code Generation tab, there is a global setting to change the collection type. Was this option changed?
How was the service created? Via Scaffolding?
Try performing a Project > Clean and see if that changes the Endpoint type to a Set.
Let us know. Kind regards,
Dave
davemeurerMemberIt turns out there is a difference in the CXF configuration while running in a Spring web app vs. just running the client directly. You’ll notice when running directly, it can not find the resources/jaxws/jaxws-web-context.xml CXF config and uses a default. I was lead to this conclusion because running the same code in the controller or service works fine with using Sets. I haven’t found out a definitive answer, so I’d be interested if anyone out there knows for sure.
One nice workaround is to change the global Collection type in MyEclipse for Spring to List. Here is how to do this in a project like this:
1. In the Service Spring Editor, go to the Code Generation tab. Take out the “Service” word in the Filename for the Web Service Endpoint Interface, and Web Service Client. (This will prevent you from needing to rename after we do another code gen)
2. You’ll need to open the Project Explorer for this step > Double-click the Spring DSL node, and go to the Code Generation tab. At the top, choose “List” (Ignore the error), and click Save.
3. On the File Menu, click Project > Clean. This should regenerate your files with the right name and with List as the Collection type. If you get compile errors, you may want to try and rescaffold. (quickest way is to right-click the Domain Object under Spring DSL in the Project Explorer)
4. You will then need to change your custom main code in the client to cast the custs variable as a List.
Thanks,
Dave -
AuthorPosts