How to use Exchange Server Outlook interface in Java SpringBoot?

ShuangCoolBoy 20 Reputation points
2025-10-22T07:03:42.7433333+00:00

Hello, I previously asked a similar question, and I thought it was closed. Now, I have a new one, and we're truly unable to resolve it. Please help.

Our project background is this: We are a third-party software provider deployed on a client's server. The client requires our software platform to integrate their Outlook meeting content, enabling synchronization and binding between our software platform and Outlook meetings. Therefore, we need to integrate Outlook with our application. We've written a Java Spring Boot application to query Outlook meeting rooms. We can think of this application as Service A. For this query interface, we use the Maven dependency ews-api (version 2.0). The client's environment provides the Exchange Server address, username, and password. I've also noted the differences between Exchange Online and Exchange Server. Based on the previous question, I've verified that the client's WWW-Authenciate supports both Basic and NTLM (I can provide the curl command). My program still displays a timeout issue, and I need more information. Let me share my code with you:

/**

  • Establishes a connection with the Exchange web server
  • @return ExchangeService
  • @throws Exception

*/

public ExchangeService createService(Map<String, String> jsonConfig) throws Exception {

/**

  • @implNote: The email here is in the format email@domain

*/

String email = jsonConfig.get("email");

String password = jsonConfig.get("password");

String serverHost = jsonConfig.get("serverHost");

// Must be null

String domain = jsonConfig.get("domain");

// Establishes a connection with the Exchange web server

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

WebCredentials credentials = null;

boolean useNTLM = false;

if (StringUtils.isNotBlank(email) && email.contains("@")) {

// If the email contains an @ sign, extract the domain and use NTLM authentication.

if (StringUtils.isBlank(domain)) {

// Extract the content between the @ sign and the first dot as the domain.

int atIndex = email.indexOf('@');

int dotIndex = email.indexOf('.', atIndex + 1);

if (dotIndex > atIndex) {

domain = email.substring(atIndex + 1, dotIndex);

} else {

// If the dot is not found, extract everything after the @.

domain = email.substring(atIndex + 1);

}

}

credentials = new WebCredentials(email, password, domain);

useNTLM = true;

log.info("Using NTLM authentication - extracted domain: {}", domain);

} else {

// If the email does not contain an @, use Basic authentication.

credentials = new WebCredentials(email, password);

log.info("Using Basic authentication");

}

log.info("Parameters email:{} password:{} domain:{} serverHost:{} Authentication method:{}",

email, password, domain, serverHost, useNTLM ? "NTLM" : "Basic");

// WebCredentials credentials = new WebCredentials(email, password);

service.setCredentials(credentials);

service.setUrl(new URI("https://" + serverHost + "/ews/exchange.asmx"));

service.setTraceEnabled(true);

service.setPreAuthenticate(true);

service.getHttpHeaders().put("Connection", "close");

try {

long t0 = System.currentTimeMillis();

service.getServerTimeZones(); // Lightweight authentication: connectivity + authentication

log.info("getServerTimeZones cost={}ms", System.currentTimeMillis() - t0);

log.info("EWS authentication OK (Basic, the first packet may experience a 401 error, which is normal)");

} catch (Exception e) {

log.error("Other exceptions:", e);

}

return service;

}

and

public List<MeetingRoomDTO> listMeetingRoom(MeetingRoomInput input, Map<String, String> jsonConfig) {

List<MeetingRoomDTO> meetingRoomDTOList = new ArrayList<>();

try {

ExchangeService service = outlookApi.createService(jsonConfig);

Collection<EmailAddress> meetingRoomList = outlookApi.getMeetingRoomList(service);

meetingRoomList.forEach(room -> {

MeetingRoomDTO roomDTO = new MeetingRoomDTO()

.setRoomName(room.getName()).setRoomId(room.getAddress());

meetingRoomDTOList.add(roomDTO);

});

} catch (Exception e) {

log.error("msg:{}", e.getMessage());

throw BizException.buildException(HttpStatus.BAD_REQUEST.toString(), "OutLook failed to query the meeting room list: " + e.getMessage());

}

return meetingRoomDTOList;

}

