public SESNotification parseSESNoticiation(String s) throws JDOMException, IOException {
    SESNotification sn = null;
    try {

      SAXBuilder sb = new SAXBuilder(false);
      Document doc = sb.build(new ByteArrayInputStream(s.getBytes()));
      System.out.print("a");
      //		 Simple1.class.getClassLoader()
      //         .getResourceAsStream("test.xml"
      //		 Document doc =
      // sb.build(SESNotificationParse.class.getClassLoader().getResourceAsStream("d://a.txt"));
      Element root = doc.getRootElement();
      Element body = this.getElementByName(root, "Body");
      Element notify = this.getElementByName(body, "Notify");
      Element notificationMessage = this.getElementByName(notify, "NotificationMessage");
      Element message = this.getElementByName(notificationMessage, "Message");
      Element observation = this.getElementByName(message, "Observation");
      Element samplingTime = this.getElementByName(observation, "samplingTime");
      Element TimeInstant = this.getElementByName(samplingTime, "TimeInstant");
      Element timePosition = this.getElementByName(TimeInstant, "timePosition");
      String time = timePosition.getValue();
      Element result = this.getElementByName(observation, "result");
      String re = result.getValue();
      Element SubscriptionReference =
          this.getElementByName(notificationMessage, "SubscriptionReference");
      Element ReferenceParameters =
          this.getElementByName(SubscriptionReference, "ReferenceParameters");
      Element ResourceId = this.getElementByName(ReferenceParameters, "ResourceId");
      String resourceID = ResourceId.getValue();

      System.out.println("---------------gao-----------------------");
      System.out.println("time:" + time);
      System.out.println("result:" + re);
      System.out.println("resourceID:" + resourceID);
      sn = new SESNotification();
      sn.setResourceId(resourceID);
      sn.setResult(Double.parseDouble(re));
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
      Date d = sdf.parse(time.substring(0, time.length() - 1));
      sn.setTime(d.getTime());
      System.out.println("----------------end----------------------");
    } catch (Exception e) {
      e.printStackTrace();
    }
    return sn;
  }
Exemplo n.º 2
0
  public void handle(HttpExchange httpExchange) throws IOException {
    // get request
    InputStream in = httpExchange.getRequestBody();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    // display request

    connectionNumber++;

    String s;
    String sesnofity = "";
    while ((s = reader.readLine()) != null) {
      sesnofity += s;
    }
    try {
      SESNotification sn = new SESNotificationParseSintef().parseSESNoticiation(sesnofity);
      if (sn != null) {
        System.out.println("notifycation_sn:" + sn.toString());
        String resourceId = sn.getResourceId();
        if (resourceId != null) {
          ScriptBuffer scriptbuffer = new ScriptBuffer("initPointSES('" + sn.toString() + "');");
          Mysession.getSesstionByResourceId(resourceId)
              .addScript(scriptbuffer); // here add point in the chart
        }
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // build response and close connection
    String response = ResponseBuilder.buildResponseToAnonymous();
    httpExchange.sendResponseHeaders(200, response.length());

    OutputStream out = httpExchange.getResponseBody();
    out.write(response.getBytes());
    out.flush();

    // close connection
    out.close();
    reader.close();
    in.close();
  }