1 package club.wpia.gigi.ping;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.net.HttpURLConnection;
9 import club.wpia.gigi.dbObjects.CertificateOwner;
10 import club.wpia.gigi.dbObjects.Domain;
11 import club.wpia.gigi.util.SystemKeywords;
13 public class HTTPFetch extends DomainPinger {
16 public void ping(Domain domain, String expToken, CertificateOwner user, int confId) {
18 String[] tokenParts = expToken.split(":", 2);
19 URL u = new URL("http://" + domain.getSuffix() + "/" + SystemKeywords.HTTP_CHALLENGE_PREFIX + tokenParts[0] + ".txt");
20 HttpURLConnection huc = (HttpURLConnection) u.openConnection();
21 if (huc.getResponseCode() != 200) {
22 enterPingResult(confId, "error", "Invalid status code " + huc.getResponseCode() + ".", null);
25 BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream(), "UTF-8"));
26 String line = br.readLine();
28 enterPingResult(confId, "error", "Empty document.", null);
31 if (line.trim().equals(tokenParts[1])) {
32 enterPingResult(confId, PING_SUCCEDED, "", null);
35 enterPingResult(confId, "error", "Challenge tokens differed.", null);
37 } catch (IOException e) {
39 enterPingResult(confId, "error", "Exception: connection closed.", null);