java - OData4j query using basic authentication -
first, let me start saying have got absolutely nothing working odata4j.
i building android app (using eclipse) needs consume odata web service, have ipad app work fine think it's safe the web services ok.
all of web requests require basic authentication work, , able make calls using browser confirm url , credentials using valid.
so far have code:
odataconsumer.builder builder = odataconsumers.newbuilder(url); builder.setclientbehaviors(new basicauthenticationbehavior(loginusername, loginpassword)); odataconsumer c = builder.build(); for(oentity entity : c.getentities("entry").execute()){ system.out.println(entity.getproperty("name").getvalue().tostring()); }
currently, eclipse debugger fails on for
line, presumable during .execute()
call. debugger 0 me, line looks half-relevant in logcat is:
edit: after @johnspurlock's answer, got little further. same problem overall, new error message:
badrequestexception: request uri not valid. since segment 'documents' refers collection, must last seqment in request url. intermediate segments must refer single resource.
there other messages threading - worth noting method being called within asynctask, seem common have threading errors when breaks within asynctask
.
a censored , shortened version of xml result (via browser) looks this:
<feed xml:base="http://a.example.com/odata.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/atom"> <entry> <name>one</name> </entry> <entry> <name>two</name> </entry> </feed>
i have worked out solution.
firstly, john spurlock getting me step in right direction, needed first include correct internet permission in manifest file:
<uses-permission android:name="android.permission.internet" />
then comes problem of querying, problem down lack of understand out how odata structured , queried. when creating odataconsumer
passing full url query, needed pass base .svc
path.
so rather this:
odataconsumer.builder builder = odataconsumers.newbuilder("http://a.example.com/odata.svc/documents");
i did this:
odataconsumer.builder builder = odataconsumers.newbuilder("http://a.example.com/odata.svc");
you specify documents
part when querying entites:
for(oentity entity : c.getentities("documents").execute().tolist()){ }
my original xml cut down, , contains properties elements. @ first thought feed
, entry
elements entities on own had problem when trying query them, infact part of odata magic , seem standard defined elements, these handled automatically odata4j.
each property can queried so:
string myproperty = entity.getproperty("myproperty").getvalue().tostring();
Comments
Post a Comment