msootani / ksoap2-android

Automatically exported from code.google.com/p/ksoap2-android
0 stars 0 forks source link

Casting Issue from soap object to custom class #193

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Query standard SAP soap service which returns nested response (complex 
response) with objects within objects

What is the expected output? What do you see instead?
the soap object to be casted to registered classes but casting error is thrown

What version of the product are you using? On what operating system?
KSOAP for android 3.3.0

Please provide any additional information below.

// response structure

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header/>
    <soap-env:Body>
        <n0:PurchaseOrderItemByAccountAssignmentResponse_sync xmlns:n0="http://sap.com/xi/SAPGlobal20/Global" xmlns:prx="urn:sap.com:proxy:QAS:/1SAI/TAS971671B0D287293D2CB5:701:2009/02/10">
            <PurchaseOrder>
                <ID>4502000232</ID>
                <ProcessingTypeCode>Z202</ProcessingTypeCode>
                <CancelledIndicator>false</CancelledIndicator>
                <PurchaseOrderDate>2011-01-25</PurchaseOrderDate>
                <CreationDate>2011-03-12</CreationDate>
                <CreationUserAccountID>AKARIM</CreationUserAccountID>
                <PurchasingOrganisationParty>
                    <InternalID>1501</InternalID>
                </PurchasingOrganisationParty>
                <PurchasingGroupParty>
                    <InternalID>IM1</InternalID>
                </PurchasingGroupParty>
                <SellerParty>
                    <InternalID>200001804</InternalID>
                </SellerParty>
                <BillFromParty>
                    <InternalID>200001804</InternalID>
                </BillFromParty>
                <Item>
                    <ID>10</ID>
                    <ProcessingTypeCode>0</ProcessingTypeCode>
                    <Quantity unitCode="EA">1.0</Quantity>
                    <PlantID>MM01</PlantID>
                    <Description languageCode="EN">membership certificate</Description>
                    <ProductCategory>
                        <InternalID>108</InternalID>
                    </ProductCategory>
                    <AccountAssignment>
                        <Quantity>1.0</Quantity>
                        <Percent>0.0</Percent>
                        <GeneralLedgerAccountID>7100510</GeneralLedgerAccountID>
                        <ProfitCentreID>15003000000000</ProfitCentreID>
                        <CostCentreID>15003010000100</CostCentreID>
                    </AccountAssignment>
                    <Price>
                        <TotalAmount currencyCode="USD">550.0</TotalAmount>
                        <NetPrice>
                            <Amount currencyCode="USD">550.0</Amount>
                            <BaseQuantity unitCode="EA">1.0</BaseQuantity>
                        </NetPrice>
                    </Price>
                </Item>
            </PurchaseOrder>
            <PurchaseOrder>
                <ID>4502000237</ID>
                <ProcessingTypeCode>Z202</ProcessingTypeCode>
                <CancelledIndicator>false</CancelledIndicator>
                <PurchaseOrderDate>2011-01-17</PurchaseOrderDate>
                <CreationDate>2011-03-12</CreationDate>
                <CreationUserAccountID>MMRIZWAN</CreationUserAccountID>
                <PurchasingOrganisationParty>
                    <InternalID>1501</InternalID>
                </PurchasingOrganisationParty>
                <PurchasingGroupParty>
                    <InternalID>IG1</InternalID>
                </PurchasingGroupParty>
                <SellerParty>
                    <InternalID>200000535</InternalID>
                </SellerParty>
                <BillFromParty>
                    <InternalID>200000535</InternalID>
                </BillFromParty>
                <Item>
                    <ID>10</ID>
                    <ProcessingTypeCode>0</ProcessingTypeCode>
                    <Quantity unitCode="EA">1.0</Quantity>
                    <PlantID>MM01</PlantID>
                    <Description languageCode="EN">ONE PAIL ANDEROL 500</Description>
                    <ProductCategory>
                        <InternalID>108</InternalID>
                    </ProductCategory>
                    <AccountAssignment>
                        <Quantity>1.0</Quantity>
                        <Percent>0.0</Percent>
                        <GeneralLedgerAccountID>7500160</GeneralLedgerAccountID>
                        <ProfitCentreID>15003000000000</ProfitCentreID>
                        <CostCentreID>15003010000100</CostCentreID>
                    </AccountAssignment>
                    <Price>
                        <TotalAmount currencyCode="USD">520.0</TotalAmount>
                        <NetPrice>
                            <Amount currencyCode="USD">520.0</Amount>
                            <BaseQuantity unitCode="EA">1.0</BaseQuantity>
                        </NetPrice>
                    </Price>
                </Item>
            </PurchaseOrder>
        </n0:PurchaseOrderItemByAccountAssignmentResponse_sync>
    </soap-env:Body>
</soap-env:Envelope>

// Class Structure

public class PurchaseOrder implements KvmSerializable 
{

    private String ID;
    private String ProcessingTypeCode;
    private String CancelledIndicator;
    private Date PurchaseOrderDate;
    private Date CreationDate;
    private String CreationUserAccountID;
    private PurchasingOrganisationParty PurchasingOrganisationParty;
    private SellerParty SellerParty;
    private PurchasingGroupParty PurchasingGroupParty;
    private BillFromParty BillFromParty;
    private Item[] Item1;

// all getter setter methods implemented

}

