Package ch.shamu.jsendnrdp.domain

Examples of ch.shamu.jsendnrdp.domain.CheckSubmissionResult


    HttpResponse response = httpClient.execute(request); // eventual IO exceptions are allowed to bubble up from here
    HttpEntity entity = response.getEntity();
    String responseString = EntityUtils.toString(entity, "UTF-8");

    // Treat the response
    CheckSubmissionResult result;

    try {
      result = parseResponseXML(responseString);
    }
    catch (Exception e) {
      throw new NRDPException("Failed to parse http response body from NRDP server (should be XML) : " + responseString, e);
    }

    if (!result.getStatus().equals("0")) {
      throw new NRDPException("NRDP server returned with code " + result.getStatus() + " and message " + result.getMessage());
    }

    logger.info(results.size() + " check results succesfully sent to Nagios");
  }
View Full Code Here


    logger.info(results.size() + " check results succesfully sent to Nagios");
  }

  private CheckSubmissionResult parseResponseXML(String xml) throws ParserConfigurationException, SAXException, IOException {
    final CheckSubmissionResult res = new CheckSubmissionResult();

    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();

    DefaultHandler handler = new DefaultHandler() {

      boolean statusTag = false;
      boolean messageTag = false;

      @Override
      public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        if (qName.equalsIgnoreCase("status")) {
          statusTag = true;
        }
        if (qName.equalsIgnoreCase("message")) {
          messageTag = true;
        }
      }

      @Override
      public void characters(char[] ch, int start, int length) throws SAXException {
        if (statusTag) {
          res.setStatus(new String(ch, start, length));
          statusTag = false;
        }
        if (messageTag) {
          res.setMessage(new String(ch, start, length));
          messageTag = false;
        }
      }

    };

    saxParser.parse(new InputSource(new StringReader(xml)), handler);
    if (res.getStatus() == null || res.getMessage() == null) {
      throw new SAXException("Failed to get response status and message");
    }
    return res;
  }
View Full Code Here

TOP

Related Classes of ch.shamu.jsendnrdp.domain.CheckSubmissionResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.