1 package org.cacert.gigi.ping;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.net.HttpURLConnection;
9 import org.cacert.gigi.dbObjects.CertificateOwner;
10 import org.cacert.gigi.dbObjects.Domain;
12 public class HTTPFetch extends DomainPinger {
15 public void ping(Domain domain, String expToken, CertificateOwner user, int confId) {
17 String[] tokenParts = expToken.split(":", 2);
18 URL u = new URL("http://" + domain.getSuffix() + "/cacert-" + tokenParts[0] + ".txt");
19 HttpURLConnection huc = (HttpURLConnection) u.openConnection();
20 if (huc.getResponseCode() != 200) {
21 enterPingResult(confId, "error", "Invalid status code " + huc.getResponseCode() + ".", null);
24 BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream(), "UTF-8"));
25 String line = br.readLine();
27 enterPingResult(confId, "error", "Empty document.", null);
30 if (line.trim().equals(tokenParts[1])) {
31 enterPingResult(confId, PING_SUCCEDED, "", null);
34 enterPingResult(confId, "error", "Challenge tokens differed.", null);
36 } catch (IOException e) {
38 enterPingResult(confId, "error", "Exception: connection closed.", null);