コード例 #1
0
  @Post("xml")
  public Representation testDoctor(Representation entity) {

    DomRepresentation representation = null;
    try {
      DomRepresentation input = new DomRepresentation(entity);
      // input
      Document doc = input.getDocument();
      Element rootEl = doc.getDocumentElement();
      String username = XMLUtils.getTextValue(rootEl, "username");
      String firstName = XMLUtils.getTextValue(rootEl, "firstname");
      String lastName = XMLUtils.getTextValue(rootEl, "lastname");

      // output
      representation = new DomRepresentation(MediaType.TEXT_XML);

      String res = "OK " + username;

      Map<String, String> map = new HashMap<String, String>();
      map.put("result", res);
      Document d = representation.getDocument();
      d = XMLUtils.createXMLResult("doctorTestOutput", map, d);

    } catch (IOException e) {
      representation = XMLUtils.createXMLError("login error", "" + e.getMessage());
    }

    // Returns the XML representation of this document.
    return representation;
  }
コード例 #2
0
  @Post("xml")
  public Representation acceptItem(Representation entity) {

    DomRepresentation representation = null;
    try {
      DomRepresentation input = new DomRepresentation(entity);
      // input
      Document doc = input.getDocument();
      Element rootEl = doc.getDocumentElement();
      String username = XMLUtils.getTextValue(rootEl, "username");

      // output
      representation = new DomRepresentation(MediaType.TEXT_XML);

      // Generate a DOM document representing the list of
      // items.

      String res = "";
      try {
        ObjectifyService.register(Patient.class);
      } catch (Exception e) {
      }

      Objectify ofy = ObjectifyService.begin();
      Patient us = ofy.query(Patient.class).filter("username", username).get();
      if (us == null) {
        res = "user not found.";
      } else {

        ofy.delete(us);
        res = "OK, " + us.getUsername() + " deleted.";
      }
      getLogger().info("res: " + res);
      Map<String, String> map = new HashMap<String, String>();
      map.put("result", res);
      Document d = representation.getDocument();
      d = XMLUtils.createXMLResult("rehabDeleteUserOutput", map, d);

    } catch (IOException e) {
      representation = XMLUtils.createXMLError("user delete error", "" + e.getMessage());
    }

    // Returns the XML representation of this document.
    return representation;
  }