6 Replies Latest reply on May 29, 2006 5:57 AM by Thomas Diesler

    return/pass JavaBean ?

    Eric Chow Apprentice

      Hello,

      How can I pass a JavaBean as a parameter and return an array of JavaBean through web service ?

      Any example to do this, please help ?



        • 1. Re: return/pass JavaBean ?
          Burr Sutter Master

          I'm working on an example for my own purposes. Perhaps we can work together...

          I'm working on the Service side for now here is my attempt at returning a JavaBean/POJO as well as a List/collection of those POJOs
          Note: this isn't currently working but might help us move in the same direction:

          @WebService(name = "POJOService",
          targetNamespace="http://com.burrsutter.jbossws/pojoservice")@SOAPBinding(style = SOAPBinding.Style.RPC)
          public class POJOService {
           @WebMethod(operationName="GetPersonByID")
           public Person getPerson(String id)
           {
           System.out.println("Looking for " + id);
           Person somebody = new Person();
           somebody.setName("Burr Sutter");
           somebody.setAge(24);
           somebody.setBirthDate(new java.util.Date());
           return somebody;
           }
           @WebMethod (operationName="GetAllPeople")
           public List<Person> getPeople() {
           List<Person> results = new ArrayList<Person>();
           Person a = new Person();
           a.setName("Burr Sutter");
           a.setAge(24);
           a.setBirthDate(new java.util.Date());
           results.add(a);
           Person b = new Person();
           b.setName("Thomas Diesler");
           b.setAge(23);
           b.setBirthDate(new java.util.Date());
           results.add(b);
           return results;
           }
          }

          What do you think?

          Burr
          burr.sutter@jboss.com

          • 2. Re: return/pass JavaBean ?
            Burr Sutter Master

            As a follow up to my own post, returning a collection like a List doesn't work and based on my reading of the specification, I'm not sure that it is supposed to. So here is an example that returns an array of POJOs:

            @WebMethod (operationName="GetAllPeopleArray")
             public Person[] getPeople2() {
             Person[] results = new Person[2];
             Person a = new Person();
             a.setName("Burr Sutter");
             a.setAge(24);
             a.setBirthDate(new java.util.Date());
             results[0] = a;
             Person b = new Person();
             b.setName("Thomas Diesler");
             b.setAge(23);
             b.setBirthDate(new java.util.Date());
             results[1] = b;
            
             return results;
             }


            This works fine with a VB.NET consumer. The previous example returing a List did compile but the WSDL wasn't useful. In .NET Web Services returing a List collection does work and seems to kick out an array from the perspective of the WSDL.

            Burr
            burr.sutter@jboss.com


            • 3. Re: return/pass JavaBean ?
              Ramzi Maalej Newbie

              Yes, you can pass a java bean as a parameter.

              • 4. Re: return/pass JavaBean ?
                Eugene Khosid Newbie

                How do you annotate the bean class so it shows up in WSDL file correctly?

                • 5. Re: return/pass JavaBean ?
                  Eugene Khosid Newbie

                  Never mind my question.

                  • 6. Re: return/pass JavaBean ?
                    Thomas Diesler Master

                    ekhosid,

                    your question is valid and part of the JAXWS + JAXB functionality. Currently, we are working on this part and you will be able to use annotaed user types in one of the next versions.