Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

Commit c742992

Browse files
committed
Remove obsolete JSON-RPC code.
JSON-RPC has never been supported in released versions of the framework. Removing this code before a refactor.
1 parent d8d9d2e commit c742992

4 files changed

Lines changed: 22 additions & 162 deletions

File tree

endpoints/api_config_manager.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class ApiConfigManager(object):
3636
"""Manages loading api configs and method lookup."""
3737

3838
def __init__(self):
39-
self._rpc_method_dict = {}
4039
self._rest_methods = []
4140
self._configs = {}
4241
self._config_lock = threading.Lock()
@@ -75,7 +74,6 @@ def process_api_config_response(self, config_json):
7574

7675

7776
for method_name, method in sorted_methods:
78-
self._save_rpc_method(method_name, api_version, method)
7977
self._save_rest_method(method_name, name, path_version, method)
8078

8179
def _get_sorted_methods(self, methods):
@@ -167,23 +165,6 @@ def _get_path_params(match):
167165
result[actual_var_name] = urllib.unquote_plus(value)
168166
return result
169167

170-
def lookup_rpc_method(self, method_name, version):
171-
"""Lookup the JsonRPC method at call time.
172-
173-
The method is looked up in self._rpc_method_dict, the dictionary that
174-
it is saved in for SaveRpcMethod().
175-
176-
Args:
177-
method_name: A string containing the name of the method.
178-
version: A string containing the version of the API.
179-
180-
Returns:
181-
Method descriptor as specified in the API configuration.
182-
"""
183-
with self._config_lock:
184-
method = self._rpc_method_dict.get((method_name, version))
185-
return method
186-
187168
def lookup_rest_method(self, path, http_method):
188169
"""Look up the rest method at call time.
189170
@@ -319,19 +300,6 @@ def replace_variable(match):
319300
replace_variable, pattern)
320301
return re.compile(pattern + '/?$')
321302

322-
def _save_rpc_method(self, method_name, version, method):
323-
"""Store JsonRpc api methods in a map for lookup at call time.
324-
325-
(rpcMethodName, apiVersion) => method.
326-
327-
Args:
328-
method_name: A string containing the name of the API method.
329-
version: A string containing the version of the API.
330-
method: A dict containing the method descriptor (as in the api config
331-
file).
332-
"""
333-
self._rpc_method_dict[(method_name, version)] = method
334-
335303
def _save_rest_method(self, method_name, api_name, version, method):
336304
"""Store Rest api methods in a list for lookup at call time.
337305

endpoints/api_request.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,5 @@ def reconstruct_full_url(self, port_override=None):
179179
def copy(self):
180180
return copy.deepcopy(self)
181181

182-
def is_rpc(self):
183-
# Google's JsonRPC protocol creates a handler at /rpc for any Cloud
184-
# Endpoints API, with api name, version, and method name being in the
185-
# body of the request.
186-
# If the request is sent to /rpc, we will treat it as JsonRPC.
187-
# The client libraries for iOS's Objective C use RPC and not the REST
188-
# versions of the API.
189-
return self.path == 'rpc'
190-
191182
def is_batch(self):
192183
return self._is_batch

endpoints/endpoints_dispatcher.py

