Using the webservice client generated by MyEclipse for Sprin

  1. MyEclipse IDE > Spring Development

This topic contains 2 replies, has 2 voices, and was last updated by  davemeurer 10 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #306256 Reply

    Dennis
    Participant

    I 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)

    #306263 Reply

    davemeurer
    Member

    Hello,

    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

    #306295 Reply

    davemeurer
    Member

    It 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

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Using the webservice client generated by MyEclipse for Sprin

You must be logged in to post in the forum log in