protected void doGet()

in SimpleServer/src/main/java/org/apache/uima/simpleserver/servlet/ListServices.java [74:153]


  protected void doGet(HttpServletRequest request, HttpServletResponse response) {

    String server = request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort();

    PrintWriter writer = null;
    try {
      writer = response.getWriter();
    } catch (IOException e1) {
      this.logger.log(Level.SEVERE, "Could not obtain response writer, aborting.");
      e1.printStackTrace();
      return;
    }

    if (this.myDir == null) {
      this.myDir = new File(getServletContext().getRealPath(""));
      File iniFile = new File(this.myDir, CONFIG_FILE_NAME);
      try {
        this.properties.load(new FileInputStream(iniFile));
      } catch (IOException e) {
        this.logger.log(Level.SEVERE, "Could not load config file: " + iniFile.getAbsolutePath());
        e.printStackTrace();
      }
    }

    String mode = request.getParameter("mode");
    if ((mode != null) && mode.equals("xml")) {
      try {
        writer.print(xmlToString(produceXmlList(server)));
        writer.close();
      } finally {
        writer.close();
      }
    } else {

      Document document = produceXmlList(server);
      Element root = document.getDocumentElement();
      NodeList nlist = root.getElementsByTagName("service");

      String html = "<html><head><title>List of services</title></head><body>"
          + "<h2>List of UIMA services available on " + server + "</h2>" + "<ul>";

      int n = nlist.getLength();

      for (int i = 0; i < n; i++) {
        String url = "";
        try {
          Element serviceElement = (Element) nlist.item(i);
          url = serviceElement.getAttribute("url");
        } catch (Exception e) {
          e.printStackTrace();
        }

        String desc = "<i>No service description available</i>";

        try {
          Element serviceElement = (Element) nlist.item(i);
          Element uimaService = (Element) (serviceElement.getElementsByTagName("uimaService")
              .item(0));
          String tmpDesc = uimaService.getAttribute("shortDescription");
          if ((tmpDesc != null) && tmpDesc.length() > 0) {
            desc = tmpDesc;
          }
        } catch (Exception e) {
          e.printStackTrace();
        }

        html += "<li/> <b>" + desc + "</b>" + "<br/> URL: " + url
            + " </br> For further details, please see the <a href=\"" + url + "?mode=description"
            + "\">detailed service information</a> or " + "<a href=\"" + url + "?mode=form"
            + "\">try out</a> this service. <a href=\"" + url + "?mode=xmldesc"
            + "\">Description</a> " + "of this service in XML format is also available. <br/>";

      }

      html += "</ul></body></html>";
      writer.print(html);
      writer.close();
    }
  }