Lines changed: 11 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,7 @@ def call_backend(self, orig_request, start_response):
327327
Returns:
328328
A string containing the response body.
329329
"""
330-
if orig_request.is_rpc():
331-
method_config = self.lookup_rpc_method(orig_request)
332-
params = None
333-
else:
334-
method_config, params = self.lookup_rest_method(orig_request)
330+
method_config, params = self.lookup_rest_method(orig_request)
335331
if not method_config:
336332
cors_handler = self._create_cors_handler(orig_request)
337333
return util.send_wsgi_not_found_response(start_response,
@@ -448,19 +444,14 @@ def handle_backend_response(self, orig_request, backend_request,
448444

449445
self.check_error_response(response_body, response_status)
450446

451-
# Need to check is_rpc() against the original request, because the
452-
# incoming request here has had its path modified.
453-
if orig_request.is_rpc():
454-
body = self.transform_jsonrpc_response(backend_request, response_body)
455-
else:
456-
# Check if the response from the API was empty. Empty REST responses
457-
# generate a HTTP 204.
458-
empty_response = self.check_empty_response(orig_request, method_config,
447+
# Check if the response from the API was empty. Empty REST responses
448+
# generate a HTTP 204.
449+
empty_response = self.check_empty_response(orig_request, method_config,
459450
start_response)
460-
if empty_response is not None:
461-
return empty_response
451+
if empty_response is not None:
452+
return empty_response
462453

463-
body = self.transform_rest_response(response_body)
454+
body = self.transform_rest_response(response_body)
464455

465456
cors_handler = self._create_cors_handler(orig_request)
466457
return util.send_wsgi_response(response_status, response_headers, body,
@@ -498,23 +489,6 @@ def lookup_rest_method(self, orig_request):
498489
orig_request.method_name = method_name
499490
return method, params
500491

501-
def lookup_rpc_method(self, orig_request):
502-
"""Looks up and returns RPC method for the currently-pending request.
503-
504-
Args:
505-
orig_request: An ApiRequest, the original request from the user.
506-
507-
Returns:
508-
The RPC method descriptor that was found for the current request, or None
509-
if none was found.
510-
"""
511-
if not orig_request.body_json:
512-
return None
513-
method_name = orig_request.body_json.get('method', '')
514-
version = orig_request.body_json.get('apiVersion', '')
515-
orig_request.method_name = method_name
516-
return self.config_manager.lookup_rpc_method(method_name, version)
517-
518492
def transform_request(self, orig_request, params, method_config):
519493
"""Transforms orig_request to apiserving request.
520494
@@ -533,11 +507,8 @@ def transform_request(self, orig_request, params, method_config):
533507
be sent to the backend. The path is updated and parts of the body or
534508
other properties may also be changed.
535509
"""
536-
if orig_request.is_rpc():
537-
request = self.transform_jsonrpc_request(orig_request)
538-
else:
539-
method_params = method_config.get('request', {}).get('parameters', {})
540-
request = self.transform_rest_request(orig_request, params, method_params)
510+
method_params = method_config.get('request', {}).get('parameters', {})
511+
request = self.transform_rest_request(orig_request, params, method_params)
541512
request.path = method_config.get('rosyMethod', '')
542513
return request
543514

@@ -674,21 +645,6 @@ def transform_rest_request(self, orig_request, params, method_parameters):
674645
request.body = json.dumps(request.body_json)
675646
return request
676647

677-
def transform_jsonrpc_request(self, orig_request):
678-
"""Translates a JsonRpc request/response into apiserving request/response.
679-
680-
Args:
681-
orig_request: An ApiRequest, the original request from the user.
682-
683-
Returns:
684-
A new request with the request_id updated and params moved to the body.
685-
"""
686-
request = orig_request.copy()
687-
request.request_id = request.body_json.get('id')
688-
request.body_json = request.body_json.get('params', {})
689-
request.body = json.dumps(request.body_json)
690-
return request
691-
692648
def check_error_response(self, body, status):
693649
"""Raise an exception if the response from the backend was an error.
694650
@@ -740,40 +696,6 @@ def transform_rest_response(self, response_body):
740696
body_json = json.loads(response_body)
741697
return json.dumps(body_json, indent=1, sort_keys=True)
742698

743-
def transform_jsonrpc_response(self, backend_request, response_body):
744-
"""Translates an apiserving response to a JsonRpc response.
745-
746-
Args:
747-
backend_request: An ApiRequest, the transformed request that was sent to
748-
the backend handler.
749-
response_body: A string containing the backend response to transform
750-
back to JsonRPC.
751-
752-
Returns:
753-
A string with the updated, JsonRPC-formatted request body.
754-
"""
755-
body_json = {'result': json.loads(response_body)}
756-
return self._finish_rpc_response(backend_request.request_id,
757-
backend_request.is_batch(), body_json)
758-
759-
def _finish_rpc_response(self, request_id, is_batch, body_json):
760-
"""Finish adding information to a JSON RPC response.
761-
762-
Args:
763-
request_id: None if the request didn't have a request ID. Otherwise, this
764-
is a string containing the request ID for the request.
765-
is_batch: A boolean indicating whether the request is a batch request.
766-
body_json: A dict containing the JSON body of the response.
767-
768-
Returns:
769-
A string with the updated, JsonRPC-formatted request body.
770-
"""
771-
if request_id is not None:
772-
body_json['id'] = request_id
773-
if is_batch:
774-
body_json = [body_json]
775-
return json.dumps(body_json, indent=1, sort_keys=True)
776-
777699
def _handle_request_error(self, orig_request, error, start_response):
778700
"""Handle a request error, converting it to a WSGI response.
779701
@@ -786,16 +708,8 @@ def _handle_request_error(self, orig_request, error, start_response):
786708
A string containing the response body.
787709
"""
788710
headers = [('Content-Type', 'application/json')]
789-
if orig_request.is_rpc():
790-
# JSON RPC errors are returned with status 200 OK and the
791-
# error details in the body.
792-
status_code = 200
793-
body = self._finish_rpc_response(orig_request.body_json.get('id'),
794-
orig_request.is_batch(),
795-
error.rpc_error())
796-
else:
797-
status_code = error.status_code()
798-
body = error.rest_error()
711+
status_code = error.status_code()
712+
body = error.rest_error()
799713