You can see that the code is very concise. In the createService method, I've implemented a compatibility feature. If the username contains the @ special symbol, NTLM authentication is used. Otherwise, I use Basic authentication to create the ExchangeService object.

In my implementation class, I directly call the ExchangeService object's getRoomLists method (implemented in the Outlook API).

My questions are:

  1. Am I using the SDK correctly? Is there a problem with how I create the WebCredentials object? Does the ExchangeVersion enumeration class have any impact? Do different enumerations affect functionality?
  2. Having confirmed that I'm using the SDK correctly, when using Basic authentication (that is, when the username doesn't contain the @ symbol), the logs don't show any error messages, but timeout messages are still printed, as shown in the figure:
    basic

When using NTLM authentication (that is, when the username contains the @ symbol), a catchable business exception, a 401 authentication failure, occurs, as shown in the figure:
ntlm

  1. So, having confirmed that the customer's Exchange Server service supports the authentication method, how can I troubleshoot this network connection timeout issue? Does this require verifying the customer's Exchange Server environment? For example, their network environment, and whether their username and password have the appropriate permissions? I need to understand whether this is a problem with the customer's environment or our code.
  2. The customer mentioned a certificate issue. Is this related to this timeout?
  3. Is there any official documentation available for reference on Java integration with Exchange Server?

I hope we can have a pleasant conversation. Thank you very much!

