use of com.azure.android.core.http.HttpCallback in project azure-sdk-for-android by Azure.
the class HttpClientTests method sendRequest.
private String sendRequest(String requestPath, String method) {
CountDownLatch latch = new CountDownLatch(1);
final String[] content = new String[1];
final Throwable[] throwable = new Throwable[1];
content[0] = null;
throwable[0] = null;
createHttpClient().send(new HttpRequest(HttpMethod.GET, REQUEST_HOST + ":" + getWireMockPort() + "/" + requestPath), CancellationToken.NONE, new HttpCallback() {
@Override
public void onSuccess(HttpResponse response) {
try {
content[0] = response.getBodyAsString();
} finally {
latch.countDown();
}
}
@Override
public void onError(Throwable error) {
try {
throwable[0] = error;
} finally {
latch.countDown();
}
}
});
awaitOnLatch(latch, "method");
if (throwable[0] != null) {
throw new RuntimeException(throwable[0]);
} else {
return content[0];
}
}
use of com.azure.android.core.http.HttpCallback in project azure-sdk-for-android by Azure.
the class ChatThreadAsyncClientTest method setupMockTest.
private void setupMockTest() {
final NoOpHttpClient httpClient = new NoOpHttpClient() {
@Override
public void send(HttpRequest httpRequest, CancellationToken cancellationToken, HttpCallback httpCallback) {
httpCallback.onSuccess(ChatResponseMocker.createReadReceiptsResponse(httpRequest));
}
};
this.client = getChatClientBuilder(httpClient).buildAsyncClient();
String mockThreadId = "19:4b72178530934b7790135dd9359205e0@thread.v2";
this.chatThreadClient = client.getChatThreadClient(mockThreadId);
this.threadId = chatThreadClient.getChatThreadId();
}
use of com.azure.android.core.http.HttpCallback in project azure-sdk-for-android by Azure.
the class RegistrarClient method register.
public void register(String skypeUserToken, String deviceRegistrationToken, SecretKey cryptoKey, SecretKey authKey) throws Throwable {
String registrarServiceUrl = getRegistrarServiceUrl(skypeUserToken);
HttpRequest request = new HttpRequest(HttpMethod.POST, registrarServiceUrl);
request.setHeader(USER_AGENT_HEADER, PLATFORM_UI_VERSION).setHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON).setHeader(SKYPE_TOKEN_HEADER, skypeUserToken);
addRequestBody(request, deviceRegistrationToken, cryptoKey, authKey);
CountDownLatch latch = new CountDownLatch(1);
final Throwable[] requestError = { null };
this.httpClient.send(request, CancellationToken.NONE, new HttpCallback() {
@Override
public void onSuccess(HttpResponse response) {
int statusCode = response.getStatusCode();
RegistrarClient.this.logger.info("Registrar register http response code:" + statusCode);
if (statusCode != 202) {
requestError[0] = new RuntimeException("Registrar register request failed with http status code " + statusCode + ". Error message: " + response.getBodyAsString());
}
latch.countDown();
}
@Override
public void onError(Throwable error) {
requestError[0] = error;
latch.countDown();
}
});
awaitOnLatch(latch);
if (requestError[0] != null) {
throw logger.logThrowableAsError(requestError[0]);
}
this.logger.info("Register succeed! RegistrationId:" + registrationId);
}
use of com.azure.android.core.http.HttpCallback in project azure-sdk-for-android by Azure.
the class RegistrarClient method unregister.
public void unregister(String skypeUserToken) throws Throwable {
if (registrationId == null) {
return;
}
String registrarServiceUrl = getRegistrarServiceUrl(skypeUserToken);
String unregisterUrl = registrarServiceUrl + "/" + registrationId;
HttpRequest request = new HttpRequest(HttpMethod.DELETE, unregisterUrl);
request.setHeader(USER_AGENT_HEADER, PLATFORM_UI_VERSION).setHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON).setHeader(SKYPE_TOKEN_HEADER, skypeUserToken);
CountDownLatch latch = new CountDownLatch(1);
final Throwable[] requestError = { null };
this.httpClient.send(request, CancellationToken.NONE, new HttpCallback() {
@Override
public void onSuccess(HttpResponse response) {
int statusCode = response.getStatusCode();
RegistrarClient.this.logger.info("Registrar unregister http response code:" + statusCode);
if (statusCode != 202) {
requestError[0] = new RuntimeException("Registrar unregister request failed with http status code " + statusCode + ". Error message: " + response.getBodyAsString());
}
latch.countDown();
}
@Override
public void onError(Throwable error) {
requestError[0] = error;
latch.countDown();
}
});
awaitOnLatch(latch);
if (requestError[0] != null) {
throw logger.logThrowableAsError(requestError[0]);
}
logger.info("Unregister succeed! RegistrationId:" + registrationId);
}
use of com.azure.android.core.http.HttpCallback in project azure-sdk-for-android by Azure.
the class ProtocolPolicyTests method withNoOverwrite.
@Test
public void withNoOverwrite() {
final HttpPipeline pipeline = createPipeline("ftp", false, "https://www.bing.com");
CountDownLatch latch = new CountDownLatch(1);
pipeline.send(createHttpRequest("https://www.bing.com"), RequestContext.NONE, CancellationToken.NONE, new HttpCallback() {
@Override
public void onSuccess(HttpResponse response) {
latch.countDown();
}
@Override
public void onError(Throwable error) {
try {
throw new RuntimeException(error);
} finally {
latch.countDown();
}
}
});
awaitOnLatch(latch, "withNoOverwrite");
}
Aggregations