public class PurchasingOrganisationParty implements KvmSerializable 
{
    private String InternalID;
// all getter setter methods implemented
}

public class SellerParty implements KvmSerializable 
{
    private String InternalID;

// all getter setter methods implemented
}

public class PurchasingGroupParty implements KvmSerializable 
{
    private String InternalID;

// all getter setter methods implemented

}

public class BillFromParty implements KvmSerializable 
{
    private String InternalID;
// all getter setter methods implemented
}

public class Item implements KvmSerializable {

    private String ID;
    private String ProcessingTypeCode;
    private String Quantity;
    private String PlantID;
    private String Description;
    private RequesterParty RequesterParty;
    private Product Product;
    private ProductCategory ProductCategory;
    private AccountAssignment AccountAssignment;
    private Price Price;

}

public class RequesterParty implements KvmSerializable {

    private String InternalID;

}

public class Product implements KvmSerializable {

    private String InternalID;

}

public class ProductCategory implements KvmSerializable {

    private String InternalID;

}

public class AccountAssignment implements KvmSerializable {

    private String Quantity;
    private String Percent;
    private String GeneralLedgerAccountID;
    private String ProfitCentreID;
    private String CostCentreID;

}

public class Price implements KvmSerializable {

    private String TotalAmount;
    private NetPrice NetPrice;

}

public class NetPrice implements KvmSerializable {

    private String Amount;
    private String BaseQuantity;

}

// code on the client side to produce the request and get complex response

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

PurchaseOrderItemSelectionByAccountAssignment selectionvar = new 
PurchaseOrderItemSelectionByAccountAssignment("15003010000100");

request.addProperty("PurchaseOrderItemSelectionByAccountAssignment", 
selectionvar);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

androidHttpTransport.debug = true;

List <HeaderProperty> headerPropertyList = new ArrayList<HeaderProperty>();

headerPropertyList.add(new HeaderProperty("Authorization", "Basic 
badasdasdaNadasdaAxNA=="));

try {

    androidHttpTransport.call(SOAP_ACTION, envelope,headerPropertyList);

    envelope.addMapping(NAMESPACE, "PurchasingOrganisationParty", PurchasingOrganisationParty.class);
    envelope.addMapping(NAMESPACE, "PurchasingGroupParty", PurchasingGroupParty.class);
    envelope.addMapping(NAMESPACE, "SellerParty", SellerParty.class);
    envelope.addMapping(NAMESPACE, "BillFromParty", BillFromParty.class);
    envelope.addMapping(NAMESPACE, "AccountAssignment", AccountAssignment.class);
    envelope.addMapping(NAMESPACE, "RequesterParty", RequesterParty.class);
    envelope.addMapping(NAMESPACE, "Product", Product.class);
    envelope.addMapping(NAMESPACE, "ProductCategory", ProductCategory.class);
    envelope.addMapping(NAMESPACE, "NetPrice", NetPrice.class);
    envelope.addMapping(NAMESPACE, "Price", Price.class);
    envelope.addMapping(NAMESPACE, "Item", Item.class);
    envelope.addMapping(NAMESPACE, "PurchaseOrder", PurchaseOrder.class);

    SoapObject po1 = (SoapObject) envelope.bodyIn;

    // casting error on the line below on accessing po1.get(0).getProperty(0)
    lblResult.setText("Total PO: "+ po1.getProperty(0).toString() + ": First PO: " + po1.get(0).getProperty(0));

}

I am not able to cast the response to the required purchase order class i guess 
it is some bug but i want to reconfirm is it my coding error or soemthing else 

regards,

Original issue reported on code.google.com by mubeenma...@gmail.com on 11 Jun 2014 at 10:47

GoogleCodeExporter commented 9 years ago
Hi The way i handle complex objects is as below snipplet. You can do nested for 
for every object, i have commited some changes to ksoap, and i will try to see 
the chances to implement something like this. but in the meantime you might 
want to check this approach.

PurchaseOrder responseArray[] = null;
    SoapObject _client = new SoapObject("", "soapMethod");
    SoapSerializationEnvelope _envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    _envelope.bodyOut = _client;
    KeepAliveHttpTransportSE _ht = new KeepAliveHttpTransportSE(JIRA_SERVER_URL, TIMEOUT, BUFFER_SIZE);
    _ht.call("", _envelope);

    Vector arr = (Vector) _envelope.getResponse();

    responseArray = new PurchaseOrder[arr.size()];

    for ( int i = 0; i < arr.size(); i++ ) {
        SoapObject _soapObject = (SoapObject)arr.get( i );

        int _len = _soapObject.getPropertyCount();
        PurchaseOrder _singleObject = new PurchaseOrder();
        for (int _i = 0; _i < _len; _i++) {
            _singleObject.setProperty(_i, _soapObject.getProperty(_i));
        }

        responseArray[i] = _singleObject;
    }

Original comment by jose.cas...@gmail.com on 13 Aug 2014 at 1:23

GoogleCodeExporter commented 9 years ago
The project is migrating to github. If you believe this issue is still valid 
and should be tracked please file a new issue at 
https://github.com/simpligility/ksoap2-android/issues

Original comment by mosa...@gmail.com on 7 Aug 2015 at 5:35