@@ -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 ,
0 commit comments