SocketTimeoutException when creating subscription by MS Grpah API for Java

LENZ Test 1 Reputation point
2022-04-29T02:39:11.173+00:00

Hi there,
I try to create subscription using MS Graph SDK for Java. The login looks like ok but then got SocketTimeoutException. The code and the log are shown as below. Could you please help?
Thanks
Bing

==============================
pom.xml:
<!-- Microsoft Graph SDK for Java -->
<dependency>
<!-- Include the sdk as a dependency -->
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>5.16.0</version>
</dependency>
<dependency>
<!-- This dependency is only needed if you are using the TokenCrendentialAuthProvider -->
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.2.5</version>
</dependency>

client login setup:
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(applicationId)
.clientSecret(clientSecret)
.tenantId(tenantId)
.build();

    final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(scopes, clientSecretCredential);

    final GraphServiceClient 
    graphClient =
      GraphServiceClient
        .builder()
        .authenticationProvider(tokenCredentialAuthProvider)
        .buildClient();

code of subscription:
Subscription subscription = new Subscription();
subscription.changeType = "created";
subscription.notificationUrl = "https://localhost:8880/api/myApplication/emailnotification";

    subscription.resource = "/users/" + userId + "/mailFolders('inbox')/messages";

    try {
        subscription.expirationDateTime = OffsetDateTimeSerializer.deserialize("2023-11-20T18:23:45.9356913Z");
    } catch (ParseException e) {
        System.out.println("startSubscription exception, ParseException : " + e);
        return;
    }
    subscription.clientState = secret; //"secretClientValue";
    subscription.latestSupportedTlsVersion = "v1_2";

    graphClient.subscriptions()
        .buildRequest()
        .post(subscription);

exception log:

16:05:36.366 INFO [ForkJoinPool.commonPool-worker-3] c.a.identity.ClientSecretCredential – Azure Identity => getToken() result for scopes [.default]: SUCCESS
Exception in thread "main" com.microsoft.graph.core.ClientException: Error executing the request
at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:411)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:226)
at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:203)
at com.microsoft.graph.http.BaseRequest.send(BaseRequest.java:335)
at com.microsoft.graph.requests.SubscriptionRequest.post(SubscriptionRequest.java:122)
at com.microsoft.graph.requests.SubscriptionCollectionRequest.post(SubscriptionCollectionRequest.java:64)
at nz.govt.legislation.exchangedocumentum.model.msgraph.Graph.startSubscription(Graph.java:113)
at nz.govt.legislation.exchangedocumentum.ExchangeDocumentumApplication.appMsGraphSubscription(ExchangeDocumentumApplication.java:576)
at nz.govt.legislation.exchangedocumentum.ExchangeDocumentumApplication.main(ExchangeDocumentumApplication.java:89)
Caused by: java.net.SocketTimeoutException: timeout
at okio.SocketAsyncTimeout.newTimeoutException(JvmOkio.kt:143)
at okio.AsyncTimeout.access$newTimeoutException(AsyncTimeout.kt:162)
at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:335)
at okio.RealBufferedSource.indexOf(RealBufferedSource.kt:427)
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:320)
at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:178)
at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:106)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:79)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at com.microsoft.graph.httpcore.RedirectHandler.intercept(RedirectHandler.java:137)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at com.microsoft.graph.httpcore.RetryHandler.intercept(RetryHandler.java:177)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at com.microsoft.graph.httpcore.AuthenticationHandler.intercept(AuthenticationHandler.java:59)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at com.microsoft.graph.httpcore.TelemetryHandler.intercept(TelemetryHandler.java:69)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:408)
... 8 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.base/java.net.SocketInputStream.socketRead0(Native Method)
at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:476)
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:470)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1354)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:963)
at okio.InputStreamSource.read(JvmOkio.kt:90)
at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:129)
... 34 more

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,260 questions
{count} votes