Java Code Examples for org.apache.http.client.ClientProtocolException#printStackTrace()

The following examples show how to use org.apache.http.client.ClientProtocolException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SirenServiceTest.java    From estatio with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore //This test can hinder a build when the service is down temporarily or returns no results
public void company_query_should_return_company_code() throws Exception {
    // given
    SirenService sirenService = new SirenService();
    sirenService.bearerToken = sirenService.getBearerTokenFromKeyAndSecret("foo", "foo"); // this will fail, but test is ignored anyway

    // when
    List<SirenResult> results = null;
    try {
        results = sirenService.getChamberOfCommerceCodes(COMPANY_QUERY);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    }

    // then
    assertThat(results).isNotNull();
    assertThat(results.size()).isEqualTo(1);
    SirenResult result = results.get(0);
    assertThat(result.getChamberOfCommerceCode()).isEqualTo(COMPANY_CODE);
}
 
Example 2
Source File: SirenServiceTest.java    From estatio with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore //This test can hinder a build when the service is down temporarily or returns no results
public void company_code_should_return_company_name() throws Exception {
    // given
    SirenService sirenService = new SirenService();
    sirenService.bearerToken = sirenService.getBearerTokenFromKeyAndSecret("foo", "foo"); // this will fail, but test is ignored anyway

    // when
    SirenResult result = null;
    try {
        result = sirenService.getCompanyName(COMPANY_CODE);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    }

    // then
    assertThat(result).isNotNull();
    assertThat(result.getCompanyName()).isEqualTo(COMPANY_NAME);
}
 
Example 3
Source File: ElasticSearchUtil.java    From RCT with Apache License 2.0 5 votes vote down vote up
public static boolean deleteIndex(String indexName) throws Exception {
	try {
		String result = httpDelete(getUrl() + "/" + indexName);
		JSONObject json = JSONObject.parseObject(result);
		if (json.containsKey("acknowledged") && json.getBoolean("acknowledged")) {
			return true;
		}
		return false;
	} catch (ClientProtocolException e) {
		e.printStackTrace();
	}
	return false;
}
 
Example 4
Source File: Logger.java    From VideoRecord with MIT License 5 votes vote down vote up
public static void printStackTrace(String TAG, ClientProtocolException e) {
	if (IsDebug) {
		e.printStackTrace();
	} else {
		logException(TAG, e);
	}
}
 
Example 5
Source File: Utils.java    From wd.java with MIT License 5 votes vote down vote up
public String getStatus(String method) throws Exception {
    try {
        String url = Constants.SUFFIX.replace("${host}", driver.getHost()).replace("${port}", driver.getPort()) + method;
        httpget = new HttpGet(url);
        response = httpclient.execute(httpget);
        entity = response.getEntity();
        return String.valueOf(response.getStatusLine().getStatusCode());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    }
    return "get server status error";
}
 
Example 6
Source File: WebServiceClient.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public InputStream get(String s, ArrayList arraylist)
{
    HttpResponse httpresponse;
    int i;
    InputStream inputstream;
    InputStream inputstream1;
    try
    {
        HttpGet httpget = new HttpGet(a(s, arraylist));
        httpresponse = g.execute(httpget);
        i = httpresponse.getStatusLine().getStatusCode();
    }
    catch (ClientProtocolException clientprotocolexception)
    {
        clientprotocolexception.printStackTrace();
        return null;
    }
    catch (IOException ioexception)
    {
        ioexception.printStackTrace();
        return null;
    }
    inputstream = null;
    if (i != 200)
    {
        break MISSING_BLOCK_LABEL_69;
    }
    inputstream1 = httpresponse.getEntity().getContent();
    inputstream = inputstream1;
    return inputstream;
}
 
Example 7
Source File: HttpClientUtil.java    From goods-seckill with Apache License 2.0 4 votes vote down vote up
private String res(HttpRequestBase method) {
    HttpClientContext context = HttpClientContext.create();
    CloseableHttpResponse response = null;
    String content = RESPONSE_CONTENT;
    try {
        response = client.execute(method, context);//执行GET/POST请求
        HttpEntity entity = response.getEntity();//获取响应实体
        if(entity!=null) {
            Charset charset = ContentType.getOrDefault(entity).getCharset();
            content = EntityUtils.toString(entity, charset);
            EntityUtils.consume(entity);
        }
    } catch(ConnectTimeoutException cte) {
        LOG.error("请求连接超时,由于 " + cte.getLocalizedMessage());
        cte.printStackTrace();
    } catch(SocketTimeoutException ste) {
        LOG.error("请求通信超时,由于 " + ste.getLocalizedMessage());
        ste.printStackTrace();
    } catch(ClientProtocolException cpe) {
        LOG.error("协议错误(比如构造HttpGet对象时传入协议不对(将'http'写成'htp')or响应内容不符合),由于 " + cpe.getLocalizedMessage());
        cpe.printStackTrace();
    } catch(IOException ie) {
        LOG.error("实体转换异常或者网络异常, 由于 " + ie.getLocalizedMessage());
        ie.printStackTrace();
    } finally {
        try {
            if(response!=null) {
                response.close();
            }

        } catch(IOException e) {
            LOG.error("响应关闭异常, 由于 " + e.getLocalizedMessage());
        }

        if(method!=null) {
            method.releaseConnection();
        } 

    }

    return content;
}
 
Example 8
Source File: WebServiceClient.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public InputStream post(String s, ArrayList arraylist)
{
    HttpPost httppost = new HttpPost(s);
    ArrayList arraylist1;
    HttpResponse httpresponse;
    int i;
    InputStream inputstream;
    InputStream inputstream1;
    try
    {
        arraylist1 = a();
    }
    catch (ClientProtocolException clientprotocolexception)
    {
        clientprotocolexception.printStackTrace();
        return null;
    }
    catch (IOException ioexception)
    {
        ioexception.printStackTrace();
        return null;
    }
    catch (Exception exception)
    {
        exception.printStackTrace();
        return null;
    }
    if (arraylist == null)
    {
        break MISSING_BLOCK_LABEL_28;
    }
    arraylist1.addAll(arraylist);
    httppost.setEntity(new UrlEncodedFormEntity(arraylist1, "UTF-8"));
    httpresponse = g.execute(httppost);
    i = httpresponse.getStatusLine().getStatusCode();
    inputstream = null;
    if (i != 200)
    {
        break MISSING_BLOCK_LABEL_99;
    }
    inputstream1 = httpresponse.getEntity().getContent();
    inputstream = inputstream1;
    return inputstream;
}