Example #1
0
 /**
  * 验证项目是否ok
  *
  * @param contextPath 项目路径
  */
 public static boolean isdomainok(String contextPath, String securityKey, String domiankey) {
   try {
     if (contextPath.indexOf("127.0.") > -1 || contextPath.indexOf("192.168.") > -1) {
       return true;
     }
     String dedomaininfo = PurseSecurityUtils.decryption(domiankey, securityKey);
     Gson gson = new Gson();
     JsonParser jsonParser = new JsonParser();
     JsonObject jsonObject = jsonParser.parse(dedomaininfo).getAsJsonObject();
     Map<String, String> map =
         gson.fromJson(jsonObject, new TypeToken<Map<String, String>>() {}.getType());
     String domain = map.get("domain");
     if (contextPath.indexOf(domain) < 0) {
       System.exit(2);
       return false;
     }
     String dt = map.get("dt");
     if (com.yizhilu.os.core.util.StringUtils.isNotEmpty(dt)) {
       Date t = DateUtils.toDate(dt, "yyyy-MM-dd");
       if (t.compareTo(new Date()) < 0) {
         System.exit(3);
         return false;
       }
     }
     return true;
   } catch (Exception e) {
     return false;
   }
 }
Example #2
0
 public boolean hasExpired() {
   if (expires == null) {
     return false;
   }
   Date now = new Date();
   return now.after(expires);
 }
Example #3
0
  private void ConnectKnowledgeBaseBtnMouseClicked(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_ConnectKnowledgeBaseBtnMouseClicked

    String sPrjFile = ProjectNameTF.getText().trim();
    String sLocationURI = sURI + "Location";

    Collection errors = new ArrayList();
    Date d1 = new Date();
    long l1 = d1.getTime();
    prj = Project.loadProjectFromFile(sPrjFile, errors);
    owlModel = (OWLModel) prj.getKnowledgeBase();

    kb = prj.getKnowledgeBase();
    URI uri = prj.getActiveRootURI();

    Collection colNumberOfInstance = kb.getInstances();
    lNumberOfInstance = colNumberOfInstance.size();

    Date d2 = new Date();
    long l2 = d2.getTime();
    lLoadedTime = (l2 - l1);

    theLogger.info("Connected to MySQL in " + lLoadedTime + " ms");
    theLogger.info("KB has " + lNumberOfInstance + " instances");

    LoggingAreaTA.append("Project has " + lNumberOfInstance + " in total\n");
    LoggingAreaTA.append("Project is loaded in " + lLoadedTime + " ms\n");
  } // GEN-LAST:event_ConnectKnowledgeBaseBtnMouseClicked
  public SetIfModifiedSince() throws Exception {

    serverSock = new ServerSocket(0);
    int port = serverSock.getLocalPort();

    Thread thr = new Thread(this);
    thr.start();

    Date date = new Date(new Date().getTime() - 1440000); // this time yesterday
    URL url;
    HttpURLConnection con;

    // url = new URL(args[0]);
    url = new URL("http://localhost:" + String.valueOf(port) + "/anything");
    con = (HttpURLConnection) url.openConnection();

    con.setIfModifiedSince(date.getTime());
    con.connect();
    int ret = con.getResponseCode();

    if (ret == 304) {
      System.out.println("Success!");
    } else {
      throw new RuntimeException(
          "Test failed! Http return code using setIfModified method is:"
              + ret
              + "\nNOTE:some web servers are not implemented according to RFC, thus a failed test does not necessarily indicate a bug in setIfModifiedSince method");
    }
  }
Example #5
0
  public static void main(String[] argv) {
    String hostName;
    if (argv.length == 0) hostName = "localhost";
    else hostName = argv[0];

    try {
      Socket sock = new Socket(hostName, TIME_PORT);
      ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));

      // Read and validate the Object
      Object o = is.readObject();
      if (o == null) {
        System.err.println("Read null from server!");
      } else if ((o instanceof Date)) {

        // Valid, so cast to Date, and print
        Date d = (Date) o;
        System.out.println("Server host is " + hostName);
        System.out.println("Time there is " + d.toString());

      } else {
        throw new IllegalArgumentException("Wanted Date, got " + o);
      }
    } catch (ClassNotFoundException e) {
      System.err.println("Wanted date, got INVALID CLASS (" + e + ")");
    } catch (IOException e) {
      System.err.println(e);
    }
  }
