We have a small app with Restlet on the GAE server and GWT and Android clients. Restlet serves GWT-serialized replies to GWT clients and JSON to Android clients.
All is ok with GWT-serialization both locally and on AppEngine production servers.
All is ok with Android (JSON) clients talking to local dev server.
Android taking to production AppEngine server GETs JSON replies, but POST fails. There is no error or warning in logs. The function on server gets called but parameter passed is null.
This is the offending code:
#Post("json")
public void createLocationJSON(Location location) { // location is always null
// do something with 'location'
}
Just to let everybody know: I managed to get GAE+Restlet+JSON+GWT working after much fiddling. The process was really chaotic (reminded me of days programing for the Win32): I was just changing settings until it started working.
The problem that I was having is:
It was serving the wrong representation (JSON, XML, GWT) to the wrong clients. Later it turned out that I had to pay attention to the order of methods inside the class. WTF??
I could not get it to work on sub-path, e.g. /rest/*.
I'm not going to use Restlet for the following reasons (hint to authors):
Documentation is scarce, inaccurate and sometimes contradictory (explaining thing in different ways in different parts of documentation).
Configuration is not standard JAX-RS. I know they have an option to configure it as JAX-RS, but all examples in docs are not based on this.
Since then I switched to Jersey.
You encountered a limitation of GAE that several Restlet users faced.
Some time ago, GAE stopped supporting accepting chunked HTTP entity. We reproduced this issue with both POST and PUT and raw GAE Servlets, so this isn't Restlet related. See GAE issue:
http://code.google.com/p/googleappengine/issues/detail?id=129
The only workaround we found is to not chunk entities, meaning being able to compute their size in advance.
In Restlet 2.1 M3 version that we just released, we added a simple "entityBuffering" property on ClientResource to facilitate this (set to 'false' by default).
We are in the process of upgrading our "First Application" example to illustrate the workaround. We also had to cope with GWT 2.2 breaking compatibility with its previous GWT 2.1 core API, so Restlet 2.1 will only work on GWT.
Addition details are available on this page:
http://wiki.restlet.org/docs_2.1/13-restlet/21-restlet/318-restlet/303-restlet.html
Best regards,
Jerome
Restlet ~ Founder and Technical Lead ~ http://www.restlet.org
Noelios Technologies ~ http://www.noelios.com
Related
I would like to program a WebService embedded on my android device (not the client part).
I've been evaluating Restlet Framework (Restlet) but i don't know if I go on the right way.
What do you think? Is that framework viable for my goal?
Any suggestion is welcome!
Thank you so much!
Regards.
You should check whether Restlet is compliant with android,
not just from server side code, but also from client side code (respectively).
This means for example that every JAR that Restlet framework depends on has to contain code that is compliant with Android.
An alternative approach would be to run a simple HTTP server on your device, for example the following nano http server I read about.
Another interesting project you should check is jetty for android which will hopefully give you support for servlet API as well.
Yes, you will have to spend some time on developing mapping requests and building resource handling logic, but that task is not that difficult:
A. You already have Android code for JSON processing -
For example, look here
B. Using the Java URL object you can analyze the URL of the request and understand which resource you should handle (i.e - add resource to collection, fetch collections, etc).
C. After performing the CRUD operation (i.e - store your resource in some SQLIte table), you can send back a response, and once again, composing JSON if needed is easy.
If a SOAP web service is working well via SoapUI (producing the correct SOAP responses), while building a web service client in Java using different APIs/frameworks to call this web service is facing different issues, is it safe to consider this web service stable and the issues are from the consumer side?
I'm asking a generic question in here, I have already asked a detailed one which is probably too long to read. I'm interested in the concept more than my actual implementation, so if you can answer my question without referring to my longer post, please do.
UPDATE:
I have realized that even if the WSDL is WS-I compliant and it's functioning correctly via SoapUI, this is still not enough to conclude that the web service is not broken. As #jtahlborn said, SoapUI is very tolerant to broken web services, and it could easily trick you to believe your web service is working fine, which is what happened in my case.
I'm constructing the SOAP response in the ESB and my issue was that I used a namespace that was defined in the WSDL but not in the schema. SoapUI received the response and showed it to me (with the wrong namespace); this issue could have been avoided if I turned on the response validation option.
It's also noteworthy to mention that in the Java web service client I created to test my web service, the response could not be loaded into the output object (a NullPointerException error showed up when I tried to access the output object), this was due to the namespace issue and it started working correctly once I fixed the namespace.
SoapUI is a fantastic product. one of the things which makes it a great product, however, is that it is very tolerant of poorly defined webservices. in our product, we deal with lots of webservices, and a frequent comment on an issue in our product is "it works fine in SoapUI". we have learned the hard way that SoapUI will tolerate all kinds of broken webservices. so, in summary, working with SoapUI is not a proof that your webservice is well-defined.
There are WS-I testing tools to check your web service for conformance to the Web Services Interoperability profiles. If your service adheres to the WS-I basic profile, and SoapUI can call it, the issues are definitely on the consumer side.
EDIT: well, or in between the both...
SoapUI can check your wsdl for WS-I compliance, see http://www.soapui.org/SOAP-and-WSDL/working-with-wsdls.html.
It's most likely that the consumer (client) is buggy... If the client is generated using wsdl2java it's a big chance to have bugs in it... and if you are using some special functionalities that are valid (conforming w3c) then don't be surprised... the generated clients sometimes do this... even some libraries used to generate java classes or libraries to generate the webservices are full of bugs...
A lot of things are not supported by known and frequently used libraries... (I don't want to give names -- but wsdl4java is not perfect)..
If you are using security or something ... higher chances to have bugs on both server and client side :)
maybe if you tell us what is the problem we can help you...
So here it is that BlazeDS will totally play on GAE
BlazeDS Version: 3.2.0.3978 Status:
COMPATIBLE To workaround an
EMFException thrown by
flex.messaging.io.amf.AbstractAmfInput,
follow Martin Zoldano's workarounds at
http://martinzoldano.blogspot.com/2009/04/appengine-adobe-blazeds-fix.html.
You will need to enable sessions to
get BlazeDS working.
But I wonder does it mean that messages from the server to the client, server push notifications from BlaseDS (I mean we connect to server from flex client but do not require data and server sends data to us when it wants), and BTW does any one know where to get a tutorial on doing that (Flex + BlazeDS)?
Are there any more features of Blaze v 3.2 that are under question?
well i recently try a flex-blazeds app on google plattform and it doesnt works. I found a guide that fix blazeds to run on gae, u should try it. For a basic tutorial of messaging-services in blazeds u should look a this asotto.blogspot.com/ ,
Messaging does not work, unless if you are lucky enough to have all the consumers/producers registered on the same machine (highly improbable when you have a decent traffic).
If you want to understand why, you need to read the developer guide, clustering sections. Basically the whole pub/sub graph+messages queues is kept distributed on the cluster, and the machines are using JGROUPS for communication.
Obviously, it will not work on GAE (the machines allocated by Google will don't know one of each other, and you can lose messages).
With the official implementation of BlazeDS version 4 you have duplicated session problems, because of the GAE clustering mechanism.
I'm interested in building a Google Web Toolkit (GWT) application that will run on the Google App Engine (GAE). I'd also like to expose a web service that shares the same datastore and can receive posted data from a different web application hosted elsewhere.
Would using Restlet be a good solution, or is there a simpler approach that doesn't require the use of a 3rd party library? Is there some way for the GWT client to accepted json that can then be serialised over GWT-RPC to the GAE datastore? Do I need to write a servlet that can parse and persist jsonp?
I suspect my thinking may be a bit muddled here... any assistance is appreciated!
As per http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine
Restlet
Version(s): 2.0 M5 +
Status: COMPATIBLE
The team has created an adaptation of Restlet just for App Engine.
See http://wiki.restlet.org/developers/172-restlet/251-restlet.html for instructions on tuning a standard installation of Restlet for App Engine.
Here's another blog post from the team about Restlet: http://blog.noelios.com/2009/04/11/restlet-in-the-cloud-with-google-app-engine/
GWT has native support for JSON, You just need a library on the server to parse/create JSON. (GWT JSON Sample)
GAE uses Servlets, so any Servlet would do if you wanted to go that route. There is nothing to say that your client needs to be GWT.
You can use the persistence JDO, JPA or Raw APIs for persistence, They are a little tricky and not that clearly documented (it is complex).
See these articles for a clear explanation and sample code:
http://www.ibm.com/developerworks/java/library/j-gaej1/
http://www.ibm.com/developerworks/java/library/j-gaej2/index.html
http://www.ibm.com/developerworks/java/library/j-gaej3.html
I am very new to creating webservers - and I have had several goes at trying to understand them and write a quick webserver, but it's never quite 'clicked'. At the moment I am under the impression that REST would be most suitable for my purposes (I will explain later).
Can anyone either show me a basic code example in Java (using Tomcat Apache) or a tutorial resource to show how a webserver:
Can be used for security - i.e. pass in some kind of value to identify the client - from their the webserver will either deny or grant access to the client dependant on some criteria - maybe a lookup list.
Once the client is successfully accepted they will be allowed to pass in some more values to the webserver that will be used to write a row in a database table.
Many thanks.
PS - I would have thought there might have been soemthing that comes with Eclipse Ganymede? If someone can confirm?
The best way to write restful resources in Java is via the JAX-RS standard. So I'd recommend you download Jersey which is the JAX-RS reference implementation and check out its examples; its got lots of them. Take an example for a spin then try hacking it to do what you like.
BTW JAX-RS can be run inside any Servlet engine - you just build a WAR and deploy it (there are examples in the Jersery samples) - though Jersey also comes with a small lightweight web server you can use too which is a little easier to use - again there are examples in the distro of this.
I would also suggest that you look at Restlet