#NEWLINE# def _handle_message_loop( self ) : #NEWLINE# #INDENT# request_data = self . _receive_request ( ) #NEWLINE# request = messages . RequestMessage ( ) #NEWLINE# max_size = self . _max_response_size #NEWLINE# try : #NEWLINE# #INDENT# request . read ( request_data ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# self . _logger . warning ( 'Failure parsing request message.' ) #NEWLINE# self . _logger . exception ( e ) #NEWLINE# response = self . _engine . build_error_response ( contents . ProtocolVersion . create ( 1 , 0 ) , enums . ResultReason . INVALID_MESSAGE , 'Error parsing request message. See server logs for more information.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( response , max_response_size ) = self . _engine . process_request ( request ) #NEWLINE# if max_response_size : #NEWLINE# #INDENT# max_size = max_response_size #NEWLINE# #UNINDENT# #UNINDENT# except exceptions . KmipError as e : #NEWLINE# #INDENT# response = self . _engine . build_error_response ( request . request_header . protocol_version , e . reason , str ( e ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# self . _logger . warning ( 'An unexpected error occurred while processing request.' ) #NEWLINE# self . _logger . exception ( e ) #NEWLINE# response = self . _engine . build_error_response ( request . request_header . protocol_version , enums . ResultReason . GENERAL_FAILURE , 'An unexpected error occurred while processing request. See server logs for more information.' ) #NEWLINE# #UNINDENT# #UNINDENT# response_data = utils . BytearrayStream ( ) #NEWLINE# response . write ( response_data ) #NEWLINE# if ( len ( response_data ) > max_size ) : #NEWLINE# #INDENT# self . _logger . warning ( 'Response message length too large: {0} bytes, max {1} bytes' . format ( len ( response_data ) , self . _max_response_size ) ) #NEWLINE# response = self . _engine . build_error_response ( request . request_header . protocol_version , enums . ResultReason . RESPONSE_TOO_LARGE , 'Response message length too large. See server logs for more information.' ) #NEWLINE# response_data = utils . BytearrayStream ( ) #NEWLINE# response . write ( response_data ) #NEWLINE# #UNINDENT# self . _send_response ( response_data . buffer )