Example usage for org.apache.http.client ClientProtocolException printStackTrace

List of usage examples for org.apache.http.client ClientProtocolException printStackTrace

Introduction

In this page you can find the example usage for org.apache.http.client ClientProtocolException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:csic.ceab.movelab.beepath.Util.java

public static boolean patch2DjangoJSONArray(Context context, JSONArray jsonArray, String uploadurl,
        String username, String password) {

    String response = "";

    try {/*from   ww w.  j  a va 2  s  .  c  o m*/

        JSONObject obj = new JSONObject();
        obj.put("objects", jsonArray);
        JSONArray emptyarray = new JSONArray();
        obj.put("deleted_objects", emptyarray);

        CredentialsProvider credProvider = new BasicCredentialsProvider();
        credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                new UsernamePasswordCredentials(username, password));

        // Create a new HttpClient and Post Header
        HttpPatch httppatch = new HttpPatch(uploadurl);

        HttpParams myParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(myParams, 10000);
        HttpConnectionParams.setSoTimeout(myParams, 60000);
        HttpConnectionParams.setTcpNoDelay(myParams, true);

        httppatch.setHeader("Content-type", "application/json");

        DefaultHttpClient httpclient = new DefaultHttpClient();

        httpclient.setCredentialsProvider(credProvider);
        // ByteArrayEntity bae = new ByteArrayEntity(obj.toString()
        // .getBytes("UTF8"));

        StringEntity se = new StringEntity(obj.toString(), HTTP.UTF_8);
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        // bae.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
        // "application/json"));
        httppatch.setEntity(se);

        // Execute HTTP Post Request

        HttpResponse httpResponse = httpclient.execute(httppatch);

        response = httpResponse.getStatusLine().toString();

    } catch (ClientProtocolException e) {

    } catch (IOException e) {

    } catch (JSONException e) {
        e.printStackTrace();
    }

    if (response.contains("ACCEPTED")) {
        return true;
    } else {
        return false;
    }

}

From source file:com.gemstone.gemfire.rest.internal.web.controllers.RestAPIsAndInterOpsDUnitTest.java

public static void fetchRestServerEndpoints(String restEndpoint) {
    HttpGet get = new HttpGet(restEndpoint + "/servers");
    get.addHeader("Content-Type", "application/json");
    get.addHeader("Accept", "application/json");
    CloseableHttpClient httpclient = HttpClients.createDefault();
    CloseableHttpResponse response;/*  www  . jav a  2 s . co m*/

    try {
        response = httpclient.execute(get);
        HttpEntity entity = response.getEntity();
        InputStream content = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;
        StringBuffer str = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            str.append(line);
        }

        //validate the satus code
        assertEquals(response.getStatusLine().getStatusCode(), 200);

        if (response.getStatusLine().getStatusCode() == 200) {
            JSONArray jsonArray = new JSONArray(str.toString());

            //verify total number of REST service endpoints in DS
            assertEquals(jsonArray.length(), 2);
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        fail(" Rest Request should not have thrown ClientProtocolException!");
    } catch (IOException e) {
        e.printStackTrace();
        fail(" Rest Request should not have thrown IOException!");
    } catch (JSONException e) {
        e.printStackTrace();
        fail(" Rest Request should not have thrown  JSONException!");
    }

}

From source file:free.chessclub.bot.Bot.java

public static String getTinyUrl(String fullUrl) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet get = new HttpGet("http://tinyurl.com/api-create.php?url=" + fullUrl);

    try {//www.j ava2  s  .c  o  m
        HttpResponse response = httpclient.execute(get);
        return EntityUtils.toString(response.getEntity());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.n52.geoar.data.cosm.CosmSource.java

private List<? extends SpatialEntity> searchWikilocationRequest(CosmFilter filter) {
    String request = CosmRequest.buildRequest(filter);
    List<CosmFeed> resultList = null;
    InputStream content = null;/*w ww. j a va 2 s.  c om*/
    try {
        HttpResponse response = mHttpClient.execute(new HttpGet(request));
        content = response.getEntity().getContent();
        resultList = CosmResponse.getCosmFeedsFromResponse(content);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return resultList;
}

From source file:net.noday.cat.web.admin.DwzManager.java

public void gendwz(String url, String alias) {
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://dwz.cn/create.php");
    post.getParams().setParameter("url", url).setParameter("alias", alias);
    try {//from  w ww  .j a v  a2  s . c  om
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = client.execute(post, responseHandler);
        System.out.println(responseBody);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:org.n52.geoar.data.wiki.WikiSource.java

private List<? extends SpatialEntity2<? extends Geometry>> searchWikilocationRequest(WikiFilter filter) {
    String request = WikiRequest.buildRequest(filter);
    List<WikiResult> resultList = null;
    InputStream content = null;//from   w  w w . j  av a2s  .c o m
    try {
        HttpResponse response = mHttpClient.execute(new HttpGet(request));
        content = response.getEntity().getContent();
        resultList = WikiResponse.getWikiresultsFromResponse(content);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return resultList;
}

From source file:goofyhts.torrentkinesis.test.HttpTest.java

@Test
public void testGet() {
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        HttpClientContext context = new HttpClientContext();
        CredentialsProvider credProv = new BasicCredentialsProvider();
        credProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("root", "Whcinhry21#"));
        context.setCredentialsProvider(credProv);
        HttpGet httpGet = new HttpGet("http://localhost:8150/gui/token.html");

        CloseableHttpResponse response = client.execute(httpGet, context);
        String responseBody = IOUtils.toString(response.getEntity().getContent());
        System.out.println(responseBody);
        Document doc = Jsoup.parse(responseBody);
        System.out.println(doc.getElementById("token").text());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();/*from  w  w  w.jav a 2 s .  c om*/
    }
    //Assert.assertTrue(true);
}

From source file:com.aokp.romcontrol.github.tasks.FindMissingCommitDataTask.java

/**
 * gets full GithubObject from github using the commits path and hash to
 * find the full commit data/*from www.  j a v  a2s . co  m*/
 * @param params github api url for commit
 * @return GithubObject containing all possible information
 *         (with all fields the possibility of null exists)
 */
@Override
protected GithubObject doInBackground(String... params) {
    try {
        Log.i(TAG, "looking for commit data @ " + params[0]);
        // damn almost got it into a oneliner :P
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        return new GithubObject(
                new JSONObject(new DefaultHttpClient().execute(new HttpGet(params[0]), responseHandler)));
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.brunocvcunha.taskerbox.impl.custom.hardmob.HardmobEmailAction.java

@Override
public void spreadAction(final String url, String postTitle) {
    EmailAction email = getEmailAction();

    StringBuffer sb = new StringBuffer();
    sb.append(url);//from   w  w  w  .  j a v a2  s .c o  m
    EmailValueVO emailVO = new EmailValueVO();
    emailVO.setTitle("Hardmob - " + postTitle);

    try {
        Document doc = TaskerboxHttpBox.getInstance().getDocumentForURL(url);

        for (Element post : doc.select(".postcontent")) {
            sb.append("<br>");
            sb.append(post.html());
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    emailVO.setBody(sb.toString());
    email.action(emailVO);

}

From source file:ca.ualberta.cs.c301f12t01.serverStorage.Server.java

public void get(String args) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(serverName + args);
    try {/*from   w  ww  . j ava2s.  c  o  m*/
        HttpResponse response1 = httpclient.execute(httpGet);
        // System.out.println(response1.getStatusLine());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}