Search in sources :

Example 41 with HttpClient

use of org.apache.http.client.HttpClient in project intellij-community by JetBrains.

the class AuthenticationService method acceptSSLServerCertificate.

public boolean acceptSSLServerCertificate(@Nullable SVNURL repositoryUrl, final String realm) throws SvnBindException {
    if (repositoryUrl == null) {
        return false;
    }
    boolean result;
    if (Registry.is("svn.use.svnkit.for.https.server.certificate.check")) {
        result = new SSLServerCertificateAuthenticator(this, repositoryUrl, realm).tryAuthenticate();
    } else {
        HttpClient client = getClient(repositoryUrl);
        try {
            client.execute(new HttpGet(repositoryUrl.toDecodedString()));
            result = true;
        } catch (IOException e) {
            throw new SvnBindException(fixMessage(e), e);
        }
    }
    return result;
}
Also used : SvnBindException(org.jetbrains.idea.svn.commandLine.SvnBindException) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) IOException(java.io.IOException)

Example 42 with HttpClient

use of org.apache.http.client.HttpClient in project screenbird by adamhub.

the class FileUtil method postFile.

/**
     * Uploads a file via a POST request to a URL.
     * @param fileLocation  path to the file that will be uploaded
     * @param title         title of the video
     * @param slug          slug of the video 
     * @param description   description of the video
     * @param video_type    format of the video (mp4, mpg, avi, etc.)
     * @param checksum      checksum of the file that will be uploaded
     * @param is_public     publicity settings of the file
     * @param pbUpload      progress bar for the upload
     * @param fileSize      the length, in bytes, of the file to be uploaded
     * @param csrf_token    csrf token for the POST request
     * @param user_id       Screenbird user id of the uploader
     * @param channel_id    Screenbird channel id to where the video will be uploaded to
     * @param an_tok        anonymous token identifier if the uploader is not logged in to Screenbird
     * @param listener      listener for the upload
     * @param upload_url    URL where the POST request will be sent to.
     * @return
     * @throws IOException 
     */
public static String[] postFile(String fileLocation, String title, String slug, String description, String video_type, String checksum, Boolean is_public, final JProgressBar pbUpload, long fileSize, String csrf_token, String user_id, String channel_id, String an_tok, ProgressBarUploadProgressListener listener, String upload_url) throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost(upload_url);
    File file = new File(fileLocation);
    ProgressMultiPartEntity mpEntity = new ProgressMultiPartEntity(listener);
    ContentBody cbFile = new FileBody(file, "video/quicktime");
    mpEntity.addPart("videoupload", cbFile);
    ContentBody cbToken = new StringBody(title);
    mpEntity.addPart("csrfmiddlewaretoken", cbToken);
    ContentBody cbUser_id = new StringBody(user_id);
    mpEntity.addPart("user_id", cbUser_id);
    ContentBody cbChannel_id = new StringBody(channel_id);
    mpEntity.addPart("channel_id", cbChannel_id);
    ContentBody cbAnonym_id = new StringBody(an_tok);
    mpEntity.addPart("an_tok", cbAnonym_id);
    ContentBody cbTitle = new StringBody(title);
    mpEntity.addPart("title", cbTitle);
    ContentBody cbSlug = new StringBody(slug);
    mpEntity.addPart("slug", cbSlug);
    ContentBody cbPublic = new StringBody(is_public ? "1" : "0");
    mpEntity.addPart("is_public", cbPublic);
    ContentBody cbDescription = new StringBody(description);
    mpEntity.addPart("description", cbDescription);
    ContentBody cbChecksum = new StringBody(checksum);
    mpEntity.addPart("checksum", cbChecksum);
    ContentBody cbType = new StringBody(video_type);
    mpEntity.addPart("video_type", cbType);
    httppost.setEntity(mpEntity);
    log("===================================================");
    log("executing request " + httppost.getRequestLine());
    log("===================================================");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    String[] result = new String[2];
    String status = response.getStatusLine().toString();
    result[0] = (status.indexOf("200") >= 0) ? "200" : status;
    log("===================================================");
    log("response " + response.toString());
    log("===================================================");
    if (resEntity != null) {
        result[1] = EntityUtils.toString(resEntity);
        EntityUtils.consume(resEntity);
    }
    httpclient.getConnectionManager().shutdown();
    return result;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ContentBody(org.apache.http.entity.mime.content.ContentBody) FileBody(org.apache.http.entity.mime.content.FileBody) HttpEntity(org.apache.http.HttpEntity) StringBody(org.apache.http.entity.mime.content.StringBody) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) ProgressMultiPartEntity(com.bixly.pastevid.screencap.components.progressbar.ProgressMultiPartEntity) HttpResponse(org.apache.http.HttpResponse) File(java.io.File) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 43 with HttpClient

