@Override public void run() { while (this.isAlive()) { try { if (!groupFail) { // Allow 200 + recent ArrayList<Conversation> newList = new GetConvos(api, acc).getRecentChats(); if (newList != null) { acc.setRecentCache(newList); for (Conversation newGroup : newList) { boolean flag = true; for (Conversation oldGr : acc.getRecent()) { if (oldGr.getId().equals(newGroup.getId())) flag = false; } if (flag) acc.getRecent().add(newGroup); } } } } catch (AccountUnusableForRecentException e) { if (first) groupFail = true; } catch (NullPointerException e) { if (api.isDebugMode()) e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } try { Thread.sleep(5000); } catch (InterruptedException e) { } first = false; } }
public String makeRequest(Skype usr) { try { URL obj = new URL(url); con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod( (type == RequestType.GET ? "GET" : (type == RequestType.POST ? "POST" : (type == RequestType.PUT ? "PUT" : (type == RequestType.DELETE ? "DELETE" : "OPTIONS"))))); con.setRequestProperty( "Content-Type", isForm ? "application/x-www-form-urlencoded" : (file ? "application/octet-stream" : "application/json; charset=utf-8")); con.setRequestProperty("Content-Length", Integer.toString(data.getBytes().length)); con.setRequestProperty("User-Agent", "0/7.7.0.103// libhttpX.X"); con.setRequestProperty("Cookie", api.cookies); con.setDoOutput(true); if (sendLoginHeaders) addLogin(usr); for (Header s : headers) { con.addRequestProperty(s.getType(), s.getData()); } if (!(data.getBytes().length == 0)) { DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.write(data.getBytes()); wr.flush(); wr.close(); } code = con.getResponseCode(); if (code == 200 || code == 201) { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString() == null ? "" : response.toString(); } else if (code == 401) { System.out.println("\n\nBad login..."); System.out.println( this.url + " returned 401. \nHave you been running jSkype for more than 2 days?\nWithin 4 seconds the ping-er should relog you in.\n\n"); return "---"; } else if (code == 204) { return ""; } else { if (code == 404 && url.toLowerCase().contains("endpoint")) { System.out.println("Lost connection to skype.\nReloggin!"); api.getSkype().relog(); api.getPoller().prepare(); } if (api.isDebugMode()) { if (!api.isStfuMode()) { // GetProfile will handle the debugging info if (url.equals("https://api.skype.com/users/self/contacts/profiles")) return null; // Debug info System.out.println( "Error contacting skype\nUrl: " + url + "\nCode: " + code + "\nData: " + data); for (Header header : headers) { System.out.println(header.getType() + ": " + header.getData()); } } } return null; } } catch (UnknownHostException | SocketException e) { return null; } catch (Exception e) { if (api.displayInfoMessages()) { System.out.println("================================================"); System.out.println("========Unable to request the skype api========"); System.out.println("================================================"); System.out.println("Error: " + e.getMessage()); System.out.println("URL: " + url); } e.printStackTrace(); return null; } }