Changeset 9265


Ignore:
Timestamp:
2005-03-03T16:23:19+13:00 (19 years ago)
Author:
kjdon
Message:

instead of returning null if something goes wrong, which then calls a NPE, now process returns a response with an error message inside it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/ServiceRack.java

    r8953 r9265  
    193193        // other type of request, must be processed by the subclass -
    194194        // send to the service method
    195 
     195        StringBuffer error_string = new StringBuffer();
    196196        String to = GSPath.getFirstLink(request.getAttribute(GSXML.TO_ATT));       
    197197        Element response = null;
     
    206206            try {
    207207                m = c.getDeclaredMethod(method_name, params);
    208                 // if this has worked, break
     208                // if this has worked, break
    209209                break;
    210210            } catch (NoSuchMethodException e) {
    211211                c = c.getSuperclass();
    212212            } catch (SecurityException e) {
    213                 System.err.println("ServiceRack.process: security exception for finding method "+method_name+", returning null");
    214                 return null;
     213                System.err.println("ServiceRack.process: security exception for finding method "+method_name);
     214                error_string.append("ServiceRack.process: security exception for finding method "+method_name);
    215215            }
    216216            } // while
     
    222222            } catch (Exception e) {
    223223                System.err.println("ServiceRack.process: Trying to call a processService type method (process"+to+") on a subclass("+this.getClass().getName()+"), but an exception happened:"+e.toString());
    224                 return null;
     224                error_string.append("ServiceRack.process: Trying to call a processService type method (process"+to+") on a subclass("+this.getClass().getName()+"), but an exception happened:"+e.toString());
    225225            }
    226226            } else {
    227227            System.err.println("ServiceRack.process: method "+method_name+" not found for class "+this.getClass().getName());
    228             }
    229             if (response !=null) {
    230             mainResult.appendChild(this.doc.importNode(response, true));
     228            error_string.append("ServiceRack.process: method "+method_name+" not found for class "+this.getClass().getName());
    231229            }
    232230           
    233231        } catch (ClassNotFoundException e) {
    234232            System.err.println("ServiceRack error: Element class not found");
    235             return null;
     233            error_string.append("ServiceRack error: Element class not found");
    236234        }
    237         }
     235        if (response !=null) {
     236            mainResult.appendChild(this.doc.importNode(response, true));
     237        } else {
     238            // add in a dummy response
     239            System.err.println("adding in an error element\n");
     240            response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     241            GSXML.addError(this.doc, response, error_string.toString());
     242            mainResult.appendChild(response);
     243           
     244        }
     245 
     246        } // else process request
    238247    } // for each request
    239248   
Note: See TracChangeset for help on using the changeset viewer.