TargettedMessageList errors = ThreadErrorState.getErrorState().errors;
ErrorStateEntry threaderrors = ThreadErrorState.getErrorState(); TargettedMessageList errors = null;  if (threaderrors == null) { Logger.log.error("Got null ESE from ThreadLocal"); errors = new TargettedMessageList(); } else { errors = threaderrors.errors; }
  public void service(HttpServletRequest req, HttpServletResponse res) {    ThreadErrorState.beginRequest();    try {      // this is inserted to work around a Sakai component manager bug -       // request for ihr below triggers recreation of all beans although they      // have already been created, in particular sakaibeanroot.      //ServletUtil.setServletState(getServletContext(), req, res);      if (handlerroot == null) {        BeanGetter beangetter = ServletUtil.getBeanFactory(getServletContext());        handlerroot = (InformationHandlerRoot) beangetter            .getBean("informationHandlerRoot");        baseURL = ServletUtil.getBaseURL(req);      }      String baseURL2 = ServletUtil.getBaseURL2(req);      Logger.log.info("baseURL: " + baseURL);      Logger.log.info("baseURL2: " + baseURL2);      String requestURI = req.getRequestURL().toString();      // temporary hack to avoid odd problem when hosted by Sakai.       // TODO: experiment with uses of getBaseURL2();      int lastslashpos = requestURI.lastIndexOf('/');            //String handlerID = requestURI.substring(baseURL.length());      String handlerID = requestURI.substring(lastslashpos + 1);      InformationHandler handler = handlerroot.getHandler(handlerID);      if (handler == null) {        String errmess = "The request handler " + handlerID            + " could not be found to service the request "            + req.getRequestURI();        Logger.log.warn(errmess);        res.sendError(HttpServletResponse.SC_NOT_FOUND, errmess);      }      else {        XMLProvider xmlprovider = handlerroot.getXMLProvider();        Throwable t = null;        String errorid = null;        String extraerrors = "";        try {          //String input = StreamCopier.streamToString(req.getInputStream());          Object arg = xmlprovider.readXML(null, req.getInputStream());          Object togo = handler.handleRequest(arg);          if (togo != null) {            xmlprovider.writeXML(togo, res.getOutputStream());            String debugstring = xmlprovider.toString(togo);           Logger.log.info(                "InformationServlet returning response:\n" + debugstring);          }          else {          }        }        catch (Throwable t1) {          errorid = handlerroot.getIDGenerator().generateID();          t = t1;        }        TargettedMessageList errors = ThreadErrorState.getErrorState().errors;        if (errors.size() > 0) {          for (int i = 0; i < errors.size(); ++i) {            extraerrors += errors.messageAt(i).messagecode                + errors.messageAt(i).exceptionclass;          }        }        if (errorid != null) {          ErrorObject err = new ErrorObject("Error ID " + errorid              + " processing request " + req.getRequestURI(), handlerID, t);          // TODO: This is probably not quite right - what if an error occurs          // partway through writing the output?          xmlprovider.writeXML(err, res.getOutputStream());          Logger.log.warn("Error ID " + errorid              + " processing request " + req.getRequestURL(), t);        }      } // end if there is a handler      //TODO: global registry of transactions      TransactionThreadMap.assertAllTransactionsConcluded();    }    catch (Throwable t) {      Logger.log.fatal("Completely fatal exception handling request " +           req.getRequestURI(), t);      throw UniversalRuntimeException.accumulate(t,          "Fatal exception in InformationServlet");    }    finally {//      ServletUtil.getServletState().clear();    }  }