From abffeaeef6b191a646254fe2356a301779232b12 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 3 Mar 2005 17:03:16 +0000 Subject: [PATCH] added some basic exception handling and propogation git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@163 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/osrf_message.h | 2 ++ src/libstack/osrf_message.c | 16 +++++++++------- src/libstack/osrf_stack.c | 23 +++++++++++++++++------ src/srfsh/srfsh.c | 7 +++++-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/opensrf/osrf_message.h b/include/opensrf/osrf_message.h index 9533cfa..d32a29c 100644 --- a/include/opensrf/osrf_message.h +++ b/include/opensrf/osrf_message.h @@ -42,6 +42,8 @@ struct osrf_message_struct { char* status_text; int status_code; + int is_exception; + /* if we're a RESULT */ json* result_content; diff --git a/src/libstack/osrf_message.c b/src/libstack/osrf_message.c index 3ccb954..9e37572 100644 --- a/src/libstack/osrf_message.c +++ b/src/libstack/osrf_message.c @@ -98,6 +98,7 @@ osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protoco msg->thread_trace = thread_trace; msg->protocol = protocol; msg->next = NULL; + msg->is_exception = 0; return msg; } @@ -123,9 +124,8 @@ void osrf_message_set_status_info( if( msg == NULL ) fatal_handler( "Bad params to osrf_message_set_status_info()" ); - if( msg->m_type == STATUS ) - if( status_name != NULL ) - msg->status_name = strdup( status_name ); + if( status_name != NULL ) + msg->status_name = strdup( status_name ); if( status_text != NULL ) msg->status_text = strdup( status_text ); @@ -426,7 +426,7 @@ int osrf_message_from_xml( char* xml, osrf_message* msgs[] ) { name = xmlGetProp( cur_node, BAD_CAST "name"); if(name) { - + if( !strcmp(name,"oilsMethod") ) { xmlNodePtr meth_node = cur_node->children; @@ -442,8 +442,8 @@ int osrf_message_from_xml( char* xml, osrf_message* msgs[] ) { } if( !strcmp((char*)meth_node->name,"params" ) && meth_node->children->content ) - new_msg->params = json_object_new_string( meth_node->children->content ); - //new_msg->params = json_tokener_parse(ng(json_params)); + //new_msg->params = json_object_new_string( meth_node->children->content ); + new_msg->params = json_tokener_parse(meth_node->children->content); meth_node = meth_node->next; } @@ -488,7 +488,9 @@ int osrf_message_from_xml( char* xml, osrf_message* msgs[] ) { } } - if( new_msg->m_type == STATUS ) { new_msg->status_name = strdup(name); } + if( new_msg->m_type == STATUS ) + new_msg->status_name = strdup(name); + xmlFree(name); } } diff --git a/src/libstack/osrf_stack.c b/src/libstack/osrf_stack.c index f5f5c77..8bfb199 100644 --- a/src/libstack/osrf_stack.c +++ b/src/libstack/osrf_stack.c @@ -21,8 +21,10 @@ int osrf_stack_transport_handler( transport_message* msg ) { osrf_app_session* session = osrf_app_session_find_session( msg->thread ); - if( session == NULL ) /* we must be a server, build a new session */ - fatal_handler( "Server sessions not implemented yet ..." ); + if( session == NULL ) { /* we must be a server, build a new session */ + info_handler( "Server sessions not implemented yet ..." ); + return 0; + } osrf_app_session_set_remote( session, msg->sender ); osrf_message* arr[OSRF_MAX_MSGS_PER_PACKET]; @@ -42,14 +44,14 @@ int osrf_stack_message_handler( osrf_app_session* session, osrf_message* msg ) { if(session == NULL || msg == NULL) return 0; - osrf_message* ret_msg; + osrf_message* ret_msg = NULL; if( session->type == OSRF_SESSION_CLIENT ) ret_msg = _do_client( session, msg ); else ret_msg= _do_server( session, msg ); if(ret_msg) - osrf_stack_application_handler( session, msg ); + osrf_stack_application_handler( session, ret_msg ); return 1; @@ -62,7 +64,7 @@ osrf_message* _do_client( osrf_app_session* session, osrf_message* msg ) { if(session == NULL || msg == NULL) return NULL; - //osrf_message* new_msg; + osrf_message* new_msg; if( msg->m_type == STATUS ) { @@ -108,7 +110,16 @@ osrf_message* _do_client( osrf_app_session* session, osrf_message* msg ) { default: - warning_handler("We don't know what to do with the provided message code: %d", msg->status_code ); + new_msg = osrf_message_init( RESULT, msg->thread_trace, msg->protocol ); + osrf_message_set_status_info( new_msg, + msg->status_name, msg->status_text, msg->status_code ); + warning_handler("The stack doesn't know what to do with " + "the provided message code: %d, name %s. Passing UP.", + msg->status_code, msg->status_name ); + new_msg->is_exception = 1; + osrf_app_session_set_complete( session, msg->thread_trace ); + osrf_message_free(msg); + return new_msg; } return NULL; diff --git a/src/srfsh/srfsh.c b/src/srfsh/srfsh.c index 8fe0db3..015f731 100644 --- a/src/srfsh/srfsh.c +++ b/src/srfsh/srfsh.c @@ -232,8 +232,11 @@ int send_request( char* server, char* method, growing_buffer* buffer ) { printf( "\nReceived Data: %s\n",content ); free(content); } - else - printf( "\nReceived Message but no result data\n"); + else { + printf( "\nReceived Exception:\nName: %s\nStatus: " + "%s\nStatusCode %d\n", omsg->status_name, + omsg->status_text, omsg->status_code ); + } osrf_message_free(omsg); omsg = osrf_app_session_request_recv( session, req_id, 5 ); -- 2.43.2