Is there a good HttpClient library for J2ME/MIDP? - rest

I want to call some RESTful web services from a J2ME client running on a MIDP enabled mobile device. I read the MIDP api for HTTPConnections and thought this is just crying out for a simple wrapper to hide all those unpleasant byte arrays and such like. Before I write my own I wondered whether there was a good open source library already available.
-FE-

You might want to check out this little gem, Mobile Ajax for Java ME:
https://meapplicationdevelopers.java.net/mobileajax.html
One part is (from the site):
Asynchronous I/O for Java ME
This library provides the equivalent
of XmlHttpRequest for Java ME with
some additional functionality useful
for invoking RESTful web services.
It is layered on top of the
com.sun.me.web.path library. Features
include -
* Asynchronous versions of HTTP Get and Post
* HTTP Basic Authentication
* Multipart MIME (sender only)
* Progress listeners

LWUIT 1.5 now includes classes for accessing REST, using OAuth2, JSON, etc.

I don't know of any such library, but found some succinct examples of accessing various RESTful web services

We ended up writing our own simple wrapper api for a variety of reasons not the least of which was the fact that the Sony Ericsson K750 that we were developing for had a weird bug (that SE refused to fix) where if you tried to get/use a connection when the device was off network, more than about 20 times, the internal connection pool would get hosed and never recover unless you restarted the app.

Related

can we create a web service using objective c