Example #6
0
  // function to do the join use case
  public static void share() throws Exception {
    HttpPost method = new HttpPost(url + "/share");
    String ipAddress = null;

    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
      NetworkInterface ni = (NetworkInterface) en.nextElement();
      if (ni.getName().equals("eth0")) {
        Enumeration<InetAddress> en2 = ni.getInetAddresses();
        while (en2.hasMoreElements()) {
          InetAddress ip = (InetAddress) en2.nextElement();
          if (ip instanceof Inet4Address) {
            ipAddress = ip.getHostAddress();
            break;
          }
        }
        break;
      }
    }

    method.setEntity(new StringEntity(username + ';' + ipAddress, "UTF-8"));
    try {
      ResponseHandler<String> responseHandler = new BasicResponseHandler();
      connIp = client.execute(method, responseHandler);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }

    // get present time
    date = new Date();
    long start = date.getTime();

    // Execute the vishwa share process
    Process p = Runtime.getRuntime().exec("java -jar vishwa/JVishwa.jar " + connIp);

    String ch = "alive";
    System.out.println("Type kill to unjoin from the grid");

    while (!ch.equals("kill")) {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      ch = in.readLine();
    }

    p.destroy();

    date = new Date();
    long end = date.getTime();
    long durationInt = end - start;

    String duration = String.valueOf(durationInt);
    method = new HttpPost(url + "/shareAck");
    method.setEntity(new StringEntity(username + ";" + duration, "UTF-8"));
    try {
      client.execute(method);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }
  }
Example #7
0
 /**
  * Returns the time that the file denoted by this abstract pathname was last modified.
  *
  * @return A <code>long</code> value representing the time the file was last modified, measured in
  *     system-dependent way.
  */
 public long lastModified() {
   try {
     Date date = ftpClient.lastModified(getPath());
     return date.getTime();
   } catch (IOException e) {
     return 0;
   } catch (FTPException e) {
     return 0;
   }
 }
Example #8
0
  // function to do the compute use case
  public static void compute() throws Exception {
    HttpPost method = new HttpPost(url + "/compute");

    method.setEntity(new StringEntity(username, "UTF-8"));

    try {
      ResponseHandler<String> responseHandler = new BasicResponseHandler();
      connIp = client.execute(method, responseHandler);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }

    System.out.println("Give the file name which has to be put in the grid for computation");

    // input of the file name to be computed
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String name = in.readLine();

    // get the absolute path of the current working directory
    File directory = new File(".");
    String pwd = directory.getAbsolutePath();

    // get present time
    date = new Date();
    long start = date.getTime();

    String cmd = "java -classpath " + pwd + "/vishwa/JVishwa.jar:. " + name + " " + connIp;
    System.out.println(cmd);

    // Execute the vishwa compute process
    Process p = Runtime.getRuntime().exec(cmd);

    // wait till the compute process is completed
    // check for the status code (0 for successful termination)
    int status = p.waitFor();

    if (status == 0) {
      System.out.println("Compute operation successful. Check the directory for results");
    }

    date = new Date();
    long end = date.getTime();
    long durationInt = end - start;

    String duration = String.valueOf(durationInt);
    method = new HttpPost(url + "/computeAck");
    method.setEntity(new StringEntity(username + ";" + duration, "UTF-8"));
    try {
      client.execute(method);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }
  }
Example #9
0
 /**
  * Implementing the Observer interface. Receiving the response from the Pdu.
  *
  * @param obs the UpSincePdu variable
  * @param ov the date
  * @see uk.co.westhawk.snmp.pdu.UpSincePdu
  */
 public void update(Observable obs, Object ov) {
   Pdu pdu = (Pdu) obs;
   if (pdu.getErrorStatus() == AsnObject.SNMP_ERR_NOERROR) {
     Date dres = (Date) ov;
     if (dres != null) {
       // TODO: invokeLater
       v.setText(dres.toString());
     }
   } else {
     // TODO: invokeLater
     v.setText(pdu.getErrorStatusString());
   }
 }
