Example #1
0
 //	 @Scheduled(cron = "1 0/5 * * * *")
 private void refreshCookie() {
   resetMethod();
   try {
     httpMethod.setPath("/");
     httpClient.executeMethod(httpMethod);
   } catch (HttpException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #2
0
  public boolean checkWeibo() {
    //		if (null == account.getCookie()) {
    if (null == clientMap.get(account.getUsername())) {
      //			System.out.println("false");
      logger.info("false");
      return false;
    }
    try {
      resetMethod();
      httpMethod.setPath("/");
      try {
        httpClient.executeMethod(httpMethod);
      } catch (Exception e) {
        logger.error(e.getMessage());
        return false;
      }
      String response = "";
      if (httpMethod.getStatusCode() == 200) {

        //				logger.info("check httpclient 200");
        try {
          response = new String(httpMethod.getResponseBody(), "UTF-8");
        } catch (Exception e) {
          logger.error(e.getMessage());
        }
      } else {
        logger.info("check httpClient " + httpMethod.getStatusCode());
      }
      // HttpURLConnection connection =
      // resetGetConnection("http://weibo.com/");
      // connection.connect();
      // String response = IOUtils.toString(connection.getInputStream(),
      // "UTF-8");
      // connection.disconnect();
      //			System.out.println(response);
      boolean succ = response.indexOf("ๆˆ‘็š„้ฆ–้กต") > 0;
      //			System.out.println(succ);
      logger.info(succ);
      httpMethod.releaseConnection();
      return succ;
    } catch (Exception e1) {
      e1.printStackTrace();
    }
    return false;
  }