Web Service Response returns <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

waprau picture waprau · Dec 7, 2011 · Viewed 8.2k times · Source

I am very new to Web Services. I am creating Apache CXF (apache-cxf-2.5.0) SOAP based Web Services. It creates WSDL from Java class (Java first approach).

Following is my Java class:

package com.abcd.shoppingcart;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.jws.WebService;

import org.jboss.wsf.spi.annotation.WebContext;

import com.abcd.db.DBConnection;

@WebService(endpointInterface = "com.abcd.shoppingcart.GetMerchantsCardsListInterface", serviceName = "GetMerchantsCardsList4")
@WebContext( contextRoot = "/" , urlPattern="/SrvGetmerchantsCardsList.jsp" )
public class GetMerchantsCardsList4 implements GetMerchantsCardsListInterface {
    private DBConnection dbConnection;

    private Connection con = null;
    private Statement stmt = null;
    private ResultSet rset = null;

    private String sqlSelect = null;

    String[][] cardData = null;
    int columnNo = 1, rowNo = 1, totalRows = 0, totalColumns = 6;

    public String[][] returnMerchantsCardsList(int pageNumber, int recordsPerPage) {
        dbConnection = new DBConnection();
        sqlSelect = "SELECT "
                + " giftcard.MerchantId, giftcard.MerchantName, giftcard.ID AS GiftCardId, giftcardtransactions.CardNumber AS GiftCardNumber, "
                + " giftcardtransactions.CardValue, giftcardtransactions.ImageName  "
                + " FROM merchant "
                + " INNER JOIN giftcard ON giftcard.MerchantId = merchant.ID "
                + " INNER JOIN giftcardtransactions ON giftcardtransactions.id = merchant.ID "
                + " WHERE merchant.isActive = '1' "
                + " GROUP BY giftcard.MerchantId";

        try {
            con = dbConnection.getConnection();
            stmt = con.createStatement();

            rset = stmt.executeQuery(sqlSelect);

            rset.last();
            totalRows = rset.getRow();

            totalRows++;
            totalColumns++;

            cardData = new String[totalRows][totalColumns];

            rset.beforeFirst();

            while (rset.next()) {
                columnNo = 1;
                while (columnNo < totalColumns) {
                    cardData[rowNo][columnNo] = rset.getString(columnNo);
                    //System.out.print(cardData[rowNo][columnNo] + "\t\t");
                    columnNo++;
                }
                rowNo++;
                System.out.println();
            }

            rset.close();
            stmt.close();
            con.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
        }

        return cardData;
    }
}

This is WSDL created at the specified URL:

<wsdl:definitions xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://shoppingcart.abcd.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="GetMerchantsCardsList4" targetNamespace="http://shoppingcart.abcd.com/">
<wsdl:types>
<xs:schema xmlns:ns1="http://jaxb.dev.java.net/array" xmlns:tns="http://shoppingcart.abcd.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://shoppingcart.abcd.com/">
<xs:import namespace="http://jaxb.dev.java.net/array"/>
<xs:element name="returnMerchantsCardsList" type="tns:returnMerchantsCardsList"/>
<xs:element name="returnMerchantsCardsListResponse" type="tns:returnMerchantsCardsListResponse"/>
<xs:complexType name="returnMerchantsCardsList">
<xs:sequence>
<xs:element name="pageNumber" type="xs:int"/>
<xs:element name="recordsPerPage" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="returnMerchantsCardsListResponse">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="ns1:stringArray"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://jaxb.dev.java.net/array" version="1.0">
<xs:complexType final="#all" name="stringArray">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="returnMerchantsCardsList">
<wsdl:part element="tns:returnMerchantsCardsList" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="returnMerchantsCardsListResponse">
<wsdl:part element="tns:returnMerchantsCardsListResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="GetMerchantsCardsListInterface">
<wsdl:operation name="returnMerchantsCardsList">
<wsdl:input message="tns:returnMerchantsCardsList" name="returnMerchantsCardsList"></wsdl:input>
<wsdl:output message="tns:returnMerchantsCardsListResponse" name="returnMerchantsCardsListResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GetMerchantsCardsList4SoapBinding" type="tns:GetMerchantsCardsListInterface">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="returnMerchantsCardsList">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="returnMerchantsCardsList">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="returnMerchantsCardsListResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="GetMerchantsCardsList4">
<wsdl:port binding="tns:GetMerchantsCardsList4SoapBinding" name="GetMerchantsCardsList4Port">
<soap:address location="http://localhost:8080/webservices/test/SrvGetmerchantsCardsList.jsp"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

I am using soapUI for testing. This is the request generated when I use soapUI :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:shop="http://shoppingcart.abcd.com/">
   <soapenv:Header/>
   <soapenv:Body><shop:returnMerchantsCardsList>
         <pageNumber>1</pageNumber>
         <recordsPerPage>4</recordsPerPage>
      </shop:returnMerchantsCardsList>
   </soapenv:Body>
</soapenv:Envelope>

This is the response I get when I submit request to specified endpoint URL for the FIRST time:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:returnMerchantsCardsListResponse xmlns:ns2="http://shoppingcart.abcd.com/">
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item>3</item>
            <item>Borders</item>
            <item>224</item>
             <item>jhgsjhdgjshgjjshsj</item>
            <item>25.00</item>
            <item>ord_mall.jpg</item>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item>5</item>
            <item>Gap</item>
            <item>210</item>
             <item>jhgsjhdgjshgjjshsj</item>
            <item>25.00</item>
            <item>land_mall.jpg</item>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item>6</item>
            <item>Fandango</item>
            <item>211</item>
            <item>asd78723642h36</item>
            <item>25.00</item>
            <item>game_mall.jpg</item>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item>8</item>
            <item>AMC Theaters</item>
            <item>212</item>
             <item>jhgsjhdgjshgjjshsj</item>
            <item>25.00</item>
            <item>game_mall.jpg</item>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item>9</item>
            <item>Macy{#}s</item>
            <item>214</item>
            <item>jhgsjhdgjshgjjshsj</item>
            <item>25.00</item>
            <item>mac_mall.jpg</item>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item>10</item>
            <item>i-Tunes</item>
            <item>215</item>
            <item>jhgsjhdgjshgjjshsj</item>
            <item>25.00</item>
            <item>mac_mall.jpg</item>
         </return>
      </ns2:returnMerchantsCardsListResponse>
   </soap:Body>
</soap:Envelope>

However when I resubmit request again I get following response everytime I submit request:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:returnMerchantsCardsListResponse xmlns:ns2="http://shoppingcart.abcd.com/">
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
         </return>
         <return>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
         </return>
      </ns2:returnMerchantsCardsListResponse>
   </soap:Body>
</soap:Envelope>

Actually I am expecting the same response when I submit request for the FIRST time. But somehow every time I submit request I get above response without any data. How to get rid of this?

Thank you.

Answer

waprau picture waprau · Dec 8, 2011

My problem is solved. The problem was where the variables, objects were declared. Earlier I declared those variables, objects at class level. I changed and declared the variables, objects within the method, and it worked.

Thank you.