added some basic exception handling and propogation
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 3 Mar 2005 17:03:16 +0000 (17:03 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 3 Mar 2005 17:03:16 +0000 (17:03 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@163 9efc2488-bf62-4759-914b-345cdb29e865

include/opensrf/osrf_message.h
src/libstack/osrf_message.c
src/libstack/osrf_stack.c
src/srfsh/srfsh.c

index 9533cfa..d32a29c 100644 (file)
@@ -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;
 
index 3ccb954..9e37572 100644 (file)
@@ -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);
                                }
                        }
index f5f5c77..8bfb199 100644 (file)
@@ -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;
index 8fe0db3..015f731 100644 (file)
@@ -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 );