800714
response_status = '%d %s' % (status_code,
801715
httplib.responses.get(status_code,

endpoints/test/api_config_manager_test.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def setUp(self):
2828

2929
def test_process_api_config_empty_response(self):
3030
self.config_manager.process_api_config_response({})
31-
actual_method = self.config_manager.lookup_rpc_method('guestbook_api.get',
32-
'v1')
33-
self.assertEqual(None, actual_method)
31+
actual_method = self.config_manager.lookup_rest_method('guestbook_api',
32+
'GET')
33+
self.assertEqual((None, None, None), actual_method)
3434

3535
def test_process_api_config_invalid_response(self):
3636
self.config_manager.process_api_config_response({'name': 'foo'})
37-
actual_method = self.config_manager.lookup_rpc_method('guestbook_api.get',
38-
'v1')
39-
self.assertEqual(None, actual_method)
37+
actual_method = self.config_manager.lookup_rest_method('guestbook_api',
38+
'GET')
39+
self.assertEqual((None, None, None), actual_method)
4040

4141
def test_process_api_config(self):
4242
fake_method = {'httpMethod': 'GET',
@@ -48,8 +48,8 @@ def test_process_api_config(self):
4848
'path_version': 'X',
4949
'methods': {'guestbook_api.foo.bar': fake_method}}
5050
self.config_manager.process_api_config_response({'items': [config]})
51-
actual_method = self.config_manager.lookup_rpc_method(
52-
'guestbook_api.foo.bar', 'X')
51+
actual_method = self.config_manager.lookup_rest_method(
52+
'guestbook_api/X/greetings/123', 'GET')[1]
5353
self.assertEqual(fake_method, actual_method)
5454

5555
def test_process_api_config_order_length(self):
@@ -73,9 +73,9 @@ def test_process_api_config_order_length(self):
7373
self.config_manager.process_api_config_response(
7474
{'items': [config]})
7575
# Make sure all methods appear in the result.
76-
for method_name, _, _ in test_method_info:
77-
self.assertIsNotNone(
78-
self.config_manager.lookup_rpc_method(method_name, 'X'))
76+
for method_name, path, _ in test_method_info:
77+
request_path = 'guestbook_api/X/{}'.format(path.replace('{gid}', '123'))
78+
assert (None, None, None) != self.config_manager.lookup_rest_method(request_path, 'GET')
7979
# Make sure paths and partial paths return the right methods.
8080
self.assertEqual(
8181
self.config_manager.lookup_rest_method(
@@ -170,19 +170,6 @@ def test_process_api_config_convert_https(self):
170170
'https://localhost/_ah/api',
171171
self.config_manager.configs[('guestbook_api', 'X')]['root'])
172172

173-
def test_save_lookup_rpc_method(self):
174-
# First attempt, guestbook.get does not exist
175-
actual_method = self.config_manager.lookup_rpc_method('guestbook_api.get',
176-
'v1')
177-
self.assertEqual(None, actual_method)
178-
179-
# Now we manually save it, and should find it
180-
fake_method = {'some': 'object'}
181-
self.config_manager._save_rpc_method('guestbook_api.get', 'v1', fake_method)
182-
actual_method = self.config_manager.lookup_rpc_method('guestbook_api.get',
183-
'v1')
184-
self.assertEqual(fake_method, actual_method)
185-
186173
def test_save_lookup_rest_method(self):
187174
# First attempt, guestbook.get does not exist
188175
method_spec = self.config_manager.lookup_rest_method(

0 commit comments

Comments
 (0)