getEWSClient using access token is hanging

Hi, passing on an issue from one of our developers.

We’re sing the latest version of Aspose E-mail for Java and have code that generates an access token from Microsoft successfully. However, when we leverage it to try and access EWS using getEWSClient, it seems to hang with no response or errors.

See below snippet my colleague provided:

String accessToken = AccessTokenProvider.getAccessToken(clientId, clientSecret, tenantId); // this works
String ewsUrl = "https://outlook.office365.com/EWS/Exchange.asmx";
IEWSClient ewsClient = EWSClient.getEWSClient(ewsUrl, new OAuthNetworkCredential(accessToken), null);  // hanging here

Please let us know if more information is needed or if anyone has any insight on how we can address, thanks!

Hello @reqosupport ,

Please try the following steps:

  • Ensure that there are no network or proxy issues blocking the connection to EWS.
  • Confirm that the access token is valid and has the necessary permissions to access EWS.
  • Enable activity logging to capture more information about what might be causing the hang.

Then share your feedback with us.
Thank you.

Margarita:

Is there a version of that link for Java? The link for activity logging points to .NET resources.

Sorry, To enable logging in Aspose.Email for Java please add the following:

imapClient.setLogFileName("log-path");
imapClient.setUseDateInLogFileName(true);

Thank you.

@reqosupport ,

You need to collect logs during client initialization:

//enable debug logging for the Java Secure Socket Extension
System.setProperty("javax.net.debug","all");
//enable EWSClient logging
EWSClient.setCommonLogFileName("common.log");

putting logging right before EWSClient.getEWSClient line doesn’t produce any logs - it’s just hanging. After a long while, it times out with the following stacktrace:

java.lang.RuntimeException: class com.aspose.email.system.exceptions.WebException: The request timed out
com.aspose.email.internal.o.zab.x(Unknown Source)
com.aspose.email.zajb.a(SourceFile:98)
com.aspose.email.ztc.a(SourceFile:34)
com.aspose.email.zh.a(SourceFile:294)
com.aspose.email.zh.a(SourceFile:441)
com.aspose.email.EWSClient.a(SourceFile:477)
com.aspose.email.EWSClient.getEWSClient(SourceFile:423)
com.aspose.email.EWSClient.getEWSClient(SourceFile:408)
com.aspose.email.EWSClient.getEWSClient(SourceFile:160)
com.reqo.ironhold.reader.ews.EWSTest.test(EWSTest.java:26)
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
java.base/java.lang.reflect.Method.invoke(Method.java:578)
org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:728)
org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:218)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:214)
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:139)
org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:202)
org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService.invokeAll(ForkJoinPoolHierarchicalTestExecutorService.java:146)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:202)
org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService.invokeAll(ForkJoinPoolHierarchicalTestExecutorService.java:146)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:202)
java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
java.base/java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:387)
java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java)
java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

at com.aspose.email.zh.a(SourceFile:315)
at com.aspose.email.zh.a(SourceFile:441)
at com.aspose.email.EWSClient.a(SourceFile:477)
at com.aspose.email.EWSClient.getEWSClient(SourceFile:423)
at com.aspose.email.EWSClient.getEWSClient(SourceFile:408)
at com.aspose.email.EWSClient.getEWSClient(SourceFile:160)
at com.reqo.ironhold.reader.ews.EWSTest.test(EWSTest.java:26)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
at java.base/java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:387)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

Caused by: class com.aspose.email.system.exceptions.WebException: The request timed out
com.aspose.email.internal.o.zab.x(Unknown Source)
com.aspose.email.zajb.a(SourceFile:98)
com.aspose.email.ztc.a(SourceFile:34)
com.aspose.email.zh.a(SourceFile:294)
com.aspose.email.zh.a(SourceFile:441)
com.aspose.email.EWSClient.a(SourceFile:477)
com.aspose.email.EWSClient.getEWSClient(SourceFile:423)
com.aspose.email.EWSClient.getEWSClient(SourceFile:408)
com.aspose.email.EWSClient.getEWSClient(SourceFile:160)
com.reqo.ironhold.reader.ews.EWSTest.test(EWSTest.java:26)
java.base/java.lang.reflect.Method.invoke(Method.java:578)
java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
java.base/java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:387)
java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java)
java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
at com.aspose.email.internal.o.zab.x(Unknown Source)
at com.aspose.email.zajb.a(SourceFile:98)
at com.aspose.email.ztc.a(SourceFile:34)
at com.aspose.email.zh.a(SourceFile:294)
… 14 more

Hello @dbarshai,

Try using the SAAJ API for EWSClient. This should fix the error.

EWSClient.useSAAJAPI(true);
IEWSClient ewsClient = EWSClient.getEWSClient(ewsUrl