:: how to parse KSOAP ARRAYTPE response :: - java-me

I need some help in understanding how to parse the KSOAP RESPONSE in j2me.
below is the actual ksoap response i get after making a ksoap request.
<AddressArray>
<AddressBin>
<UserSeqID>200</UserSeqID>
<AddressID>115</AddressID>
<ZipCode>10005</ZipCode>
<IsPrimary>false</IsPrimary>
<State>New York</State>
<StateID>37</StateID>
<StateCode>NY</StateCode>
<City>New York Mills village</City>
<CityID>11701</CityID>
<StreetAddress>90 feet rd</StreetAddress>
<NickName>Gym</NickName>
</AddressBin>
<AddressBin>
<UserSeqID>200</UserSeqID>
<AddressID>110</AddressID>
<ZipCode>10002</ZipCode>
<IsPrimary>false</IsPrimary>
<State>New York</State>
<StateID>37</StateID>
<StateCode>NY</StateCode>
<City>New York city</City>
<CityID>11700</CityID>
<StreetAddress>5th Street</StreetAddress>
<NickName>Home</NickName>
</AddressBin>
<AddressBin>
<UserSeqID>200</UserSeqID>
<AddressID>114</AddressID>
<ZipCode>10002</ZipCode>
<IsPrimary>true</IsPrimary>
<State>New York</State>
<StateID>37</StateID>
<StateCode>NY</StateCode>
<City>New York city</City>
<CityID>11700</CityID>
<StreetAddress>4th Street</StreetAddress>
<NickName>Office</NickName>
</AddressBin>
</AddressArray>
here is the ksoap response template
<AddressArray>
<AddressBin>
<UserSeqID>int</UserSeqID>
<AddressID>int</AddressID>
<ZipCode>string</ZipCode>
<IsPrimary>boolean</IsPrimary>
<State>string</State>
<StateID>int</StateID>
<StateCode>string</StateCode>
<City>string</City>
<CityID>int</CityID>
<StreetAddress>string</StreetAddress>
<NickName>string</NickName>
</AddressBin>
<AddressBin>
<UserSeqID>int</UserSeqID>
<AddressID>int</AddressID>
<ZipCode>string</ZipCode>
<IsPrimary>boolean</IsPrimary>
<State>string</State>
<StateID>int</StateID>
<StateCode>string</StateCode>
<City>string</City>
<CityID>int</CityID>
<StreetAddress>string</StreetAddress>
<NickName>string</NickName>
</AddressBin>
</AddressArray>
please let me know how should i map the soap xml respone to custom java classes ?

I don't know how it works in J2ME, but what I did with Android was to run a loop the size of the PropertyCount(which in your case would be the PropertyCount of AddressArray) of the SOAP response, access every individual property of that (your case AddressBin) while in the loop, and then again access every property of that property (your case UserSeqID, AddressID, etc.), put them into a String, parse those to the desired variables and put those variables in a model and put those models in an array.
If you want them to be automatically serialized I can't help you with that because I don't know how that works.
Hope this helps.

Related

Why do I fail to submit data to textarea with python requests.post()

I want to use the requests.post tool to automatically query domain name attribution on this websitea website,But the return value is always empty, I guess it is because the post method failed to transfer the data to the textarea
url = 'http://icp.chinaz.com/searchs'
data = {
'hosts':'qq.com',
'btn_search':'%E6%9F%A5%E8%AF%A2', '__RequestVerificationToken=':'CfDJ8KmGV0zny1FLtrcRZkGCczG2owvCRigVmimqp33mw5t861kI7zU2VfQBri65hIwu_4VXbmtqImMmTeZzqxE7NwwvAtwWcZSMnk6UDuzP3Ymzh9YrHPJkj_cy8vSLXvUYXrFO0HnCb0pSweHIL9pkReY',
}
requests.post(url=url,data=data,headers=headers).content.decode('utf-8')
I'd be very grateful if you could point out where I'm going wrong
I have tried to replace headers and so on.

Error "Failed to construct URI for OData request with request path" SAP Java VDM withQueryParameter

I have create a CAP VDM in java with SAP SDK 3.29.1.
In event handler #On read, i would like to pass the input filters to the VDM.
Es.
#On(event = CdsService.EVENT_READ, entity = "XXXX")
public void readXXX(CdsReadEventContext context) throws ODataException {
final String filter = context.getParameterInfo().getQueryParameter("$filter");
final List<XXXXX> dati = new DefaultXXXService().getAllXXXX().select().withQueryParameter("$filter", filter).executeRequest(dest);
}
When run the query in the log i get the error:
"Failed to construct URI for OData request with request path ..."
"Illegal character in query at index 95. ...."
But the path and filter is right for the call, can you help me?
In the old version sdk i used:
FilterExpression filtriFrontEnd =FilterExpressionConverter.convertTo(queryRequest.getQueryExpression());
final List<XXXX> area = new DefaultXXXXService().getAllXXX().filter(new UncheckedFilterExpression<>(filtriFrontEnd)).select().execute(new ErpConfigContext("XXX"));
Thank you.
When run the query in the log i get the error: "Failed to construct URI for OData request with request path ..." "Illegal character in query at index 95. ...."
Can you check whether the following works for you..?
import com.sap.cloud.sdk.datamodel.odata.client.request.ODataUriFactory;
final String filter = context.getParameterInfo().getQueryParameter("$filter");
final String encodedFilter = ODataUriFactory.encodeQuery(filter);
final List<XXXXX> dati = new DefaultXXXService().getAllXXXX().select().withQueryParameter("$filter", encodedFilter ).executeRequest(dest);
Please let me know, as this could be an issue that needs to be addressed.
The method contract of withQueryParameter which explicitly warns about this API usage:
Using this function to bypass fluent helper method calls can lead to unsupported response handling. There is no contract on the order or priority of parameters added to the query.
Instead please use the filter function directly. There should be an entity field for the postal code, the code should look similar to this:
new DefaultXXXService()
.getAllXXXX()
.filter(Entity.POSTAL_CODE.eq("16100"))
If this is not feasible in your use case I suggest to build this filter expression manually as you did before and apply encoding to it as Alex pointed out in his answer.

