| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: rpc-example | 
					
						
							|  |  |  | REQUIRES: contrib/http-client contrib/calendar ;
 | 
					
						
							|  |  |  | USING: kernel hashtables xml-rpc xml calendar sequences | 
					
						
							|  |  |  |     arrays math httpd io http-client namespaces ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : functions | 
					
						
							|  |  |  |     H{ { "add" [ + ] } | 
					
						
							|  |  |  |        { "subtract" [ - ] } | 
					
						
							|  |  |  |        { "multiply" [ * ] } | 
					
						
							|  |  |  |        { "divide" [ / ] } } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : apply-function ( name args -- {number} )
 | 
					
						
							| 
									
										
										
										
											2008-12-17 20:17:37 -05:00
										 |  |  |     [ functions hash ] dip first2 rot call 1array ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : problem>solution ( xml-doc -- xml-doc )
 | 
					
						
							|  |  |  |     receive-rpc dup rpc-method-name swap rpc-method-params | 
					
						
							|  |  |  |     apply-function <rpc-response> send-rpc ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : respond-rpc-arith ( -- )
 | 
					
						
							|  |  |  |     "raw-response" get
 | 
					
						
							|  |  |  |     string>xml problem>solution xml>string | 
					
						
							|  |  |  |     put-http-response ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : test-rpc-arith | 
					
						
							| 
									
										
										
										
											2008-06-04 20:54:05 -04:00
										 |  |  |     "add" { 1 2 } <rpc-method> send-rpc | 
					
						
							|  |  |  |     "http://localhost:8080/responder/rpc/" | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     http-post ;
 |