Example #10
0
 public static long getDateHeader(String stringValue) throws ParseException {
   for (SimpleDateFormat dateHeaderFormat : dateHeaderFormats) {
     try {
       Date date = dateHeaderFormat.parse(stringValue);
       return date.getTime();
     } catch (
         Exception
             e) { // used to be ParseException, but NumberFormatException may be thrown as well
       // Ignore and try next
     }
   }
   throw new ParseException(stringValue, 0);
 }
Example #11
0
 private boolean stranger(String myName) {
   // tty.println("=+= " + (myName.getBytes()[0])+" =" );
   // tty.println("=+= " + Character.isISOControl(myName.charAt(0)));
   if (Character.isISOControl(myName.charAt(0))) myName = "QUIT";
   if (myName.equals("QUIT")) {
     writeLine("! Thank you for coming!");
   }
   if (myName == null || myName.equals("QUIT")) {
     tty.println(" --- from " + remoteAddr + " at " + now.toString());
     return true;
   } // "QUIT" is not allowed as a nick name
   if (myName.equals(SECRET_NAME)) {
     tty.println("GiGi  from " + remoteAddr + " at " + now.toString());
     doList();
     return true;
   }
   return false; // a usual user name
 }
Example #12
0
  public void run() {
    now = new Date();
    try {
      remoteAddr = mySock.getInetAddress().getHostAddress();
      // 然後取得InputStream並包成 BufferedReader 方便 readLine()
      in = new BufferedReader(new InputStreamReader(mySock.getInputStream()));
      // 再取得 OutputStream 並包成 PrintWriter
      out = new PrintWriter(new OutputStreamWriter(mySock.getOutputStream()), true);
      // 接著, 要求連線者輸入 nickname
      myName = askNickname();
      // 若輸入怪異的nickname例如Control_C 則終止連線
      if (stranger(myName)) {
        close();
        return;
      }
      // 廣播給所有聊天室的人
      doBcast("CHAT *** " + myName + " is coming in ***");
      // 並在 console 上顯示 (tty == System.out)
      tty.println(myName + "@" + remoteAddr + " enters the Chat Room " + now.toString());
      // writeLine(msg) 會把 msg 寫到目前連線者終端機
      writeLine("CHAT *** Welcome 歡迎 " + myName + " 進入聊天室 ***");
      writeLine("You can type '/help' for help");

      String cmd, msg;
      int mode;
      FOO:
      while ((cmd = in.readLine()) != null) {
        StringTokenizer stkn = new StringTokenizer(cmd, " \t");
        String command = " ";
        if (stkn.countTokens() >= 1) command = stkn.nextToken();
        msg = " ";
        if (stkn.hasMoreTokens()) msg = stkn.nextToken("\n");
        mode = parseCommand(command.toUpperCase());
        switch (mode) {
          case CMD_MSG:
            doMsg(msg);
            break;
          case CMD_LIST:
            doList();
            break;
          case CMD_QUERY:
            doQuery(cmd.substring(6));
            break;
          case CMD_NICK:
            doNick(msg);
            break;
          case CMD_HELP:
            doHelp();
            break;
          case CMD_QUIT:
            now = new Date();
            tty.println(myName + "  said BYE   at   " + now.toString());
            doBcast("[" + myName + " saied Bye Bye! ]");
            break FOO;
          case CMD_DATA:
            doBcast("[" + myName + "] " + cmd);
            tty.println(myName + ": " + cmd);
            break;
        } // switch
      } // while  FOO:
    } catch (Exception e) {
      tty.println(e.toString());
    }
    now = new Date();
    tty.println(now.toString() + "  one thread stop");
    close();
  }
  /**
   * Waits until either the State attribute of this MBean equals the specified <VAR>state</VAR>
   * parameter, or the specified <VAR>timeout</VAR> has elapsed. The method <CODE>waitState</CODE>
   * returns with a boolean value indicating whether the specified <VAR>state</VAR> parameter equals
   * the value of this MBean's State attribute at the time the method terminates.
   *
   * <p>Two special cases for the <VAR>timeout</VAR> parameter value are:
   *
   * <UL>
   *   <LI>if <VAR>timeout</VAR> is negative then <CODE>waitState</CODE> returns immediately (i.e.
   *       does not wait at all),
   *   <LI>if <VAR>timeout</VAR> equals zero then <CODE>waitState</CODE> waits until the value of
   *       this MBean's State attribute is the same as the <VAR>state</VAR> parameter (i.e. will
   *       wait indefinitely if this condition is never met).
   * </UL>
   *
   * @param state The value of this MBean's State attribute to wait for. <VAR>state</VAR> can be one
   *     of: <CODE>DiscoveryResponder.OFFLINE</CODE>, <CODE>DiscoveryResponder.ONLINE</CODE>, <CODE>
   *     DiscoveryResponder.STARTING</CODE>, <CODE>DiscoveryResponder.STOPPING</CODE>.
   * @param timeout The maximum time to wait for, in milliseconds, if positive. Infinite time out if
   *     0, or no waiting at all if negative.
   * @return <code>true</code> if the value of this MBean's State attribute is the same as the
   *     <VAR>state</VAR> parameter; <code>false</code> otherwise.
   */
  public boolean waitState(int state, long timeout) {
    if (logger.finerOn()) {
      logger.finer(
          "waitState",
          state + "(0on,1off,2st) TO=" + timeout + " ; current state = " + getStateString());
    }
    // ------------
    // Test timeout
    // ------------
    if (timeout < 0) {
      return (this.state == state);
    }

    boolean done = (this.state == state);
    Date currentDate;
    long currentTimeOut = -1;

    // -----------------
    // Date start
    // -----------------
    Date endDate = new Date((new Date()).getTime() + timeout);
    while (!done) {
      // -----------------
      // Find out timeout
      // ----------------
      if (timeout != 0) {
        currentTimeOut = endDate.getTime() - (new Date()).getTime();
        if (currentTimeOut <= 0) {
          done = true;
          break;
        }
      }

      try {
        synchronized (this) {
          if (timeout == 0) {
            if (logger.finerOn()) {
              logger.finer("waitState", "Start waiting infinite, current state = " + this.state);
            }
            done = (this.state == state);
            while (!done) {
              done = (this.state == state);
              try {
                wait(1000);
              } catch (Exception e) {
              }
            }
          } else {
            if (logger.finerOn()) {
              logger.finer(
                  "waitState",
                  "Start waiting " + currentTimeOut + " current state = " + this.state);
            }
            wait(currentTimeOut);
          }
        }
        done = (this.state == state);
      } catch (InterruptedException e) {
        done = (this.state == state);
      }
    }
    if (logger.finerOn()) {
      logger.finer("waitState", "End, TO=" + currentTimeOut);
    }
    return (this.state == state);
  }
