[infinispan-commits] Infinispan SVN: r2292 - trunk/server/rest/src/main/resources.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Sep 1 06:54:54 EDT 2010
Author: manik.surtani at jboss.com
Date: 2010-09-01 06:54:54 -0400 (Wed, 01 Sep 2010)
New Revision: 2292
Modified:
trunk/server/rest/src/main/resources/sample_python_REST_client.py
trunk/server/rest/src/main/resources/sample_ruby_REST_client.rb
Log:
Updated sample REST scripts
Modified: trunk/server/rest/src/main/resources/sample_python_REST_client.py
===================================================================
--- trunk/server/rest/src/main/resources/sample_python_REST_client.py 2010-09-01 10:52:21 UTC (rev 2291)
+++ trunk/server/rest/src/main/resources/sample_python_REST_client.py 2010-09-01 10:54:54 UTC (rev 2292)
@@ -8,21 +8,32 @@
## Your Infinispan WAR server host
hostname = "localhost:8080"
+webapp_name = "infinispan-server-rest"
+cache_name = "___defaultcache"
+key = "my_key"
#putting data in
-conn = httplib.HTTPConnection(hostname)
-data = "SOME DATA HERE !" #could be string, or a file...
-conn.request("POST", "/infinispan/rest/Bucket/0", data, {"Content-Type": "text/plain"})
-response = conn.getresponse()
-print response.status
+print "Storing data on server %s under key [%s] over REST" % (hostname, key)
+try:
+ conn = httplib.HTTPConnection(hostname)
+ data = "This is some test data." #could be string, or a file...
+ conn.request("POST", "/%s/rest/%s/%s" % (webapp_name, cache_name, key), data, {"Content-Type": "text/plain"})
+ response = conn.getresponse()
+ print "HTTP status: %s" % response.status
+except:
+ print "Unable to connect to the REST server on %s. Is it running?" % hostname
#getting data out
-import httplib
-conn = httplib.HTTPConnection(hostname)
-conn.request("GET", "/infinispan/rest/Bucket/0")
-response = conn.getresponse()
-print response.status
-print response.read()
+print "Retrieving data from server %s under key [%s]" % (hostname, key)
+try:
+ conn = httplib.HTTPConnection(hostname)
+ conn.request("GET", "/%s/rest/%s/%s" % (webapp_name, cache_name, key))
+ response = conn.getresponse()
+ print "HTTP status: %s" % response.status
+ print "Value retrieved: %s" % response.read()
+except:
+ print "Unable to connect to the REST server on %s. Is it running?" % hostname
-## For more information on usagse see http://www.jboss.org/community/wiki/InfinispanRESTserver
+## For more information on usage see http://community.jboss.org/wiki/InfinispanRESTserver
+
Modified: trunk/server/rest/src/main/resources/sample_ruby_REST_client.rb
===================================================================
--- trunk/server/rest/src/main/resources/sample_ruby_REST_client.rb 2010-09-01 10:52:21 UTC (rev 2291)
+++ trunk/server/rest/src/main/resources/sample_ruby_REST_client.rb 2010-09-01 10:54:54 UTC (rev 2292)
@@ -11,31 +11,28 @@
http = Net::HTTP.new('localhost', 8080)
#Create new entry
-http.post('/infinispan/rest/MyData/MyKey', 'DATA HERE', {"Content-Type" => "text/plain"})
+http.post('/infinispan-server-rest/rest/___defaultcache/MyKey', 'DATA HERE', {"Content-Type" => "text/plain"})
#get it back
-puts http.get('/infinispan/rest/MyData/MyKey').body
+puts http.get('/infinispan-server-rest/rest/___defaultcache/MyKey').body
#use PUT to overwrite
-http.put('/infinispan/rest/MyData/MyKey', 'MORE DATA', {"Content-Type" => "text/plain"})
+http.put('/infinispan-server-rest/rest/___defaultcache/MyKey', 'MORE DATA', {"Content-Type" => "text/plain"})
#and remove...
-http.delete('/infinispan/rest/MyData/MyKey')
+http.delete('/infinispan-server-rest/rest/___defaultcache/MyKey')
-#Create binary data like this... just the same...
-http.put('/infinispan/rest/MyImages/Image.png', File.read('/Users/michaelneale/logo.png'), {"Content-Type" => "image/png"})
-
#and if you want to do json...
require 'rubygems'
require 'json'
#now for fun, lets do some JSON !
data = {:name => "michael", :age => 42 }
-http.put('/infinispan/rest/Users/data/0', data.to_json, {"Content-Type" => "application/json"})
+http.put('/infinispan-server-rest/rest/___defaultcache/MyKey', data.to_json, {"Content-Type" => "application/json"})
puts "OK !"
-## For more information on usagse see http://www.jboss.org/community/wiki/InfinispanRESTserver
+## For more information on usagse see http://community.jboss.org/wiki/InfinispanRESTserver
More information about the infinispan-commits
mailing list