SOAP + Zeep + XSD extension

Am interacting with a SOAP service through Zeep and so far it's been going fine, except I hit a snag with regards to dealing with passing values in anything related to an XSD extension.
I've tried multiple ways and am at my wits end.
campaignClient = Client("https://platform.mediamind.com/Eyeblaster.MediaMind.API/V2/CampaignService.svc?wsdl")
listPaging = {"PageIndex":0,"PageSize":5}
fact=campaignClient.type_factory("ns1")
parentType = fact.CampaignIDFilter
subtype=dict(parentType.elements)["CampaignID"] = (123456,)
combined= parentType(CampaignID=subtype)
rawData = campaignClient.service.GetCampaigns(Paging=listPaging,CampaignsFilter=combined, ShowCampaignExtendedInfo=False,_soapheaders=token)
print(rawData)
The context is the following :
this service is to get a list of items and it's possible to apply a filter to it, which is a generic type. You can then implement any type of filter matching that type, here a CampaignIDFilter.
My other attempts failed and the service used to pinpoint incorrect type or such but this way - which I think is on paper sound, gets me a 'something went wrong'.
I'm literraly implementing the solution found here : Creating XML sequences with zeep / python
Here's the service Doc http://platform.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v=3
Cheers
Turns out the right way to get there was to hack around a bit to get the right structure and use of types. The code itself :
objectType = campaignClient.get_type('ns1:CampaignIDFilter')
objectWrap = xsd.Element('CampaignServiceFilter',objectType)
objectValue = objectWrap(CampaignID=123456)
wrapperT = campaignClient.get_type('ns1:ArrayOfCampaignServiceFilter')
wrapper = xsd.Element("CampaignsFilter",wrapperT)
outercontent = wrapper(objectValue)
This ends up generating the following XML :
<soap-env:Body>
<ns0:GetCampaignsRequest xmlns:ns0="http://api.eyeblaster.com/message">
<ns0:CampaignsFilter>
<ns1:CampaignServiceFilter xmlns:ns1="http://api.eyeblaster.com/V1/DataContracts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:type="ns1:CampaignIDFilter">
<ns1:CampaignID>123456</ns1:CampaignID>
</ns1:CampaignServiceFilter>
</ns0:CampaignsFilter>
<ns0:Paging>
<ns0:PageIndex>0</ns0:PageIndex>
<ns0:PageSize>5</ns0:PageSize>
</ns0:Paging>
<ns0:ShowCampaignExtendedInfo>false</ns0:ShowCampaignExtendedInfo>
</ns0:GetCampaignsRequest>
</soap-env:Body>
Much credit to the user here which gave me the boiler plate needed to get this lovecraftian horror to work how to specify xsi:type zeep python

PubNub message format in callbacks

When I get a callback, I get an object passed in. The content of the object seems to have two levels of 'encoding'. It always seems to consist of 3 basic elements:
My data
Timestamp
Channel
in that order so [0]=data, [1] = timestamp and [2] = channel where timestamp and channel are PubNub supplied strings. My data comes in as a JSON object (string, numeric, or object etc.) in the first item returned.
But nowhere can I find in the documentation that this structure (i.e. 3 incoming 'objects') is actually defined. If it is defined then I should be able to map a type or class to it, to better handle it, i.e. cast it to a 'PubNubMessage' class [object data; string timestamp; string channel;]?
Can someone please point me at a document where this message format is actually defined?

Parse attribute of Media Element

I want to parse url attribute from the XML and show image in image control (the one reffered to by the URL) in listbox from the following feed link: http://feeds.bbci.co.uk/news/rss.xml
My code is:
var ComingNewsFromUri = from rss in XElement.Parse(e.Result).Descendants("item")
select new NewsItems
{
Title = rss.Element("title").Value,
PubDate = rss.Element("pubDate").Value,
Description = rss.Element("description").Value
};
For RSS, I would recommend using SyndicationFeed and SyndicationItem....does all the parsing and converting to objects automatically and brilliantly for you.
http://ryanhayes.net/blog/how-to-build-an-rss-feed-reader-in-windows-phone-7part-i-retrieving-parsing-and-displaying-post-titles/
I have an RSS feed app on the store myself using SyndicationFeed and it is very reliable and convenient.
Here is another sample by Microsoft
http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f

Resources