4 Replies Latest reply on Nov 2, 2006 6:09 AM by lowecg2004

    Return value for Java bean always empty

    lowecg2004

      Hello,

      I'm trying to set up a simple web service that returns a StockData object that has 4 properties. From my client, I can invoke the service and I can step through the method in the debugger and see that an object is created and populated. However, when the method returns at the client the object is null.

      The endpoint in a JSR 181 EJB3:

      Interface:
      
      @Remote
      public interface WeatherService {
       public StockData getStockData(String title);
      }
      
      Implementation:
      
      @WebService(name = "WeatherService", targetNamespace = "http://org.test", serviceName = "WeatherService")
      @SOAPBinding(style = SOAPBinding.Style.RPC)
      @Stateless
      @Remote(WeatherService.class)
      @RemoteBinding(jndiBinding = "/ejb3/EJB3EndpointInterface")
      public class WeatherServiceBean implements WeatherService {
       @WebMethod
       public StockData getStockData(final String title) {
       StockData stockData = new StockData(title, 1, 234, true);
       return stockData;
       }
      }
      
      
      SOAP Request:
      
      <soapenv:Envelope
       xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
       <s0:getStockData
       xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:s0="http://org.test">
       <String_1>SomeTitle</String_1>
       </s0:getStockData>
       </soapenv:Body>
      </soapenv:Envelope>
      
      SOAP Respose:
      
      <env:Envelope
       xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
       <env:Header />
       <env:Body>
       <ns1:getStockDataResponse xmlns:ns1="http://org.test">
       <result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
       </ns1:getStockDataResponse>
       </env:Body>
      </env:Envelope>
      
      
      The generated WSDL from calling http://dfvgm71j:8080/WebServiceEJB/WeatherServiceBean?WSDL:
      
      <definitions name="WeatherService"
       targetNamespace="http://org.test"
       xmlns="http://schemas.xmlsoap.org/wsdl/"
       xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
       xmlns:tns="http://org.test"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <types>
       <schema elementFormDefault="qualified"
       targetNamespace="http://org.test"
       xmlns="http://www.w3.org/2001/XMLSchema"
       xmlns:soap11-enc="http://schemas.xmlsoap.org/soap/encoding/"
       xmlns:tns="http://org.test"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <complexType name="StockData">
       <sequence/>
       </complexType>
       </schema>
       </types>
       <message name="WeatherService_getStockDataResponse">
       <part name="result" type="tns:StockData"/>
       </message>
       <message name="WeatherService_getStockData">
       <part name="String_1" type="xsd:string"/>
       </message>
       <portType name="WeatherService">
       <operation name="getStockData" parameterOrder="String_1">
       <input message="tns:WeatherService_getStockData"/>
       <output message="tns:WeatherService_getStockDataResponse"/>
       </operation>
       </portType>
       <binding name="WeatherServiceBinding" type="tns:WeatherService">
       <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
       <operation name="getStockData">
       <soap:operation soapAction=""/>
       <input>
       <soap:body namespace="http://org.test" use="literal"/>
       </input>
       <output>
       <soap:body namespace="http://org.test" use="literal"/>
       </output>
       </operation>
       </binding>
       <service name="WeatherService">
       <port binding="tns:WeatherServiceBinding" name="WeatherServicePort">
       <soap:address location="http://DFVGM71J:8080/WebServiceEJB/WeatherServiceBean"/>
       </port>
       </service>
      </definitions>



      I can't work this out. If I change the return type to a String then my client gets the value. What am I doing wrong?

      Chris.

        • 1. Re: Return value for Java bean always empty
          jason.greene

          The problem is that the StockData schema indicates that the javabean has no properties:

          <complexType name="StockData">
           <sequence/>
          </complexType>
          


          Can you paste the code to StockData?

          Thanks,
          -Jason



          • 2. Re: Return value for Java bean always empty
            lowecg2004

            Hi Jason,

            Here is the code that I had for StockData:

            package org.test;
            
            import java.io.Serializable;
            
            public class StockData
             implements Serializable
            {
             /**
             *
             */
             private static final long serialVersionUID = 1L;
            
             private String title;
             private int issue;
             private int value;
             private boolean hasStock;
            
             public StockData() {
             }
            
             public StockData(String title,
             int issue,
             int value,
             boolean hasStock) {
             this.title = title;
             this.issue = issue;
             this.value = value;
             this.hasStock = hasStock;
             }
            
             void setTitle(String title) {
             this.title = title;
             }
             String getTitle() {
             return title;
             }
             void setIssue(int issue) {
             this.issue = issue;
             }
             int getIssue() {
             return issue;
             }
             void setValue(int value) {
             this.value = value;
             }
             int getValue() {
             return value;
             }
             void setHasStock(boolean hasStock) {
             this.hasStock = hasStock;
             }
             boolean isHasStock() {
             return hasStock;
             }
            }


            Thanks for taking the time to help me with this,

            Chris.



            • 3. Re: Return value for Java bean always empty
              jason.greene

              The problem is that your getters/setters aren't public.

              Your data objects must be either a conformant JavaBean, or a class with public fields and a noarg constructor.

              -Jason

              • 4. Re: Return value for Java bean always empty
                lowecg2004

                Oh (expletive deleted).

                It was so obvious - I'd been looking at it for so long that I completely missed the basics!

                Thanks for you help,

                Chris.