use of com.azure.android.core.http.HttpResponse in project azure-sdk-for-android by Azure.
the class PlaybackClient method send.
@Override
public void send(HttpRequest httpRequest, CancellationToken cancellationToken, HttpCallback httpCallback) {
try {
HttpResponse httpResponse = playbackHttpResponse(httpRequest);
httpCallback.onSuccess(httpResponse);
} catch (Throwable error) {
httpCallback.onError(error);
}
}
use of com.azure.android.core.http.HttpResponse 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.HttpResponse 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.HttpResponse 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");
}
use of com.azure.android.core.http.HttpResponse in project azure-sdk-for-android by Azure.
the class RequestIdPolicyTests method newRequestIdForEachCall.
@Test
public void newRequestIdForEachCall() {
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(new NoOpHttpClient() {
String firstRequestId = null;
@Override
public void send(HttpRequest request, CancellationToken cancellationToken, HttpCallback httpCallback) {
if (firstRequestId != null) {
String newRequestId = request.getHeaders().getValue(REQUEST_ID_HEADER);
Assertions.assertNotNull(newRequestId, "newRequestId should not be null");
Assertions.assertNotEquals(newRequestId, firstRequestId);
}
firstRequestId = request.getHeaders().getValue(REQUEST_ID_HEADER);
if (firstRequestId == null) {
Assertions.fail("The firstRequestId should not be null.");
}
httpCallback.onSuccess(mockResponse);
}
}).policies(new RequestIdPolicy()).build();
CountDownLatch latch1 = new CountDownLatch(1);
pipeline.send(new HttpRequest(HttpMethod.GET, "http://localhost/"), RequestContext.NONE, CancellationToken.NONE, new HttpCallback() {
@Override
public void onSuccess(HttpResponse response) {
latch1.countDown();
}
@Override
public void onError(Throwable error) {
try {
throw new RuntimeException(error);
} finally {
latch1.countDown();
}
}
});
awaitOnLatch(latch1, "newRequestIdForEachCall");
CountDownLatch latch2 = new CountDownLatch(1);
pipeline.send(new HttpRequest(HttpMethod.GET, "http://localhost/"), RequestContext.NONE, CancellationToken.NONE, new HttpCallback() {
@Override
public void onSuccess(HttpResponse response) {
latch2.countDown();
}
@Override
public void onError(Throwable error) {
try {
throw new RuntimeException(error);
} finally {
latch2.countDown();
}
}
});
awaitOnLatch(latch2, "newRequestIdForEachCall");
}
Aggregations