Azure-sdk-for-java: Exception: java.lang.RuntimeException: java.io.IOException: java.net.UnknownHostException: login.microsoftonline.com

Created on 7 Feb 2018  路  7Comments  路  Source: Azure/azure-sdk-for-java

We are getting Exception: java.lang.RuntimeException: java.io.IOException: java.net.UnknownHostException: login.microsoftonline.com

Stack trace:
java.net.UnknownHostException: login.microsoftonline.com
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) ~[?:1.8.0_152]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_152]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_152]
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673) ~[?:1.8.0_152]
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173) ~[?:1.8.0_152]
at sun.net.NetworkClient.doConnect(NetworkClient.java:180) ~[?:1.8.0_152]
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463) ~[?:1.8.0_152]
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558) ~[?:1.8.0_152]
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264) ~[?:1.8.0_152]
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367) ~[?:1.8.0_152]
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) ~[?:1.8.0_152]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156) ~[?:1.8.0_152]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050) ~[?:1.8.0_152]
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) ~[?:1.8.0_152]
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334) ~[?:1.8.0_152]
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309) ~[?:1.8.0_152]
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:259) ~[?:1.8.0_152]
at com.microsoft.aad.adal4j.AdalOAuthRequest.configureHeaderAndExecuteOAuthCall(AdalOAuthRequest.java:140) ~[adal4j-1.1.2.jar:1.1.2]
at com.microsoft.aad.adal4j.AdalOAuthRequest.send(AdalOAuthRequest.java:83) ~[adal4j-1.1.2.jar:1.1.2]
at com.microsoft.aad.adal4j.AdalTokenRequest.executeOAuthRequestAndProcessResponse(AdalTokenRequest.java:80) ~[adal4j-1.1.2.jar:1.1.2]
at com.microsoft.aad.adal4j.AuthenticationContext.acquireTokenCommon(AuthenticationContext.java:818) ~[adal4j-1.1.2.jar:1.1.2]
at com.microsoft.aad.adal4j.AuthenticationContext.access$100(AuthenticationContext.java:66) ~[adal4j-1.1.2.jar:1.1.2]
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:174) ~[adal4j-1.1.2.jar:1.1.2]
at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:163) ~[adal4j-1.1.2.jar:1.1.2]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_152]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_152]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_152]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]

Investigate Mgmt customer-reported

Most helpful comment

I am also using using proxy to connect to the internet. And I am currently getting this error when using the azure calls by running an application (spring boot) locally.. The code was downloaded from the Sample GIT projects as below,

URL of the first sample Project: https://docs.microsoft.com/en-us/java/azure/spring-framework/configure-spring-boot-starter-java-app-with-azure-active-directory?view=azure-java-stable

URL of the second sample Project https://github.com/Azure-Samples/aad-java-manage-users-groups-and-roles

While running both of the above sample projects to connect with Azure, we are getting the Exception as : Caused by: java.net.UnknownHostException: login.microsoftonline.com

Later tried at home, where there is no Proxy to connect to the internet, and then am able to successfully get output for the second sample project without this "UnknownHostException" error. So at this point it seems this UnknownHostException is related to the proxy (i.e) where the system uses proxy settings to connect to the internet.

For more information of this similar exception you may also refer the URL https://github.com/Azure/azure-sdk-for-java/issues/942

All 7 comments

I am also using using proxy to connect to the internet. And I am currently getting this error when using the azure calls by running an application (spring boot) locally.. The code was downloaded from the Sample GIT projects as below,

URL of the first sample Project: https://docs.microsoft.com/en-us/java/azure/spring-framework/configure-spring-boot-starter-java-app-with-azure-active-directory?view=azure-java-stable

URL of the second sample Project https://github.com/Azure-Samples/aad-java-manage-users-groups-and-roles

While running both of the above sample projects to connect with Azure, we are getting the Exception as : Caused by: java.net.UnknownHostException: login.microsoftonline.com

Later tried at home, where there is no Proxy to connect to the internet, and then am able to successfully get output for the second sample project without this "UnknownHostException" error. So at this point it seems this UnknownHostException is related to the proxy (i.e) where the system uses proxy settings to connect to the internet.

For more information of this similar exception you may also refer the URL https://github.com/Azure/azure-sdk-for-java/issues/942

I am facing the exact same issue:

I have used basic example: https://github.com/Azure-Samples/azure-cosmos-db-cassandra-java-getting-started

I am getting unknown host, telnet is working fine the same host & port.

Please let me know, If this is resolved..?

hi @ChenTanyi could you pls have a look? I think this should be adal libraries issue, which is in runtime.

UnknownHostException is a network issue, which means the client cannot query the DNS address of login.microsoftonline.com successfully. I think it is not the libraries issue.

And after reading these two issue related, it is likely the problem when running libraries behind a proxy.

@vaibhavkulkar @anil-kapoor Can you tell me about your network status when meeting this error? If you are using a proxy and cannot request Internet directly which means your proxy is not a system proxy. You could try to add proxy in the credential:

ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
credentials.withProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888)));

Close as no response. If there is still same problem, feel free to reopen it again.

I am having the same issue, I deployed my web app in the kubernetes cluster and use Azure digital twin as storage. But for mine, it throws this exception at first and works after I refresh the page. If it is a proxy issue, why would it fixed itself?

@jinyanghuang It is not a proxy issue. UnknownHostException is a network issue, which is caused by DNS lookup error. Proxy is just a problem that could cause such error, since some of the people above said they are behind a proxy.

You could do a DNS lookup before you executing the SDK, then you could know whether it is the DNS / Network error or the SDK error. I've no idea about what your network looks like. Thus, cannot give useful advise.
One of the possible solution is you could use a proxy which can access both your web app and the public network.

(PS: if it only fails the first time, maybe it is because the DNS service of your kubernetes cluster is not up at that time.)

Was this page helpful?
0 / 5 - 0 ratings