use of org.apache.http.client.HttpClient in project android-player-samples by BrightcoveOS.

the class MainActivity method httpGet.

public String httpGet(String url) {
    String domain = getResources().getString(R.string.ais_domain);
    String result = "";
    CookieStore cookieStore = new BasicCookieStore();
    BasicHttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    // If we have a cookie stored, parse and use it. Otherwise, use a default http client.
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);
        if (!authorizationCookie.equals("")) {
            String[] cookies = authorizationCookie.split(";");
            for (int i = 0; i < cookies.length; i++) {
                String[] kvp = cookies[i].split("=");
                if (kvp.length != 2) {
                    throw new Exception("Illegal cookie: missing key/value pair.");
                }
                BasicClientCookie c = new BasicClientCookie(kvp[0], kvp[1]);
                c.setDomain(domain);
                cookieStore.addCookie(c);
            }
        }
        HttpResponse httpResponse = httpClient.execute(httpGet, localContext);
        result = EntityUtils.toString(httpResponse.getEntity());
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage());
    }
    return result;
}
Also used : CookieStore(org.apache.http.client.CookieStore) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 44 with HttpClient

use of org.apache.http.client.HttpClient in project intellij-community by JetBrains.

the class TrelloRepository method executeMethod.

@Nullable
private <T> T executeMethod(@NotNull HttpUriRequest method, @NotNull ResponseHandler<T> handler) throws Exception {
    final HttpClient client = getHttpClient();
    final HttpResponse response = client.execute(method);
    final StatusLine statusLine = response.getStatusLine();
    if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
        final Header header = response.getFirstHeader("Content-Type");
        if (header != null && header.getValue().startsWith("text/plain")) {
            final String entityContent = TaskResponseUtil.getResponseContentAsString(response);
            throw new Exception(TaskBundle.message("failure.server.message", StringUtil.capitalize(entityContent)));
        }
        throw new Exception(TaskBundle.message("failure.http.error", statusLine.getStatusCode(), statusLine.getStatusCode()));
    }
    return handler.handleResponse(response);
}
Also used : HttpClient(org.apache.http.client.HttpClient) JsonParseException(com.google.gson.JsonParseException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 45 with HttpClient

use of org.apache.http.client.HttpClient in project intellij-community by JetBrains.

the class RedmineRepository method fetchIssues.

public List<RedmineIssue> fetchIssues(String query, int offset, int limit, boolean withClosed) throws Exception {
    ensureProjectsDiscovered();
    // Legacy API, can't find proper documentation
    //if (StringUtil.isNotEmpty(query)) {
    //  builder.addParameter("fields[]", "subject").addParameter("operators[subject]", "~").addParameter("values[subject][]", query);
    //}
    HttpClient client = getHttpClient();
    HttpGet method = new HttpGet(getIssuesUrl(offset, limit, withClosed));
    IssuesWrapper wrapper = client.execute(method, new GsonSingleObjectDeserializer<>(GSON, IssuesWrapper.class));
    return wrapper == null ? Collections.<RedmineIssue>emptyList() : wrapper.getIssues();
}
Also used : HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet)

Aggregations

HttpClient (org.apache.http.client.HttpClient)941 HttpResponse (org.apache.http.HttpResponse)584 HttpGet (org.apache.http.client.methods.HttpGet)429 IOException (java.io.IOException)308 Test (org.junit.Test)275 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)272 HttpPost (org.apache.http.client.methods.HttpPost)212 HttpEntity (org.apache.http.HttpEntity)128 URI (java.net.URI)92 InputStream (java.io.InputStream)81 StringEntity (org.apache.http.entity.StringEntity)74 ArrayList (java.util.ArrayList)69 ClientProtocolException (org.apache.http.client.ClientProtocolException)66 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)61 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)61 InputStreamReader (java.io.InputStreamReader)59 URL (java.net.URL)57 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)53 URISyntaxException (java.net.URISyntaxException)50 MockResponse (com.google.mockwebserver.MockResponse)48