Example #14
0
  public List getIterationList(String projectId) {
    List<Map> list = new ArrayList<Map>();

    try {

      String apiUrl =
          rallyApiHost
              + "/iteration?"
              + "project="
              + rallyApiHost
              + "/project/"
              + projectId
              + "&fetch=true&order=Name%20desc&start=1&pagesize=100";

      String checkProjectRef = rallyApiHost + "/project/" + projectId;

      log.info("rallyApiUrl:" + apiUrl);
      log.info("checkProjectRef:" + checkProjectRef);

      String responseXML = getRallyXML(apiUrl);

      SimpleDateFormat ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
      Date currentDate = new Date();

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {

        Map map = new HashMap();

        Element item = (Element) iter.next();
        String objId = item.getChildText("ObjectID");
        String name = item.getChildText("Name");
        String state = item.getChildText("State");

        String startDateStr = item.getChildText("StartDate");
        String endDateStr = item.getChildText("EndDate");

        Date startDate = ISO8601FORMAT.parse(startDateStr);
        Date endDate = ISO8601FORMAT.parse(endDateStr);

        boolean isCurrent = false;

        int startCheck = startDate.compareTo(currentDate);
        int endCheck = endDate.compareTo(currentDate);

        if (startCheck < 0 && endCheck > 0) {
          isCurrent = true;
        }

        log.info("name=" + name + " isCurrent=" + isCurrent);

        String releaseRef = item.getAttribute("ref").getValue();

        // In child project, parent object have to be filiered
        Element projectElement = item.getChild("Project");
        String projectRef = projectElement.getAttributeValue("ref");

        if (projectRef.equals(checkProjectRef)) {

          map.put("objId", objId);
          map.put("rallyRef", releaseRef);
          map.put("name", name);
          map.put("state", state);
          map.put("isCurrent", "" + isCurrent);

          list.add(map);
        }
      }

      log.info("-----------");

    } catch (Exception ex) {
      log.error("ERROR: ", ex);
    }

    return list;
  }
