List of usage examples for org.apache.http.conn ConnectTimeoutException getMessage
public String getMessage()
From source file:kontrol.HttpUtil.java
public static int getStatus(URI url, Locale locale, int timeout) throws IOException { try {//from w ww.ja v a 2s . c o m HttpGet request = new HttpGet(url); request.addHeader("Accept-Language", locale.toLanguageTag()); HttpResponse response = getCookielessHttpClient(timeout).execute(request); if (response.getStatusLine().getStatusCode() >= 400) { System.err.println(url + ":" + response.getStatusLine().getStatusCode()); // System.err.println(response.getStatusLine().getStatusCode() + ":" + IOUtils.toString(response.getEntity().getContent())); } return response.getStatusLine().getStatusCode(); } catch (ConnectTimeoutException e) { System.err.println(e.getMessage()); return -1; } catch (Exception e) { System.err.println(e.getMessage()); return 999; } }
From source file:es.javocsoft.android.lib.toolbox.net.HttpOperations.java
/** * A GET operation.//from w w w. j ava 2 s. c o m * * @param url * @return * @throws Exception */ public static String doGet(String url, Map<String, String> headersData) throws ConnectTimeoutException, SocketTimeoutException, Exception { String res = null; if (LOG_ENABLE) Log.d(TAG, "GET: " + url); URL urlPath = null; try { urlPath = new URL(url); res = ToolBox.net_httpclient_doAction(HTTP_METHOD.GET, urlPath.toString(), null, headersData); } catch (ConnectTimeoutException e) { if (LOG_ENABLE) Log.e(TAG, "GET: Error doing get to service url '" + urlPath.toString() + "': " + e.getMessage(), e); throw e; } catch (SocketTimeoutException e) { if (LOG_ENABLE) Log.e(TAG, "GET: Error doing get to service url '" + urlPath.toString() + "': " + e.getMessage(), e); throw e; } catch (Exception e) { if (LOG_ENABLE) Log.e(TAG, "GET: Error doing get to service url '" + urlPath.toString() + "': " + e.getMessage(), e); throw e; } return res; }
From source file:com.fhc25.percepcion.osiris.mapviewer.common.restutils.RestClient.java
private static void serverConnection(HttpClient client, HttpUriRequest request, RestListener listener) { try {// w w w . j a v a2s . c o m HttpResponse httpResponse = client.execute(request); responseCode = httpResponse.getStatusLine().getStatusCode(); message = httpResponse.getStatusLine().getReasonPhrase(); HttpEntity entity = httpResponse.getEntity(); if (responseCode >= 200 && responseCode <= 299) { InputStream isResponse = null; if (entity != null) { isResponse = entity.getContent(); } listener.onComplete(isResponse); } else { String errorText = convertStreamToString(entity.getContent()); Lgr.e(TAG, errorText); RestError error = null; try { error = new RestError(errorText); } catch (JSONException je) { error = new RestError(-1, 3, "Malformed response"); } listener.onError(error); } Lgr.v(TAG, "ResponseCode: " + responseCode); } catch (ConnectTimeoutException e) { Lgr.e(TAG, e.getMessage()); //e.printStackTrace(); //listener.onError(new KError(508, 0, e.getMessage())); listener.onConnectionFailed(); } catch (SocketTimeoutException e) { Lgr.e(TAG, e.getMessage() + " Socket timeout"); //e.printStackTrace(); //listener.onError(new KError(508, 0, "Server timeout")); listener.onConnectionFailed(); } catch (UnknownHostException e) { Lgr.e(TAG, e.getMessage() + " Connection failed"); /* KError error = null; try { error = new KError(e.getMessage()); } catch (JSONException e1) { Lgr.e(TAG, e.getMessage()); } listener.onError(error); */ listener.onConnectionFailed(); } catch (IOException e) { Lgr.e(TAG, e.getMessage()); RestError error = null; try { error = new RestError(e.getMessage()); } catch (JSONException e1) { Lgr.e(TAG, e.getMessage()); } listener.onError(error); } catch (Exception e) { e.printStackTrace(); listener.onError(new RestError(-1, 0, e.getMessage())); } }
From source file:com.fhc25.percepcion.osiris.mapviewer.common.restutils.RestClientStream.java
private static void serverConnection(HttpClient client, HttpUriRequest request, RestListenerStream listener) { try {//from www . ja v a2 s . c om HttpResponse httpResponse = client.execute(request); mResponseCode = httpResponse.getStatusLine().getStatusCode(); mMessage = httpResponse.getStatusLine().getReasonPhrase(); HttpEntity entity = httpResponse.getEntity(); if (mResponseCode >= 200 && mResponseCode <= 299) { InputStream isResponse = null; if (entity != null) { isResponse = entity.getContent(); } listener.onComplete(isResponse); } else { String errorText = convertStreamToString(entity.getContent()); Lgr.e(TAG, errorText); RestError error = null; try { error = new RestError(errorText); } catch (JSONException je) { error = new RestError(-1, 3, "Malformed response"); } listener.onError(error); } Lgr.v(TAG, "ResponseCode: " + mResponseCode); } catch (ConnectTimeoutException e) { //e.printStackTrace(); //listener.onError(new KError(508, 0, e.getMessage())); listener.onConnectionFailed(); } catch (SocketTimeoutException e) { //e.printStackTrace(); //listener.onError(new KError(508, 0, e.getMessage())); listener.onConnectionFailed(); } catch (UnknownHostException e) { Lgr.e(TAG, e.getMessage()); listener.onConnectionFailed(); } catch (IOException e) { Lgr.e(TAG, e.getMessage()); listener.onConnectionFailed(); } catch (Exception e) { e.printStackTrace(); listener.onError(new RestError(-1, 0, e.getMessage())); } }
From source file:com.ksc.http.KscHttpClientSslHandshakeTimeoutTest.java
@Test(timeout = 60 * 1000) public void testSslHandshakeTimeout() { KSCHttpClient httpClient = new KSCHttpClient( new ClientConfiguration().withSocketTimeout(CLIENT_SOCKET_TO).withMaxErrorRetry(0)); System.out.println("Sending request to localhost..."); try {//from w w w . j a va2s . c om httpClient.execute(new EmptyHttpRequest(server.getHttpsEndpoint(), HttpMethodName.GET), new NullResponseHandler(), new NullErrorResponseHandler(), new ExecutionContext()); fail("Client-side socket read timeout is expected!"); } catch (KscClientException e) { /** * Http client catches the SocketTimeoutException and throws a * ConnectTimeoutException. * {@link org.apache.http.impl.conn.DefaultHttpClientConnectionOperator#connect(ManagedHttpClientConnection, HttpHost, InetSocketAddress, int, SocketConfig, HttpContext)} */ Assert.assertTrue(e.getCause() instanceof ConnectTimeoutException); ConnectTimeoutException cte = (ConnectTimeoutException) e.getCause(); Assert.assertThat(cte.getMessage(), org.hamcrest.Matchers.containsString("Read timed out")); } }
From source file:com.android.volley.toolbox.AdaptedHttpStack.java
@Override public HttpResponse executeRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { org.apache.http.HttpResponse apacheResp; try {//w ww . j ava 2 s . com apacheResp = mHttpStack.performRequest(request, additionalHeaders); } catch (ConnectTimeoutException e) { // BasicNetwork won't know that this exception should be retried like a timeout, since // it's an Apache-specific error, so wrap it in a standard timeout exception. throw new SocketTimeoutException(e.getMessage()); } int statusCode = apacheResp.getStatusLine().getStatusCode(); org.apache.http.Header[] headers = apacheResp.getAllHeaders(); List<Header> headerList = new ArrayList<>(headers.length); for (org.apache.http.Header header : headers) { headerList.add(new Header(header.getName(), header.getValue())); } if (apacheResp.getEntity() == null) { return new HttpResponse(statusCode, headerList); } long contentLength = apacheResp.getEntity().getContentLength(); if ((int) contentLength != contentLength) { throw new IOException("Response too large: " + contentLength); } return new HttpResponse(statusCode, headerList, (int) apacheResp.getEntity().getContentLength(), apacheResp.getEntity().getContent()); }
From source file:bad.robot.http.apache.ApacheExceptionWrappingExecutor.java
@Override public <V> V submit(Callable<V> callable) throws HttpException { try {/* w w w. j ava2 s . c o m*/ return callable.call(); } catch (ConnectTimeoutException e) { throw new HttpConnectionTimeoutException(e); } catch (SocketTimeoutException e) { throw new HttpSocketTimeoutException(e); } catch (HttpHostConnectException e) { throw new HttpConnectionRefusedException(e); } catch (UnknownHostException e) { throw new HttpUnknownHostException(e.getMessage(), e); } catch (Throwable e) { throw new HttpException(e); } }
From source file:net.networksaremadeofstring.rhybudd.DeviceList.java
public void Refresh() { if (dialog != null) { dialog.setTitle("Contacting Zenoss..."); dialog.setMessage("Please wait:\nLoading Infrastructure...."); dialog.setCancelable(false);/* w w w .ja v a2 s. c o m*/ if (!dialog.isShowing()) { dialog.show(); } } else { dialog = new ProgressDialog(this); dialog.setTitle("Contacting Zenoss..."); dialog.setMessage("Please wait:\nLoading Infrastructure...."); dialog.setCancelable(false); dialog.show(); } if (listOfZenossDevices != null) listOfZenossDevices.clear(); ((Thread) new Thread() { public void run() { String MessageExtra = ""; try { Message msg = new Message(); Bundle bundle = new Bundle(); ZenossAPI API = null; try { if (PreferenceManager.getDefaultSharedPreferences(DeviceList.this) .getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) { API = new ZenossAPIZaas(); } else { API = new ZenossAPICore(); } ZenossCredentials credentials = new ZenossCredentials(DeviceList.this); API.Login(credentials); } catch (ConnectTimeoutException cte) { if (cte.getMessage() != null) { bundle.putString("exception", "The connection timed out;\r\n" + cte.getMessage().toString()); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); //Toast.makeText(DeviceList.this, "The connection timed out;\r\n" + cte.getMessage().toString(), Toast.LENGTH_LONG).show(); } else { bundle.putString("exception", "A time out error was encountered but the exception thrown contains no further information."); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); //Toast.makeText(DeviceList.this, "A time out error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show(); } } catch (Exception e) { if (e.getMessage() != null) { bundle.putString("exception", "An error was encountered;\r\n" + e.getMessage().toString()); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); //Toast.makeText(DeviceList.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show(); } else { bundle.putString("exception", "An error was encountered but the exception thrown contains no further information."); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); //Toast.makeText(DeviceList.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show(); } } try { if (API != null) { listOfZenossDevices = API.GetRhybuddDevices(); } else { listOfZenossDevices = null; } } catch (Exception e) { if (e.getMessage() != null) MessageExtra = e.getMessage(); listOfZenossDevices = null; } if (listOfZenossDevices != null && listOfZenossDevices.size() > 0) { DeviceCount = listOfZenossDevices.size(); Message.obtain(); handler.sendEmptyMessage(1); RhybuddDataSource datasource = new RhybuddDataSource(DeviceList.this); datasource.open(); datasource.UpdateRhybuddDevices(listOfZenossDevices); datasource.close(); } else { //Message msg = new Message(); //Bundle bundle = new Bundle(); bundle.putString("exception", "A query to both the local DB and Zenoss API returned no devices. " + MessageExtra); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); } } catch (Exception e) { //BugSenseHandler.log("DeviceList", e); Message msg = new Message(); Bundle bundle = new Bundle(); bundle.putString("exception", e.getMessage()); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); } } }).start(); }