use of com.microsoft.graph.core.ClientException in project msgraph-sdk-java by microsoftgraph.
the class BaseRequest method getRequestUrl.
/**
* Gets the request URL
*
* @return the request URL
*/
@Override
public URL getRequestUrl() {
String requestUrl = addFunctionParameters();
URI baseUrl = URI.create(requestUrl);
final UriBuilder uriBuilder = UriBuilder.fromUri(baseUrl);
for (final QueryOption option : queryOptions) {
uriBuilder.queryParam(option.getName(), option.getValue().toString());
}
try {
return new URL(uriBuilder.build().toString());
} catch (final MalformedURLException e) {
if (this instanceof CustomRequest) {
this.getClient().getLogger().logError("Invalid custom URL: " + uriBuilder.toString(), e);
} else {
throw new ClientException("Invalid URL: " + uriBuilder.toString(), e);
}
}
return null;
}
use of com.microsoft.graph.core.ClientException in project msgraph-sdk-java by microsoftgraph.
the class ChunkedUploadRequest method upload.
/**
* Upload a chunk with tries.
*
* @param responseHandler The handler to handle the HTTP response.
* @param <UploadType> The upload item type.
* @return The upload result.
*/
public <UploadType> ChunkedUploadResult<UploadType> upload(final ChunkedUploadResponseHandler<UploadType> responseHandler) {
while (this.retryCount < this.maxRetry) {
try {
Thread.sleep(RETRY_DELAY * this.retryCount * this.retryCount);
} catch (final InterruptedException e) {
throw new ClientException("Exception while waiting to retry file upload.", e);
}
ChunkedUploadResult<UploadType> result = null;
try {
result = this.baseRequest.getClient().getHttpProvider().send(baseRequest, ChunkedUploadResult.class, this.data, responseHandler);
} catch (final ClientException e) {
throw new ClientException("Request failed with error, retry if necessary.", e);
}
if (result != null && result.chunkCompleted()) {
return result;
}
this.retryCount++;
}
return new ChunkedUploadResult<UploadType>(new ClientException("Upload session failed too many times.", null));
}
use of com.microsoft.graph.core.ClientException in project msgraph-sdk-java by microsoftgraph.
the class GraphServiceClientTest method testOverrideOfDefaultExecutors.
@Test
public void testOverrideOfDefaultExecutors() {
IExecutors ex = new IExecutors() {
@Override
public void performOnBackground(Runnable runnable) {
// do nothing
}
@Override
public <Result> void performOnForeground(Result result, ICallback<Result> callback) {
// do nothing
}
@Override
public <Result> void performOnForeground(int progress, int progressMax, IProgressCallback<Result> callback) {
// do nothing
}
@Override
public <Result> void performOnForeground(ClientException exception, ICallback<Result> callback) {
// do nothing
}
};
IGraphServiceClient client = //
GraphServiceClient.builder().authenticationProvider(//
auth).executors(//
ex).buildClient();
assertEquals(ex, client.getExecutors());
assertEquals(auth, client.getAuthenticationProvider());
assertNotNull(client.getHttpProvider());
assertNotNull(client.getLogger());
assertNotNull(client.getSerializer());
assertEquals(ex, ((DefaultHttpProvider) client.getHttpProvider()).getExecutors());
}
use of com.microsoft.graph.core.ClientException in project msgraph-sdk-java by microsoftgraph.
the class BaseStreamRequestTests method testSendWithContentAndCallback.
@Test
public void testSendWithContentAndCallback() {
final ITestConnectionData data = new ITestConnectionData() {
@Override
public int getRequestCode() {
return 200;
}
@Override
public String getJsonResponse() {
return "{ \"id\": \"zzz\" }";
}
@Override
public Map<String, String> getHeaders() {
final HashMap<String, String> map = new HashMap<>();
map.put("Content-Type", "application/json");
return map;
}
};
DefaultHttpProvider mProvider = new DefaultHttpProvider(new MockSerializer(null, ""), mAuthenticationProvider, new MockExecutors(), new MockLogger());
mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
mBaseClient.setHttpProvider(mProvider);
final AtomicBoolean success = new AtomicBoolean(false);
final AtomicBoolean failure = new AtomicBoolean(false);
final ICallback<InputStream> callback = new ICallback<InputStream>() {
@Override
public void success(InputStream inputStream) {
success.set(true);
}
@Override
public void failure(ClientException ex) {
failure.set(true);
}
};
final BaseStreamRequest<InputStream> request = new BaseStreamRequest<InputStream>("https://a.b.c", mBaseClient, null, InputStream.class) {
};
request.send(new byte[] { 1, 2, 3, 4 }, callback);
assertTrue(success.get());
assertFalse(failure.get());
assertEquals(1, mAuthenticationProvider.getInterceptionCount());
}
use of com.microsoft.graph.core.ClientException in project msgraph-sdk-java by microsoftgraph.
the class BaseStreamRequestTests method testSendWithCallback.
@Test
public void testSendWithCallback() {
final ITestConnectionData data = new ITestConnectionData() {
@Override
public int getRequestCode() {
return 200;
}
@Override
public String getJsonResponse() {
return "{ \"id\": \"zzz\" }";
}
@Override
public Map<String, String> getHeaders() {
final HashMap<String, String> map = new HashMap<>();
map.put("Content-Type", "application/json");
return map;
}
};
DefaultHttpProvider mProvider = new DefaultHttpProvider(new MockSerializer(null, ""), mAuthenticationProvider, new MockExecutors(), new MockLogger());
mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data)));
mBaseClient.setHttpProvider(mProvider);
final AtomicBoolean success = new AtomicBoolean(false);
final AtomicBoolean failure = new AtomicBoolean(false);
final ICallback<InputStream> callback = new ICallback<InputStream>() {
@Override
public void success(InputStream inputStream) {
success.set(true);
}
@Override
public void failure(ClientException ex) {
failure.set(true);
}
};
final BaseStreamRequest<InputStream> request = new BaseStreamRequest<InputStream>("https://a.b.c", mBaseClient, null, InputStream.class) {
};
request.send(callback);
assertTrue(success.get());
assertFalse(failure.get());
assertEquals(1, mAuthenticationProvider.getInterceptionCount());
}
Aggregations