In my iphone application I am calling (by SOAP post method) a web service which is written in .net and hosted on a server, and its all working fine. But my doubt is, can we write a web service in objective c? And host it on a server? so that we should be able to access it from any of the platforms like .net, php and objectiveC.
I read a fantastic tutorial regarding this question some time ago here.
To be honest, it can be quite difficult to really use this in a productive environment. If you want to get all the features and tools Apple gives to you (what seems to be the intention of your question), you'll have to use a Mac in order to run your service afterwards.
In my opionion using PHP for example (if you need a db also backed up by MySQL) is much easier. Almost all hosters support it and you won't have to worry about setting up a bunch of macs and connecting them via solid and stable cables to the internet (and with that: guarantee availability).
Yes. A web service is just some application that can provide a service over the web. As you can create an application in Objective C, it can be a web service the same as made in any other language.
You can make it run on any server where you have an objective C compiler, however, the framework you use may restrict your choices to the server (ie, you can write objective C on windows, but you wouldn't be able to use the NS framework)
Web services are not limited to a programming language, however you do need to find if there is any framework using objective-c can run on specific server. For example, iiS allows you to use Asp.net which could be implemented using C# or VB.Net.
From the clients who will consume web services, they don't have to be a specific type of device. I think that's the point of web services. The messages travel in between is formatted. For example, a SOAP message is using xml, and that would ensure the message travel on HTTP. Therefore no matter you use iPhone or Android or Blackberry, you should have no problem to make web service calls.
So in general, I think you have to see what kind of web services you want to create, and then see if Apple(I assume) can provide you with a good framework to do it. In terms of client side, as long as your web services are using XML or JSON, it should be well supported.
Hope it helps.

searching for a working GWT RPC library

im searching for a GWT-RPC lib for the client side to communicate with a zend framework php server
thus rpc like json, xml or rest would be interesting
all i find are projects which have been stuck in years 2007/08 which dont seem to work anymore
so is there anyone who can suggest a working library?
thx
As far as I know nobody has built a GWT-RPC to communicate with a non-Java server, to allow you to have the automatic object sharing between client (written in Java) and server (written in non-Java) that GWT-RPC provides.
Luckily, GWT provides a mechanism for communicating with a server in regular JSON, using RequestBuilder. See this link for more information about making regular HTTP requests in GWT.

[iPhone and Web Services]: REST vs SOAP

I've started my degree project, a mobile application suitable for iPhone, Android and (in the near future) Symbian. The server architecture is the following:
web site (for "standard" users);
web service (for mobile connections), based on TomCat and Axis2;
mySQL DB to storage users data.
Surfing across the web, I've read a lot of discussion about the interaction between the iPhone and Web Services, and I've to say that I've not a clear idea of what I can do and what not.
Let's start from the protocol used to retrieve data from the DB: the Android-side application uses SOAP protocol, can I do the same with iPhone? Are there some limitations or problems?
I have also read about the using of REST instead of SOAP, could it be possible with the server architecture described above? Which are the main advantages/disadvantages?
Sorry if these questions sound "n00b", but it's my first real experience with iPhone and the lot of informations found on the web messed up my mind and I'm scared to be confused. Forgive me for any error.
SOAP is simply too heavy for mobile communications. Why do all the work to wrap requests in an additional XML layer you'll have to parse? You send more data than you need to, and impose greater CPU burden on client and server.
Use REST. If you are doing a cross-platform project JSON makes a great payload container, otherwise plists work well for sending data from the server.
You can definitely do SOAP on the iPhone. Here is a nice tutorial on the subject. After all, SOAP is a HTTP based protocol and you have all the libraries you need to do HTTP on the iPhone.
Having said that, RESTful APIs are simpler than SOAP, so you might want to consider them. They're also HTTP based so you won't have any problems on doing that on iPhone. On the server side, if you use Java, you will have to use JAX-RS to implement that part.
Hope it helps.
Google Buffers
If your looking for a language and platform agnostic solution have a look at Google Buffers. You can easily serialise objects for transmission over the wire.
This question should get you started in Objective-C.
JSON
I have also used JSON within iPhone Apps with great success. Again, relatively language and platform agnostic but much simpler than Google Buffers.
SOAP with Fast Infoset is suited for small devices:
JAX-WS 2.0 and its reference implementation support both Fast Infoset and MTOM/XOP. This article includes information about Web Service Performance for Fast Infoset vs. MTOM/XOP:
http://www.devx.com/xml/Article/35385/1954
Fast Infoset is optimized for small
devices that have bandwidth
constraints, and is supported by many
vendors such as Microsoft .NET and
.NET CF, Sun GlassFish, BEA WebLogic,
IBM SDK for Java 6.0 and others.
http://en.wikipedia.org/wiki/Fast_Infoset

Code for syncing the iPhone with REST-servers

is there any open source code for syncing an iPhone
with a server (preferably REST)?
Found nothing on github and google code.
Regards...
I have been working with a project called ObjectiveResource (Github project here: http://github.com/yfactorial/objectiveresource/tree/master), which is focused mainly on the communication layer between your iphone models and a REST based web service. It is targeted at rails applications but should work with any REST api. Part of that project is a more sync oriented solution that is still in early development, but which has been discussed quite a bit lately in the objective resource google group at http://groups.google.com/group/objectiveresource?hl=en.
I highly recommend objective resource, I've been using it along with sqlitepersistenobjects to handle sync on my iphone project.
I suggest using the excellent ASIHTTPRequest source from All-Seeing Interactive: http://allseeing-i.com/ASIHTTPRequest. I'm doing this, and so are several released iPhone apps, so you can be sure the code is pretty solid.
This is a wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier. It is written in Objective-C and works in both Mac OS X and iPhone applications.
It is suitable for performing basic HTTP requests and interacting with REST-based services (GET / POST / PUT / DELETE). The ASIFormDataRequest subclass makes it easy to submit POST data and files using multipart/form-data.
I've used Adrian Kosmaczewski's iPhone Rest Wrapper with success. See also this SO question.
I would recommend checking out RestKit: http://restkit.org/ It provides an excellent API for accessing RESTful web services and representing the remote resources as local objects, including persisting them to Core Data.

What common backend can be accessed securely from an iPhone and Android application?

I'm thinking about creating an application for the iPhone and Android that will need to access a common backend to retrieve account information. Can both access a web service over https? What other way would allow me to have one interface to the backend that is accessible by both?
They both work over http and https which is a common enough protocol. I would suggest you go with a RESTful web service so you expose your service via URI's like http://www.myservice.com/weather/zip/98007 which would return an XML blob that can be parsed by the client.
if you are starting from nothing, i'd definitely go with RESTful service that returns/accepts JSON... there are plenty of libraries for both platforms that will accept JSON and turn it into arrays and dictionaries.
I'd recommend using a RESTful web service backend, which is all standard HTTP and/or HTTPS. If you can use Ruby on Rails, its default scaffolding will get you about 99% of the way there and for the iPhone there is an open source project called ObjectiveResource that will automate your communication with this Rails backend. I haven't investigated yet what options are available on Android but since it is all simple HTTP it should be straightforward. I am not the maintainer of ObjectiveResource but I have contributed some code. You can check it out here:
http://iphoneonrails.com
One good approach I have seen used with other services is to write the backend in such a way that it can feed data back in different types - for Android an XML response is best, but for the iPhone sending back plist data is preferred (though it can also work with XML if required). In both cases it's easier to simply POST updates back to the server than to wrap an update in XML.
Both platforms should be able to use whatever form of authentication you wish to use, the iPhone I know supports all methods of HTTP authentication.