use of org.apache.http.conn.ConnectTimeoutException in project XPrivacy by M66B.
the class Util method bug.
public static void bug(XHook hook, Throwable ex) {
if (ex instanceof InvocationTargetException) {
InvocationTargetException exex = (InvocationTargetException) ex;
if (exex.getTargetException() != null)
ex = exex.getTargetException();
}
int priority;
if (ex instanceof ActivityShare.AbortException)
priority = Log.WARN;
else if (ex instanceof ActivityShare.ServerException)
priority = Log.WARN;
else if (ex instanceof ConnectTimeoutException)
priority = Log.WARN;
else if (ex instanceof FileNotFoundException)
priority = Log.WARN;
else if (ex instanceof HttpHostConnectException)
priority = Log.WARN;
else if (ex instanceof NameNotFoundException)
priority = Log.WARN;
else if (ex instanceof NoClassDefFoundError)
priority = Log.WARN;
else if (ex instanceof OutOfMemoryError)
priority = Log.WARN;
else if (ex instanceof RuntimeException)
priority = Log.WARN;
else if (ex instanceof SecurityException)
priority = Log.WARN;
else if (ex instanceof SocketTimeoutException)
priority = Log.WARN;
else if (ex instanceof SSLPeerUnverifiedException)
priority = Log.WARN;
else if (ex instanceof StackOverflowError)
priority = Log.WARN;
else if (ex instanceof TransactionTooLargeException)
priority = Log.WARN;
else if (ex instanceof UnknownHostException)
priority = Log.WARN;
else if (ex instanceof UnsatisfiedLinkError)
priority = Log.WARN;
else
priority = Log.ERROR;
boolean xprivacy = false;
for (StackTraceElement frame : ex.getStackTrace()) if (frame.getClassName() != null && frame.getClassName().startsWith("biz.bokhorst.xprivacy")) {
xprivacy = true;
break;
}
if (!xprivacy)
priority = Log.WARN;
log(hook, priority, ex.toString() + " uid=" + Process.myUid() + "\n" + Log.getStackTraceString(ex));
}
use of org.apache.http.conn.ConnectTimeoutException in project OkVolley by googolmo.
the class OkNetwork method performRequest.
@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
long requestStart = SystemClock.elapsedRealtime();
while (true) {
Response httpResponse = null;
byte[] responseContents = null;
Map<String, String> responseHeaders = Collections.emptyMap();
try {
// Gather headers.
Map<String, String> headers = new HashMap<String, String>();
addCacheHeaders(headers, request.getCacheEntry());
httpResponse = mHttpStack.performRequest(request, headers);
int statusCode = httpResponse.code();
responseHeaders = new TreeMap<String, String>();
for (String field : httpResponse.headers().names()) {
responseHeaders.put(field, httpResponse.headers().get(field));
}
// Handle cache validation.
if (statusCode == 304) {
return new NetworkResponse(304, request.getCacheEntry().data, responseHeaders, true);
}
if (httpResponse.body() != null) {
if (responseGzip(responseHeaders)) {
Buffer buffer = new Buffer();
GzipSource gzipSource = new GzipSource(httpResponse.body().source());
while (gzipSource.read(buffer, Integer.MAX_VALUE) != -1) {
}
responseContents = buffer.readByteArray();
} else {
responseContents = httpResponse.body().bytes();
}
} else {
responseContents = new byte[0];
}
// // Some responses such as 204s do not have content. We must check.
// if (httpResponse.getEntity() != null) {
// responseContents = entityToBytes(httpResponse.getEntity()
// , responseGzip(responseHeaders));
// } else {
// // Add 0 byte response as a way of honestly representing a
// // no-content request.
// responseContents = new byte[0];
// }
// if the request is slow, log it.
long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
logSlowRequests(requestLifetime, request, responseContents, httpResponse);
if (statusCode < 200 || statusCode > 299) {
throw new IOException();
}
return new NetworkResponse(statusCode, responseContents, responseHeaders, false);
} catch (SocketTimeoutException e) {
attemptRetryOnException("socket", request, new TimeoutError());
} catch (ConnectTimeoutException e) {
attemptRetryOnException("connection", request, new TimeoutError());
} catch (MalformedURLException e) {
throw new RuntimeException("Bad URL " + request.getUrl(), e);
} catch (IOException e) {
int statusCode;
NetworkResponse networkResponse = null;
if (httpResponse != null) {
statusCode = httpResponse.code();
} else {
throw new NoConnectionError(e);
}
VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
if (responseContents != null) {
networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false);
if (statusCode == 401 || statusCode == 403) {
attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
} else {
// TODO: Only throw ServerError for 5xx status codes.
throw new ServerError(networkResponse);
}
} else {
throw new NetworkError(networkResponse);
}
}
}
}
use of org.apache.http.conn.ConnectTimeoutException in project docker-maven-plugin by fabric8io.
the class AuthConfigFactory method createStandardAuthConfig.
/**
* Create an authentication config object which can be used for communication with a Docker registry
*
* The authentication information is looked up at various places (in this order):
*
* <ul>
* <li>From system properties</li>
* <li>From the provided map which can contain key-value pairs</li>
* <li>From the openshift settings in ~/.config/kube</li>
* <li>From the Maven settings stored typically in ~/.m2/settings.xml</li>
* </ul>
*
* The following properties (prefix with 'docker.' or 'registry.') and config key are evaluated:
*
* <ul>
* <li>username: User to authenticate</li>
* <li>password: Password to authenticate. Can be encrypted</li>
* <li>email: Optional EMail address which is send to the registry, too</li>
* </ul>
*
* @param isPush if true this AuthConfig is created for a push, if false it's for a pull
* @param authConfigMap String-String Map holding configuration info from the plugin's configuration. Can be <code>null</code> in
* which case the settings are consulted.
* @param settings the global Maven settings object
* @param user user to check for
* @param registry registry to use, might be null in which case a default registry is checked,
* @return the authentication configuration or <code>null</code> if none could be found
*
* @throws MojoFailureException
*/
private AuthConfig createStandardAuthConfig(boolean isPush, Map authConfigMap, Settings settings, String user, String registry) throws MojoExecutionException {
AuthConfig ret;
// Check first for specific configuration based on direction (pull or push), then for a default value
for (LookupMode lookupMode : new LookupMode[] { getLookupMode(isPush), LookupMode.DEFAULT, LookupMode.REGISTRY }) {
// System properties docker.username and docker.password always take precedence
ret = getAuthConfigFromSystemProperties(lookupMode);
if (ret != null) {
log.debug("AuthConfig: credentials from system properties");
return ret;
}
// Check for openshift authentication either from the plugin config or from system props
if (lookupMode != LookupMode.REGISTRY) {
ret = getAuthConfigFromOpenShiftConfig(lookupMode, authConfigMap);
if (ret != null) {
log.debug("AuthConfig: OpenShift credentials");
return ret;
}
}
// Get configuration from global plugin config
ret = getAuthConfigFromPluginConfiguration(lookupMode, authConfigMap);
if (ret != null) {
log.debug("AuthConfig: credentials from plugin config");
return ret;
}
}
// ===================================================================
// These are lookups based on registry only, so the direction (push or pull) doesn't matter:
// Now lets lookup the registry & user from ~/.m2/setting.xml
ret = getAuthConfigFromSettings(settings, user, registry);
if (ret != null) {
log.debug("AuthConfig: credentials from ~/.m2/setting.xml");
return ret;
}
// check EC2 instance role if registry is ECR
if (EcrExtendedAuth.isAwsRegistry(registry)) {
ret = getAuthConfigViaAwsSdk();
if (ret != null) {
log.debug("AuthConfig: AWS credentials from AWS SDK");
return ret;
}
ret = getAuthConfigFromAwsEnvironmentVariables();
if (ret != null) {
log.debug("AuthConfig: AWS credentials from ENV variables");
return ret;
}
try {
ret = getAuthConfigFromEC2InstanceRole();
} catch (ConnectTimeoutException ex) {
log.debug("Connection timeout while retrieving instance meta-data, likely not an EC2 instance (%s)", ex.getMessage());
} catch (IOException ex) {
// don't make that an error since it may fail if not run on an EC2 instance
log.warn("Error while retrieving EC2 instance credentials: %s", ex.getMessage());
}
if (ret != null) {
log.debug("AuthConfig: credentials from EC2 instance role");
return ret;
}
try {
ret = getAuthConfigFromTaskRole();
} catch (ConnectTimeoutException ex) {
log.debug("Connection timeout while retrieving ECS meta-data, likely not an ECS instance (%s)", ex.getMessage());
} catch (IOException ex) {
log.warn("Error while retrieving ECS Task role credentials: %s", ex.getMessage());
}
if (ret != null) {
log.debug("AuthConfig: credentials from ECS Task role");
return ret;
}
}
// No authentication found
return null;
}
use of org.apache.http.conn.ConnectTimeoutException in project UltimateAndroid by cymcsg.
the class HttpUtils method uploadFiles.
public static String uploadFiles(String url, List<NameValuePair> paramsList, String fileParams, List<File> files) throws Exception {
String result = "";
try {
DefaultHttpClient mHttpClient;
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000);
mHttpClient = new DefaultHttpClient(params);
HttpPost httpPost = new HttpPost(url);
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
if (BasicUtils.judgeNotNull(paramsList)) {
for (NameValuePair nameValuePair : paramsList) {
entityBuilder.addTextBody(nameValuePair.getName(), nameValuePair.getValue());
}
}
// entityBuilder.addBinaryBody(fileParams, file);
for (File f : files) {
if (f != null && f.exists())
entityBuilder.addBinaryBody(fileParams, f);
}
HttpEntity entity = entityBuilder.build();
httpPost.setEntity(entity);
HttpResponse httpResp = mHttpClient.execute(httpPost);
if (httpResp.getStatusLine().getStatusCode() == 200) {
result = EntityUtils.toString(httpResp.getEntity(), "UTF-8");
Logs.d("HttpPost success :");
Logs.d(result);
} else {
Logs.d("HttpPost failed" + " " + httpResp.getStatusLine().getStatusCode() + " " + EntityUtils.toString(httpResp.getEntity(), "UTF-8"));
result = "HttpPost failed";
}
} catch (ConnectTimeoutException e) {
result = "ConnectTimeoutException";
Logs.e("HttpPost overtime: " + "");
} catch (Exception e) {
e.printStackTrace();
Logs.e(e, "");
result = "Exception";
}
return result;
}
use of org.apache.http.conn.ConnectTimeoutException in project UltimateAndroid by cymcsg.
the class HttpUtils_Deprecated method getResponseFromPostUrl.
/*
* 发送POST请求,通过URL和参数获取服务器反馈应答,通过返回的应答对象 在对数据头进行分析(如获得报文头 报文体等)
*/
public static String getResponseFromPostUrl(String url, String logininfo, List<NameValuePair> params) throws Exception {
String result = null;
// 新建HttpPost对象
HttpPost httpPost = new HttpPost(url);
// 设置字符集
HttpEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
// 设置参数实体
httpPost.setEntity(entity);
// 获取HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
//连接超时
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
//请求超时
httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000);
try {
// 获取HttpResponse实例
HttpResponse httpResp = httpClient.execute(httpPost);
// 判断是够请求成功
if (httpResp.getStatusLine().getStatusCode() == 200) {
// 获取返回的数据
result = EntityUtils.toString(httpResp.getEntity(), "UTF-8");
Logs.d("HttpPost方式请求成功,返回数据如下:");
Logs.d(result);
} else {
Logs.d("HttpPost方式请求失败" + " " + httpResp.getStatusLine().getStatusCode() + " " + EntityUtils.toString(httpResp.getEntity(), "UTF-8"));
result = "connect_failed";
}
} catch (ConnectTimeoutException e) {
result = "over_time";
Logs.e("HttpPost方式请求失败: " + "操作超时");
} catch (Exception e) {
e.printStackTrace();
Logs.e(e.getMessage());
Logs.e(e.getMessage(), "");
result = "over_time";
}
return result;
}
Aggregations