Currently I am working on implementing a connector for Microsoft Dynamics Nav in Java.
For that I want to create a connection with Dynamics Nav server through NTLM. Most of the blogs and documentations I found regarding this are outdated.
Connecting to NAV Web Services from Java
It will be appreciated if anyone can suggest me a method to handle Dynamics Nav authentication using org.apache.http.client.HttpClient
. (Please suggest me if there is any Java client library available for Dynamics Nav)
Furthermore, it will be appreciated if any one can suggest me a place where I can get a free Dynamics Nav testing environment to test my Dynamics Nav connector application.
Windows Challenge/Response (NTLM
) is the authentication protocol used on networks that include systems running the Windows operating system and on stand-alone systems. I was able to handle NTLM
authentication using org.apache.http.client.HttpClient
version 4.4
.
Here is the Maven dependency I have used (Methods and method names can be slightly different in other versions).
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4</version>
</dependency>
Following imports are required for the implementation. This is the basic requirement for a non-SSL connection.
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
Here is the implementation. Need to replace Username
, Password
, and Domain
with real credentials.
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
HttpClient httpClient = HttpClientBuilder.create()
.setDefaultCredentialsProvider(credentialsProvider)
.build();
credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials("Username", "Password", null, "Domain"));
Now this http client can be used to communicate with the Dynamics NAV API.
But I was unable to find a free testing environment for Microsoft Dynamics NAV within my region (Asia). But few cloud service providers are offering free testing trials for other regions.
As a Linux user I had to install Windows in a virtual environment and install Dynamics NAV on it to create a testing environment. If you are familiar with Docker you can download the Dynamics NAV Docker image from this link.