use of com.amazonaws.services.s3.Headers in project openhab-android by openhab.
the class MyWebImage method getBitmapFromUrl.
private Bitmap getBitmapFromUrl(Context context, final String url) {
final Map<String, Object> result = new HashMap<String, Object>();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
MyAsyncHttpClient client = new MyAsyncHttpClient(context, prefs.getBoolean(Constants.PREFERENCE_SSLHOST, false), prefs.getBoolean(Constants.PREFERENCE_SSLCERT, false));
client.setTimeout(READ_TIMEOUT);
client.setBaseUrl(url);
if (shouldAuth) {
client.setBasicAuth(authUsername, authPassword);
}
client.get(url, new MyHttpClient.ResponseHandler() {
@Override
public void onFailure(Call call, int statusCode, Headers headers, byte[] responseBody, Throwable error) {
Log.e(TAG, "Failed to get " + url + " with code " + statusCode + ":" + error);
synchronized (result) {
result.put("error", error);
result.notify();
}
}
@Override
public void onSuccess(Call call, int statusCode, Headers headers, byte[] responseBody) {
InputStream is = new ByteArrayInputStream(responseBody);
Map headersMap = headers.toMultimap();
boolean isSVG = headersMap.containsKey("content-type") && headersMap.get("content-type").toString().contains("svg");
synchronized (result) {
result.put("bitmap", getBitmapFromInputStream(isSVG, is));
result.notify();
}
}
});
synchronized (result) {
try {
result.wait(60000);
} catch (InterruptedException e) {
Log.e(TAG, "Timeout fetching " + url);
return null;
}
if (result.containsKey("error")) {
return null;
}
}
Log.i(TAG, "fetched bitmap for " + url);
return (Bitmap) result.get("bitmap");
}
use of com.amazonaws.services.s3.Headers in project openhab-android by openhab.
the class DefaultConnectionTest method testSyncResolveAbsoluteUrl.
@Test
public void testSyncResolveAbsoluteUrl() {
MyHttpClient httpClient = testConnection.getSyncHttpClient();
httpClient.get("http://mylocalmachine.local/rest/test", new MyHttpClient.TextResponseHandler() {
@Override
public void onFailure(Call call, int statusCode, Headers headers, String responseBody, Throwable error) {
assertEquals("http://mylocalmachine.local/rest/test", call.request().url().toString());
}
@Override
public void onSuccess(Call call, int statusCode, Headers headers, String responseBody) {
fail("The request should never succeed in tests.");
}
});
}
use of com.amazonaws.services.s3.Headers in project openhab-android by openhab.
the class MySyncHttpClientTest method testMethodErrorResponse.
/**
* Unit test against Issue #315 "Crash when connection could not be established"
*/
@Test
public void testMethodErrorResponse() {
MySyncHttpClient httpClient = new MySyncHttpClient(null, false, true);
httpClient.setBaseUrl("https://demo.test");
String host = "just.a.local.url.local";
Response resp = httpClient.method("https://" + host, "GET", new HashMap<String, String>(), null, "", new MyHttpClient.ResponseHandler() {
public void onFailure(Call call, int statusCode, Headers headers, byte[] responseBody, Throwable error) {
}
public void onSuccess(Call call, int statusCode, Headers headers, byte[] responseBody) {
}
});
assertEquals(500, resp.code());
assertTrue(resp.message().startsWith(UnknownHostException.class.getName()));
}
use of com.amazonaws.services.s3.Headers in project protools by SeanDragon.
the class ToolSendHttp method send.
public static HttpReceive send(HttpSend httpSend, OkHttpClient okHttpClient) {
final HttpReceive httpReceive = new HttpReceive();
httpReceive.setHaveError(true);
try {
Request request = convertRequest(httpSend);
Call call = okHttpClient.newCall(request);
Response response = call.execute();
ResponseBody body = response.body();
if (body == null) {
throw new HttpException("发送http失败,响应体为空");
}
final Map<String, String> responseHeaders = Maps.newHashMap();
if (httpSend.getNeedReceiveHeaders()) {
final Headers headers = response.headers();
final Set<String> headerNameSet = headers.names();
headerNameSet.forEach(oneHeaderName -> {
final String oneHeaderValue = headers.get(oneHeaderName);
responseHeaders.put(oneHeaderName, oneHeaderValue);
});
}
int responseStatusCode = response.code();
if (responseStatusCode != 200) {
throw new HttpException("本次请求响应码不是200,是" + responseStatusCode);
}
String responseBody = body.string();
if (log.isDebugEnabled()) {
log.debug(responseBody);
}
httpReceive.setResponseBody(responseBody).setHaveError(false).setStatusCode(responseStatusCode).setStatusText(responseStatusCode + "").setResponseHeader(responseHeaders);
response.close();
okHttpClient.dispatcher().executorService().shutdown();
} catch (IOException e) {
httpReceive.setErrMsg("获取返回内容失败!").setThrowable(e);
} catch (HttpException e) {
httpReceive.setErrMsg(e.getMessage()).setThrowable(e);
}
if (httpReceive.getHaveError()) {
if (log.isWarnEnabled()) {
Throwable throwable = httpReceive.getThrowable();
log.warn(ToolFormat.toException(throwable), throwable);
}
}
httpReceive.setIsDone(true);
return httpReceive;
}
use of com.amazonaws.services.s3.Headers in project nifi-minifi by apache.
the class RestChangeIngestorCommonTest method testFileUploadSameConfig.
@Test
public void testFileUploadSameConfig() throws Exception {
when(mockDifferentiator.isNew(Mockito.any(InputStream.class))).thenReturn(false);
Request request = new Request.Builder().url(url).post(RequestBody.create(MEDIA_TYPE_MARKDOWN, testString)).addHeader("charset", "UTF-8").build();
Response response = client.newCall(request).execute();
if (response.isSuccessful())
throw new IOException("Unexpected code " + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
assertEquals("Request received but instance is already running this config.", response.body().string());
verify(testNotifier, Mockito.never()).notifyListeners(Mockito.any());
}
Aggregations