Example #15
0
  int doSMTPTransaction(SMTPInputStream in, SMTPOutputStream out) throws IOException {
    int replyCode;
    Date today = new Date();
    // GET SERVER RESPONSE on CONNECTION ESTABLISHMENT
    // WAIT FOR RESPONSE (WAIT_TIMEOUT) millis
    //      NOT RESPONSE ON CONNECT ERROR CODE 1
    replyCode = waitForTimeout(in);
    if (replyCode == 0) {
      infoArea.Println("NOT RESPONSE ON CONNECT ERROR CODE 1");
      return 1;
    }
    if (replyCode == -1) {
      infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
      return 4;
    }

    if (replyCode != SMTP_RCODE_READY) {
      infoArea.Println("UNSUCCESS CONNECTION ");
      return replyCode;
    }

    infoArea.Println("connection response is OK");
    infoArea.Println("request HELO");

    // SEND HELO CRLF
    out.WriteToStream(SMTPCommand[SMTP_CMD_HELO]);
    out.WriteToStream(SMTPCommand[SMTP_CMD_SPC]);
    out.WriteToStream("127.0.0.1");
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);

    // WAIT FOR RESPONSE ON HELO
    replyCode = waitForTimeout(in);
    if (replyCode == 0) {
      infoArea.Println("NOT RESPONSE TO HELO ERROR CODE 2");
      return 2;
    }
    if (replyCode == -1) {
      infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
      return 4;
    }
    if (replyCode != SMTP_RCODE_COMPLETED) {
      infoArea.Println("UNABLE TO COMPLETE REPLY");
      return replyCode;
    }
    infoArea.Println("HELO response is OK");
    infoArea.Println("request MAIL FROM");

    // SEND MAIL FROM: SPC <sender> CRLF
    out.WriteToStream(SMTPCommand[SMTP_CMD_MAIL_FROM]);
    out.WriteToStream(SMTPCommand[SMTP_CMD_SPC]);
    out.WriteToStream(senderMail.getText());
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);

    // WAIT FOR RESPONSE ON MAIL FROM
    replyCode = waitForTimeout(in);
    if (replyCode == 0) {
      infoArea.Println("NOT RESPONSE TO HELO ERROR CODE 2");
      return 2;
    }
    if (replyCode == -1) {
      infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
      return 4;
    }
    if (replyCode != SMTP_RCODE_COMPLETED) {
      infoArea.Println("UNABLE TO COMPLETE REPLY");
      return replyCode;
    }
    infoArea.Println("MAIL FROM response is OK");
    infoArea.Println("request RCPT TO");

    // SEND RCPT TO: SPC <sender> CRLF
    out.WriteToStream(SMTPCommand[SMTP_CMD_RCPT_TO]);
    out.WriteToStream(SMTPCommand[SMTP_CMD_SPC]);
    out.WriteToStream(reciverMail.getText());
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);

    // WAIT FOR RESPONSE ON RCPT TO
    replyCode = waitForTimeout(in);
    if (replyCode == 0) {
      infoArea.Println("NOT RESPONSE TO HELO ERROR CODE 2");
      return 2;
    }
    if (replyCode == -1) {
      infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
      return 4;
    }
    if ((replyCode != SMTP_RCODE_COMPLETED) && (replyCode != SMTP_RCODE_FORWARD)) {
      infoArea.Println("UNABLE TO COMPLETE REPLY");
      return replyCode;
    }
    infoArea.Println("RCPT TO response is OK");
    // TRY TO SEND TO CC
    if ((ccMail.getText().length()) > 0) {
      infoArea.Println("request CC RCPT TO");
      // SEND RCPT TO: SPC <sender> CRLF
      out.WriteToStream(SMTPCommand[SMTP_CMD_RCPT_TO]);
      out.WriteToStream(SMTPCommand[SMTP_CMD_SPC]);
      out.WriteToStream(ccMail.getText());
      out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);

      // WAIT FOR RESPONSE ON RCPT TO
      replyCode = waitForTimeout(in);
      if (replyCode == 0) {
        infoArea.Println("NOT RESPONSE TO HELO ERROR CODE 2");
        return 2;
      }
      if (replyCode == -1) {
        infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
        return 4;
      }
      if ((replyCode != SMTP_RCODE_COMPLETED) && (replyCode != SMTP_RCODE_FORWARD)) {
        infoArea.Println("UNABLE TO COMPLETE CC");
      } else {
        infoArea.Println("CC.RCPT TO response is OK");
      }
    }
    // TRY TO SEND TO BCC
    if ((bccMail.getText().length()) > 0) {
      // SEND RCPT TO: SPC <sender> CRLF
      out.WriteToStream(SMTPCommand[SMTP_CMD_RCPT_TO]);
      out.WriteToStream(SMTPCommand[SMTP_CMD_SPC]);
      out.WriteToStream(bccMail.getText());
      out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);

      // WAIT FOR RESPONSE ON RCPT TO
      replyCode = waitForTimeout(in);
      if (replyCode == 0) {
        infoArea.Println("NOT RESPONSE TO HELO ERROR CODE 2");
        return 2;
      }
      if (replyCode == -1) {
        infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
        return 4;
      }
      if ((replyCode != SMTP_RCODE_COMPLETED) && (replyCode != SMTP_RCODE_FORWARD)) {
        infoArea.Println("UNABLE TO COMPLETE BCC");
      } else {
        infoArea.Println("BCC.RCPT TO response is OK");
      }
    }
    infoArea.Println("request DATA");

    // SEND DATA CRLF
    out.WriteToStream(SMTPCommand[SMTP_CMD_DATA]);
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);

    // WAIT FOR RESPONSE ON DATA
    replyCode = waitForTimeout(in);
    if (replyCode == 0) {
      infoArea.Println("NOT RESPONSE TO HELO ERROR CODE 2");
      return 2;
    }
    if (replyCode == -1) {
      infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
      return 4;
    }
    if (replyCode != SMTP_RCODE_MAIL_START) {
      infoArea.Println("UNABLE TO COMPLETE REPLY");
      return replyCode;
    }
    infoArea.Println("DATA response is OK");
    infoArea.Println("request DATA");

    // SEND mail content CRLF.CRLF
    out.WriteToStream("Subject: " + subjectMail.getText());
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);
    out.WriteToStream("From: " + senderMail.getText());
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);
    out.WriteToStream("To: " + reciverMail.getText());
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);
    out.WriteToStream("Date: " + today.toString());
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);
    out.WriteToStream(bodyMail.getText());
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF_CRLF]);

    // WAIT FOR RESPONSE ON mail content CRLF.CRLF
    replyCode = waitForTimeout(in);
    if (replyCode == 0) {
      infoArea.Println("NOT RESPONSE TO HELO ERROR CODE 2");
      return 2;
    }
    if (replyCode == -1) {
      infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
      return 4;
    }
    if (replyCode != SMTP_RCODE_COMPLETED) {
      infoArea.Println("UNABLE TO COMPLETE REPLY");
      return replyCode;
    }
    infoArea.Println("mail content response is OK");
    infoArea.Println("request QUIT");

    // SEND QUIT CRLF
    out.WriteToStream(SMTPCommand[SMTP_CMD_QUIT]);
    out.WriteToStream(SMTPCommand[SMTP_CMD_CRLF]);

    // WAIT FOR RESPONSE (WAIT_TIMEOUT) millis
    //      NOT RESPONSE TO QUIT ERROR CODE 3
    replyCode = waitForTimeout(in);
    if (replyCode == 0) {
      infoArea.Println("NOT RESPONSE TO QUIT ERROR CODE 3");
      return 3;
    }
    if (replyCode == -1) {
      infoArea.Println("UNKNOWN REPLY CODE ERROR CODE 4");
      return 4;
    }
    if (replyCode != SMTP_RCODE_CLOSING) {
      infoArea.Println("UNCLOSED CONNECTION REPLY");
      return replyCode;
    }
    infoArea.Println("QUIT response is BYE");
    infoArea.Println("end of SMTP transaction");

    //  TRANSACTION OK ERROR CODE 0
    return 0;
  }
Example #16
0
 /**
  * Returns a long containing the NTP value for a given Java Date.
  *
  * @param d Date to set
  * @return long
  */
 public static long getNtpTime(Date d) throws SdpParseException {
   if (d == null) return -1;
   return ((d.getTime() / 1000) + SdpConstants.NTP_CONST);
 }