|
Blogs
AbstractIn VCD #16 you have seen, amongst others, the REST bot. This short blog wants to explain how he/it works. The blog is devided into the ABAP part and the Google wave part. You may read both or just one of these parts, according your preferences. MotivationIn the last couple of weeks you surely have followed the new trending topics on twitter and SDN: REST and Googlewave. My timeline in these exciting weeks
What else motivation an ABAP enthusiast needs to jump into a new adventure? RESTAs you can see in Daniels blog, SOAP isn't the easiest way of communication between Googlewave and SAP. Therefore my first question was: how did DJ do this? But I didn't ask him, I did ask myself. Last time I've developed a HTTP handler in the SAP ICF was some years ago, so I had to experiment a little bit. But the first handler works quite fast, so my next question was: can be build an universal handler that is able to handle all kind of REST requests? The answer is: yes we can ;) The result you can find in the ABAP part of this blog. REST extremeBrian McKellar 06/27/2004: "I like your idea of addressable data. It will not take long until someone has the handler for /name_of_table/row_key!" (as a comment on DJ's above mentioned Blog) He was quite right... GooglewaveIf you are not familiar with Googlewave yet, you may have a look on Daniels Blog "Starting on Google Wave" About RobotsWave robots are tiny programs written in Java or Python. They interact with the wave nearly as they were human participants. The code is stored as an Google App Engine application on the google server (appspot.com). Advantages:
Disadvantages:
About GadgetsGadgets are XML files which you can embedded into a blib of a wave. Advantages:
Disadvantage:
The ABAP PartThe main goal for our new universal handler class is to handle REST HTTP requests regardless which object type we request and which content-type we expect as response. HTTP request should look like http://host:port/rest/noun/key1/key2/../keyn/verb
The REST handler ClassThe new handler class must implement the interface IF_HTTP_EXTENSION. Method IF_HTTP_EXTENSION~HANDLE_REQUEST: In the ICF tree (transaction SICF) we only have to create a new entry “REST” under /sap/bc, enter the logon data and the new created handler class into the handler list:
(In a productive environment you better create an alias to this service) The REST resolver classesAfter implementing the handler class, you only have to create a class for each object type you want to serve, i.e. the Customer-Class with a method “resolve” and the following interface:
The import parameter “request” contains the object key(s) and the desired method (verb) as last entry. Exporting parameters:
The method “resolve” could looks like:
If you want to serve many objects, you should create an Interface for this method (not part of this blog). The “REST extreme” classJust the code, no comments. There is really no use case for productive usage of this kind of stuff. Just a proof of concept and the right motivation (see above).
The Wave PartThe Google wave part was (for me) the more difficult one: I didn’t want (and still don’t want) to learn Java therefore I had to learn Python. But this was a nice experience! The Robot Creating the robot to answer the simple questions (plain text response) was quite simple, it (or he?) contains just two sections:
The GadgetBut one issue was still open: I have created a resolving class which delivers a PDF response (rest/spool/xyz/getpdf). As I mentioned above, the robot only can handle plain-text responses. “Make a gadget”, a twitter follower advised me. Nice try, but how can I pass parameters to a gadget. I mentioned also, that the robot has no access to the gadget and the gadget cannot read the requesting blip for the parameters. Sleepless nights. One day, I was at my current customer, I’ve got the answer: do we really need a static XML file for the gadget? Quit work, took my motorbike and flew to my home office and tried my idea: it works :) The solution: I simply wrote a BSP (gadget.xml) which has one input parameter: I change my robot a bit the gadget was correctly called by the robot as you can see in the replay of VCD #16. Added part in the robot: ConclusionThese where funny weeks. Have met some new and interesting people, had some great discussions, learned a lot. What’s the next topic? ;-) More to read...
Uwe Fetzer is ABAP addicted since 1991 www.se38.de Add to: del.icio.us | Digg | Reddit
| |||||||||||||||||||||