Changeset 499
- Timestamp:
- 04/13/07 16:25:16 (1 year ago)
- Files:
-
- trunk/docroot/jsonrpclab/json.rpc.Client.js (modified) (1 diff)
- trunk/docroot/jsonrpclab/testBuddyQuoteService.php (modified) (2 diffs)
- trunk/src/main/php/_test/BuddyQuoteService.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/service/jsonrpc (added)
- trunk/src/main/php/net/stubbles/service/jsonrpc/util (added)
- trunk/src/main/php/net/stubbles/service/jsonrpc/util/stubJsonRpcProxyGenerator.php (added)
- trunk/src/main/php/net/stubbles/websites/processors/stubJsonRpcProcessor.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docroot/jsonrpclab/json.rpc.Client.js
r480 r499 47 47 } 48 48 49 var postUrl = this.serviceURL +'?processor=jsonrpc';49 var postUrl = this.serviceURL; 50 50 var jsonRpcReq = { 51 51 'method': classAndMethod, trunk/docroot/jsonrpclab/testBuddyQuoteService.php
r481 r499 8 8 <script type="text/javascript" src="json.js"></script> 9 9 <script type="text/javascript" src="json.rpc.Client.js"></script> 10 <script type="text/javascript" src="<?php echo dirname($_SERVER['PHP_SELF']);?>/jsonrpc.php?processor=jsonrpc&__generateProxy=true"></script> 10 11 <script type="text/javascript"> 11 12 // This will later be generated13 function BuddyQuoteService(clientObj) {14 this.dispatcher = new stubbles.json.rpc.Client(clientObj, '<?php echo dirname($_SERVER['PHP_SELF']);?>/jsonrpc.php');15 }16 17 BuddyQuoteService.prototype = {18 getQuote: function() {19 return this.dispatcher.doCall('BuddyQuoteService.getQuote', arguments);20 }21 }22 23 24 // This is application code...25 12 var callbackObj = { 26 13 callback__getQuote: function(id, result, error) { 14 alert(result); 15 }, 16 callback__getReversedQuote: function(id, result, error) { 27 17 alert(result); 28 18 } … … 36 26 Quote (0-6) <input type="text" id="quoteId" size="3"/> 37 27 <input type="button" onclick="bq.getQuote(document.getElementById('quoteId').value);" value="Get the quote!"/> 28 <input type="button" onclick="bq.getReversedQuote(document.getElementById('quoteId').value);" value="Get the reversed quote!"/> 38 29 </fieldset> 39 30 trunk/src/main/php/_test/BuddyQuoteService.php
r496 r499 31 31 return $this->buddyQuotes[$arrKey]; 32 32 } 33 34 /** 35 * Get a quote in reversed order 36 * 37 * @WebMethod 38 * @param int $arrKey 39 * @return string 40 */ 41 public function getReversedQuote($arrKey) { 42 return strrev($this->buddyQuotes[$arrKey]); 43 } 44 45 /** 46 * This method will not be exported (no @WebMethod annotation) 47 * 48 * @return string 49 */ 50 public function fooBar() { 51 return 'OOOops!'; 52 } 53 33 54 } 34 55 ?> trunk/src/main/php/net/stubbles/websites/processors/stubJsonRpcProcessor.php
r497 r499 73 73 public function doProcess() { 74 74 75 switch ($this->request->getMethod()) { 76 case 'get': 77 $this->doGET(); 78 break; 79 case 'post': 80 $this->doPOST(); 81 break; 82 } 75 if ($this->request->hasValue('__generateProxy', stubRequest::SOURCE_PARAM)) { 76 $this->generateProxies(); 77 } elseif ($this->request->getMethod() === 'get') { 78 $this->doGET(); 79 } else { 80 $this->doPOST(); 81 } 82 83 } 84 85 /** 86 * Generate and send the generated javascript clients 87 * 88 * @param array restrict to classes 89 * @todo restrict to classes 90 */ 91 public function generateProxies($class = null) { 92 stubClassLoader::load('net.stubbles.service.jsonrpc.util.stubJsonRpcProxyGenerator'); 93 $jsCode = ''; 94 foreach ($this->classMap as $jsClass => $fqClass) { 95 $jsCode = stubJsonRpcProxyGenerator::generateJavascriptProxy($fqClass, $jsClass, $jsCode); 96 } 97 $this->response->write($jsCode); 83 98 } 84 99