Exchange | Exchange Server | Development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Steven-N 15,160 Reputation points Microsoft External Staff Moderator
    2025-10-22T10:07:17.5+00:00

    Hi ShuangCoolBoy

    Thank you for reaching out to Microsoft Q&A

    Based on your description, you currently have a Java Spring Boot application using the EWS Java API to query Outlook meeting rooms from an on‑premises Exchange Server. The client environment supports Basic and NTLM authentication, but your code experiences timeouts with Basic and 401 errors with NTLM. And now you want to find the information for your 5 questions.

    First of all, I’m regret to say that due to the highly technical and complex nature of your issue, I may not be able to provide an exact solution. As a forum moderator, my access to resources and specialized testing environments is limited. Additionally, since your setup involves a server environment, we’re unable to access its structure or specific configurations, which makes it difficult to accurately detect the root cause in certain cases. 

    However, I’ve taken the time to conduct research and draw from my personal experience to provide insights into your five questions. I’ve also attached relevant documentation to each answer. I hope these suggestions are helpful to you. 

    Regarding to your first question: Am I using the SDK correctly? Is there a problem with how I create the WebCredentials object? Does the ExchangeVersion enumeration class have any impact? Do different enumerations affect functionality? 

    From my observation, your usage of the EWS Java API SDK appears mostly correct for basic EWS operations like fetching room lists, as you're properly initializing ExchangeService, setting credentials, and pointing to the EWS endpoint (/ews/exchange.asmx). The call to getServerTimeZones() is a good lightweight test for connectivity and auth, as states in https://github.com/OfficeDev/ews-java-api

    • About ExchangeVersion: 

    Yes, it impacts functionality. Exchange2010_SP2 is an older version, if the client's Exchange Server is newer (2016, 2019, or later), features like certain room list queries might behave differently or fail. Newer enums (e.g., Exchange2016) support more APIs and better auth handling and the mismatch can lead to subtle errors or missing features. So, I recommend detecting the server's version (via service.autodiscoverUrl()) or asking the client, then set the closest matching enum. Different enums can affect XML schemas, property availability, and error handling as states in https://v4.hkg1.meaqua.org/en-us/exchange/client-developer/exchange-web-services/start-using-web-services-in-exchange

    Regarding to your second question: Why am I seeing timeouts with Basic authentication (no error messages, just timeouts) and 401 authentication failures with NTLM, even after confirming the server supports both? 

    From what I know about this behavior, Timeouts in Basic auth (no errors) suggest initial connection succeeds but negotiation stalls, often from firewalls/proxies, high latency, EWS throttling (exceeding CPU/connection/AD limits), or SSL issues like untrusted certs causing silent failures. Despite server support, check permissions for room access.  

    Additionally, NTLM's repeated 401s indicate negotiation failure, typically from wrong domain (use exact Windows, not email-based), mismatched username formats (try DOMAIN\username), server config errors (Kerberos/IIS), or outdated API lacking NTLMv2. Enable setTraceEnabled(true); test with Postman/SoapUI for response details. 

    Link references:

    https://v4.hkg1.meaqua.org/en-us/exchange/client-developer/exchange-web-services/authentication-and-ews-in-exchange

    https://v4.hkg1.meaqua.org/en-us/exchange/client-developer/exchange-web-services/ews-throttling-in-exchange

    Regarding to your third question: Having confirmed that the customer's Exchange Server service supports the authentication method, how can I troubleshoot this network connection timeout issue? Does this require verifying the customer's Exchange Server environment? 

    Yes, troubleshooting will likely require collaboration with the client to verify their environment, as timeouts often stem from network/server-side factors rather than just code. As the recommended steps: 

    1. Increase timeouts: Set service.setTimeout(30000) (30 seconds) or higher to see if it's purely latency. 
    2. Test connectivity: Use ping or telnet to the server host on port 443. Then, try a simple HTTPS GET with curl -v --ntlm -u username:password https://server/ews/exchange.asmx (for NTLM) or with --basic to mimic your code. 
    3. Log everything: Add HttpClient logging (via log4j or similar) to capture raw requests/responses. 
    4. Minimal repro: Create a standalone Java app (no Spring) with your createService method and run it on the client's network if possible. 

    Link references:

    https://github.com/OfficeDev/ews-java-api

    https://v4.hkg1.meaqua.org/en-us/exchange/client-developer/exchange-web-services/authentication-and-ews-in-exchange

    https://v4.hkg1.meaqua.org/en-us/exchange/client-developer/exchange-web-services/ews-throttling-in-exchange

    Client environment verification:  

    • Permissions: The username/password must have "Full Access" or at least "View" rights on room mailboxes. Use Exchange Admin Center (EAC) to check if the account can impersonate or access rooms via Get-RoomList in PowerShell. 
    • Network: Firewalls, proxies, or VPNs might block EWS. Ask for traceroute from your server to theirs. Ensure no MTU issues or packet loss. 
    • Server config: Confirm EWS is enabled (Get-WebServicesVirtualDirectory in PowerShell). Check IIS logs on Exchange for incoming requests/errors. Verify auth providers in IIS (NTLM/Basic enabled). 
    • Certificates: Mismatched certs can cause timeouts. 
    • Versions: Ensure Exchange CU (Cumulative Update) is current; older versions have EWS bugs.

    Link references:

    https://v4.hkg1.meaqua.org/en-us/exchange/client-developer/exchange-web-services/authentication-and-ews-in-exchange

    https://v4.hkg1.meaqua.org/en-us/exchange/client-developer/exchange-web-services/start-using-web-services-in-exchange

    Next one, about your fourth question: The customer mentioned a certificate issue. Is this related to this timeout 

    From my perspective view, the answer is Yes, this is a common cause of timeouts in Java EWS integrations with on-premises Exchange. Exchange uses HTTPS for EWS, and if the server's SSL certificate is self-signed, expired, or not trusted (e.g., issued by an internal CA not in Java's cacerts), the SSL handshake fails silently, leading to timeouts rather than explicit errors as states in https://v4.hkg1.meaqua.org/en-us/exchange/client-developer/exchange-web-services/how-to-validate-a-server-certificate-for-the-ews-managed-api

    And your last question: Is there any official documentation available for reference on Java integration with Exchange Server? 

    Unfortunately, from my research, currently Microsoft doesn't provide an official Java SDK for EWS. However, official Microsoft docs cover EWS concepts, authentication, and operations that apply to any client language, including Java. Below is all the documentation related to this issue that I was able to find. Feel free to review it to gain additional insights, I am truly hope it might help clarify certain aspects or guide you toward a solution. 

    This summary is based on my findings from the community and several relevant threads. However, it may not accurately reflect the behavior in question. To help you reach your goal more effectively, I recommend posting a thread on the Microsoft Tech Community forum or Newest Questions - Stack Overflow . There are great platforms for deeper technical discussions and connecting with individuals who have hands-on experience and expertise. They’re best positioned to provide guidance and valuable insights on this topic.    

    Best regards


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".     

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.