Search in sources :

Example 66 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method getEvents.

public String getEvents(int start, boolean useNewActivity) throws SeafException {
    String apiPath;
    try {
        Map<String, Object> params = Maps.newHashMap();
        if (useNewActivity) {
            apiPath = String.format("api/v2.1/activities/");
            if (start == 0) {
                start = 1;
            }
            params.put("page", start);
        } else {
            apiPath = String.format("api2/events/");
            params.put("start", start);
        }
        HttpRequest req = prepareApiGetRequest(apiPath, params);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        return new String(req.bytes(), "UTF-8");
    } catch (SeafException e) {
        throw e;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    } catch (IOException e) {
        throw SeafException.networkException;
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject) IOException(java.io.IOException)

Example 67 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method delete.

public Pair<String, String> delete(String repoID, String path, boolean isdir) throws SeafException {
    try {
        Map<String, Object> params = Maps.newHashMap();
        params.put("p", encodeUriComponent(path).replaceAll("\\+", "%20"));
        params.put("reloaddir", "true");
        String suffix = isdir ? "/dir/" : "/file/";
        HttpRequest req = prepareApiDeleteRequest("api2/repos/" + repoID + suffix, params);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String newDirID = req.header("oid");
        if (newDirID == null) {
            return null;
        }
        String content = new String(req.bytes(), "UTF-8");
        if (content.length() == 0) {
            return null;
        }
        return new Pair<String, String>(newDirID, content);
    } catch (SeafException e) {
        throw e;
    } catch (UnsupportedEncodingException e) {
        throw SeafException.encodingException;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject) Pair(android.util.Pair)

Example 68 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method completeRemoteWipe.

public void completeRemoteWipe(String token) throws SeafException {
    try {
        HttpRequest req = prepareApiPostRequest("api2/device-wiped/", true, null);
        req.form("token", token);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_CREATED);
    } catch (SeafException e) {
        throw e;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException)

Example 69 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method getBlockDownloadList.

public String getBlockDownloadList(String repoID, String path) throws SeafException, IOException {
    try {
        String apiPath = String.format("api2/repos/%s/file/", repoID);
        Map<String, Object> params = Maps.newHashMap();
        params.put("p", encodeUriComponent(path));
        params.put("op", "downloadblks");
        HttpRequest req = prepareApiGetRequest(apiPath, params);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String result = new String(req.bytes(), "UTF-8");
        return result;
    } catch (SeafException | IOException e) {
        throw e;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject) IOException(java.io.IOException)

Example 70 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.

the class SeafConnection method getDownloadLink.

public Pair<String, String> getDownloadLink(String repoID, String path, boolean isReUsed) throws SeafException {
    try {
        String apiPath = String.format("api2/repos/%s/file/", repoID);
        Map<String, Object> params = Maps.newHashMap();
        params.put("p", encodeUriComponent(path));
        params.put("op", "download");
        if (isReUsed) {
            params.put("reuse", 1);
        }
        HttpRequest req = prepareApiGetRequest(apiPath, params);
        checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
        String result = new String(req.bytes(), "UTF-8");
        String fileID = req.header("oid");
        // should return "\"http://gonggeng.org:8082/...\"" or "\"https://gonggeng.org:8082/...\"
        if (result.startsWith("\"http") && fileID != null) {
            String url = result.substring(1, result.length() - 1);
            return new Pair<String, String>(url, fileID);
        } else {
            throw SeafException.illFormatException;
        }
    } catch (SeafException e) {
        throw e;
    } catch (UnsupportedEncodingException e) {
        throw SeafException.encodingException;
    } catch (IOException e) {
        throw SeafException.networkException;
    } catch (HttpRequestException e) {
        throw getSeafExceptionFromHttpRequestException(e);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpRequestException(com.github.kevinsawicki.http.HttpRequest.HttpRequestException) JSONObject(org.json.JSONObject) IOException(java.io.IOException) Pair(android.util.Pair)

Aggregations

HttpRequest (com.github.kevinsawicki.http.HttpRequest)86 HttpRequestException (com.github.kevinsawicki.http.HttpRequest.HttpRequestException)29 IOException (java.io.IOException)25 JSONObject (org.json.JSONObject)19 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 File (java.io.File)8 TimerTask (java.util.TimerTask)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 Pair (android.util.Pair)6 URL (java.net.URL)5 JSONException (org.json.JSONException)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)4 JSONObject (com.alibaba.fastjson.JSONObject)4 ZipFile (net.lingala.zip4j.ZipFile)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 IPEntity (com.example.li.springboot_crawler_demo.utils.img.entity.IPEntity)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2