Difference between revisions of "Xebra Create XML-RPC Webapp"

 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Xebra]]
 
[[Category:Xebra]]
 +
[[Xebra About|About]] | [[Xebra Installation|Installation]] |  [[Xebra Documentation|Documentation]] |  [[Xebra Tutorial|Tutorials]] | [[Xebra FAQ|Frequently Asked Questions]]
 +
  
 
* Create a new file ''demo.xrpc'' in the webapp directory. On translation, this will generate a xml-rpc servlet class.
 
* Create a new file ''demo.xrpc'' in the webapp directory. On translation, this will generate a xml-rpc servlet class.
  
 
<xml>
 
<xml>
<xrpc:api class="MY_XMLRPC_API" namespace="demo">
+
<xrpc:api namespace="demo">
 +
  <page:controller class="MY_XMLRPC_API" />
 
   <xrpc:method name="sum" />
 
   <xrpc:method name="sum" />
 
   <xrpc:method name="hello" />
 
   <xrpc:method name="hello" />
Line 22: Line 25:
  
 
hello (a_name: STRING): STRING
 
hello (a_name: STRING): STRING
 +
                        -- Prints hello.
 
require
 
require
 
a_name_attached: attached a_name
 
a_name_attached: attached a_name
 
not_a_name_is_empty: not a_name.is_empty
 
not_a_name_is_empty: not a_name.is_empty
 
do
 
do
Result := "Hello there " + a_name.string
+
Result := "Hello there " + a_name
 
end
 
end
  
sum (i, j: NATURAL_16): INTEGER
+
sum (a_i, a_j: NATURAL_16): INTEGER
-- XML-RPC using Eiffel types.
+
-- Returns the sum of a_i and a_j
 
do
 
do
Result := (i + j).as_integer_32
+
Result := (a_i + a_j).as_integer_32
 
end
 
end
 
end
 
end
 
</e>
 
</e>
  
* Run the server and browse to http://localhost:55000/yourwebapp/demo.xrpc. After the webapp has been translated, compiled and run you should see a page saying ''invalid method''. That is because you tried to make an xml-rpc call with a GET request. Only POST is allowed, though.
+
* Run the server and browse to http://localhost:55000/yourwebapp/demo.xrpc. After the webapp has been translated, compiled and run you should see a page saying ''invalid method''. This is because you tried to make an xml-rpc call with a GET request. Only POST is allowed, though.
  
 
* To make an actual xml-rpc call you can use python. Run:
 
* To make an actual xml-rpc call you can use python. Run:
Line 45: Line 49:
 
>>> s=xmlrpclib.ServerProxy("http://localhost:55000/yourwebapp/demo.xrpc")
 
>>> s=xmlrpclib.ServerProxy("http://localhost:55000/yourwebapp/demo.xrpc")
 
>>> s.demo.sum(4,5)
 
>>> s.demo.sum(4,5)
>>> s.math.hello("Gerhard")
+
>>> s.demo.hello("Gerhard")
 
</c>
 
</c>

Latest revision as of 09:09, 11 July 2009

About | Installation | Documentation | Tutorials | Frequently Asked Questions


  • Create a new file demo.xrpc in the webapp directory. On translation, this will generate a xml-rpc servlet class.
<xrpc:api namespace="demo">
  <page:controller class="MY_XMLRPC_API" />
  <xrpc:method name="sum" />
  <xrpc:method name="hello" />
</xrpc:api>
  • Now go into estudio and create a new class MY_XMLRPC_API:
class
	MY_XMLRPC_API
 
inherit
	XWA_XRPC_API
 
feature -- Basic operations
 
	hello (a_name: STRING): STRING
                        -- Prints hello.
		require
			a_name_attached: attached a_name
			not_a_name_is_empty: not a_name.is_empty
		do
			Result := "Hello there " + a_name
		end
 
	sum (a_i, a_j: NATURAL_16): INTEGER
			-- Returns the sum of a_i and a_j
		do
			Result := (a_i + a_j).as_integer_32
		end
end
  • Run the server and browse to http://localhost:55000/yourwebapp/demo.xrpc. After the webapp has been translated, compiled and run you should see a page saying invalid method. This is because you tried to make an xml-rpc call with a GET request. Only POST is allowed, though.
  • To make an actual xml-rpc call you can use python. Run:
>>> import xmlrpclib
>>> s=xmlrpclib.ServerProxy("http://localhost:55000/yourwebapp/demo.xrpc")
>>> s.demo.sum(4,5)
>>> s.demo.hello("Gerhard")