WebException: Request timed out is thrown on reading Mails from Inbox using EWSClient (Java)

Aspose Email Stops Reading Mails From Inbox Post throwing request timed out WebException. This issue happens only in AWS Windows/ Linux environment .

Following code snippet to get the connection

NetworkCredential credentials = new NetworkCredential(userName, password, “”);
String mailboxUri = “[https://outlook.office365.com/ews/exchange.asmx ](https://outlook.office365.com/ews/exchange.asmx)”;
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);

@anand_bhavi_arisglobal_com,

Thank you for contacting Aspose Support.

We were unable to reproduce the issue on Linux using the latest version of Aspose.Email for Java API. It is requested that you try connecting from a different network. If possible, please share the test account credential so that we can investigate this scenario further. The screenshot of the result is also attached for your reference.
EWSClient.png (52.9 KB)

Hi ahmad,

The issue doesn’t occur in normal Windows/Linux setup. It happen’s only in AWS Windows/Linux set up that too post 4 - 5 hours . Up to 4 - 5 hour’s system will be able to connect to inbox and read the mails. Once we restart the our application then again it’s works up to 4- 5 hours.

Since connection is established through web services , is there any settings suggested for AWS environment to work seamlessly without re-start of our application.

@anand_bhavi_arisglobal_com,

Thank you for your feedback.

Our API does not provide any environment specific settings. As long as the environment is compatible, the same code should work. Additionally, the request timed out exception is a very generic which can arise due to a variety of reasons.
If possible, please provide the details given below so that we can investigate the scenario further.

  • Complete stack trace.
  • Complete environment details.
  • Complete code snippet in which you are executing the code provided in your initial message.
  • Complete stack trace: ERROR com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.error() - getConnection() - Exception while getting outlook Connection
    java.lang.IllegalStateException: class com.aspose.email.system.exceptions.WebException: The request timed out
    com.aspose.email.internal.m.z.w(Unknown Source)
    com.aspose.email.nr.a(SourceFile:213)
    com.aspose.email.nr.a(SourceFile:305)
    com.aspose.email.EWSClient.getEWSClient(SourceFile:297)
    com.aspose.email.EWSClient.getEWSClient(SourceFile:75)
    com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.getConnection(EWSEmailProcessorImpl.java:73)
    com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.saveAll(EWSEmailProcessorImpl.java:158)
    com.arisglobal.ate.agx.irt.helper.IRTEmailAdapterHelper.readEmailCase(IRTEmailAdapterHelper.java:220)
    com.arisglobal.ate.agx.irt.IRTEmailTaskCreator.poll(IRTEmailTaskCreator.java:84)
    com.arisglobal.ate.work.AbstractThreadPoolWorker.run(AbstractThreadPoolWorker.java:148)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    java.lang.Thread.run(Thread.java:748)
    at com.aspose.email.nr.a(SourceFile:241) ~[aspose-email-6.5.0.0-jdk16.jar:6.5.0.0]
    at com.aspose.email.nr.a(SourceFile:305) ~[aspose-email-6.5.0.0-jdk16.jar:6.5.0.0]
    at com.aspose.email.EWSClient.getEWSClient(SourceFile:297) ~[aspose-email-6.5.0.0-jdk16.jar:6.5.0.0]
    at com.aspose.email.EWSClient.getEWSClient(SourceFile:75) ~[aspose-email-6.5.0.0-jdk16.jar:6.5.0.0]
    at com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.getConnection(EWSEmailProcessorImpl.java:73) [ate.jar:?]
    at com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.saveAll(EWSEmailProcessorImpl.java:158) [ate.jar:?]
    at com.arisglobal.ate.agx.irt.helper.IRTEmailAdapterHelper.readEmailCase(IRTEmailAdapterHelper.java:220) [ate.jar:?]
    at com.arisglobal.ate.agx.irt.IRTEmailTaskCreator.poll(IRTEmailTaskCreator.java:84) [ate.jar:?]
    at com.arisglobal.ate.work.AbstractThreadPoolWorker.run(AbstractThreadPoolWorker.java:148) [ate.jar:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
    Caused by: com.aspose.email.system.exceptions.WebException: The request timed out
    at com.aspose.email.internal.m.z.w(Unknown Source) ~[aspose-email-6.5.0.0-jdk16.jar:6.5.0.0]
    at com.aspose.email.nr.a(SourceFile:213) ~[aspose-email-6.5.0.0-jdk16.jar:6.5.0.0]
    … 11 more

  • Complete environment details:
    OS : Centos 7 64 Bit
    Java: JDK 1.8

  • Complete code snippet in which you are executing the code provided in your initial message:
    private IEWSClient client;

/**
* This method is used to get connection
* getConnection ().
* @return Connection
*
*/
public IEWSClient getConnection() {
if (isTraceEnabled) {
logger.trace(“getConnection() for EWSEmail- start”);
}
if (isInfoEnabled) {
logger.info(“getConnection() - getting EWSEmail the connection for User : “,
userName, “”);
}
try {
NetworkCredential credentials = new NetworkCredential(userName, password, “”);
logger.info(“Host Name:” + host);
logger.info(“userName Name:” + userName);
String mailboxUri = “https://”+host+”/ews/exchange.asmx”;
logger.info(“mailboxUri:” + mailboxUri);
client = EWSClient.getEWSClient(mailboxUri, credentials);

	} catch (Exception e) {
		logger.error(
				"getConnection() - Exception while getting outlook Connection ",
				e);
	}

	if (isTraceEnabled) {
		logger.trace("getConnection() for EWSEmail - end");
	}
	return client;
}

/**
 * This method will close  Imap connection 
 * closeConnection ().
 * @return Boolean
 * 
 */

public boolean closeConnection() {
	
	if (isTraceEnabled) {
		logger.trace("closeConnection() for EWSEmail- start");
	}
	boolean retValue = true;
	try {
		client.dispose();
	}catch(Exception e) {
		retValue = false;
	}
	if (isTraceEnabled) {
		logger.trace("closeConnection() for EWSEmail - end");
	}
	return retValue;
}

/**
 * This method will get Message email Count of EWSEmail connection 
 * getMessagesCount ().
 * @return Int 
 * 
 */

public int getMessagesCount() {
	return client.listMessages(client.getMailboxInfo().getInboxUri()).size();
}

   /**
 * This method will Read the Mail from mail box and save the eml in specified folder 
 * and it helps to take Back up of eml and send mail to ack up eml
 * @param TaskDao , TaskContext
 * @return Boolean.
 * 
 */

public boolean saveAll(TaskDao irtTaskDao, TaskContext taskContext)
		throws Exception {

	if (isTraceEnabled) {
		logger.trace("saveAll(TaskDao irtTaskDao, TaskContext taskContext)- start");
	}
	boolean retValue = true;
	getConnection();
	if (client != null) {
		
	
	if (maxNumberOfMessages == 0) {
		maxNumberOfMessages = getMessagesCount();
	}
	List<Long> taskIdList = new ArrayList<Long>();
	ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri());
	for (ExchangeMessageInfo msgInfo : msgCollection) {
		try {
			MailMessage eml = client.fetchMessage(msgInfo.getUniqueUri());
			Long messageSeq = irtTaskDao
					.getNextSequence(IRT_EMAIL_DB_SEQUENCE_FOR_EMAIL_FILENAME);
			if (isInfoEnabled) {
				logger.info(
						"saveAll(TaskDao irtTaskDao, TaskContext taskContext) - Saving Mail to eml and Taking Back up for Task id and User Id: ",
						taskContext.getLinkedRecordId()+ " ," + userName ," ");
			}
			eml.save(emlPath + File.separator + messageSeq + ".eml",
					SaveOptions.getDefaultEml());
			if(partner.getIsemailBackupreq()){
				performBackup(partner, eml,
						String.valueOf(taskContext.getLinkedRecordId()),
						String.valueOf(messageSeq));
			}
			client.deleteMessage(msgInfo.getUniqueUri(),true);
			Long recordId = irtTaskDao.createTask(TaskType.IRT_EMAIL,
					TaskStatus.CREATED_IDLE,
					taskContext.getLinkedRecordId(),
					String.valueOf(messageSeq));
			taskIdList.add(recordId);
		} catch (Exception e) {
			logger.error(
					"saveAll(TaskDao irtTaskDao, TaskContext taskContext) ",
					e);
		}
	}
	if (null != taskIdList && !taskIdList.isEmpty()) {
		irtTaskDao.updateInProgressStatus(taskIdList,
				TaskStatus.CREATED_ACTIVE);
	}
	closeConnection();
	if (isTraceEnabled) {
		logger.trace("saveAll(TaskDao irtTaskDao, TaskContext taskContext)- end");
	}
	}
	return retValue;
}

Please let me know is there any manual ways to identify whether the request time out is occurring while retrieving WSLD file or authenticating credentials.

@anand_bhavi_arisglobal_com,

Thank you for your feedback.

By reviewing the stack trace that you shared, we observed that you were using an older version of Aspose.Email API whereas, it is always recommended to use the latest version of the API because it contains the latest enhancements and features.

By looking at the stack trace, it seems that the issue is related to authentication however, we cannot share additional details unless we are able to replicate the issue in our environment using the latest version of the API. Please test this scenario using Aspose.Email for Java 18.11 and in case the issue persists, please share the respective stack trace.

We have tried with aspose-email-18.9-jdk16.jar , but still issue persist. We have found two types of Timed Out Exception. Following are the stack trace.

java.lang.IllegalStateException: class com.aspose.email.system.exceptions.WebException: The request timed out
com.aspose.email.internal.o.ab.b(Unknown Source)
com.aspose.email.internal.o.ab.y(Unknown Source)
com.aspose.email.rc.a(SourceFile:260)
com.aspose.email.rc.a(SourceFile:352)
com.aspose.email.of.a(SourceFile:430)
com.aspose.email.of.d(SourceFile:352)
com.aspose.email.of.getMailboxInfo(SourceFile:297)
com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.getMessagesCount(EWSEmailProcessorImpl.java:123)
com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.saveAll(EWSEmailProcessorImpl.java:166)
com.arisglobal.ate.agx.irt.helper.IRTEmailAdapterHelper.readEmailCase(IRTEmailAdapterHelper.java:201)
com.arisglobal.ate.agx.irt.IRTEmailTaskCreator.poll(IRTEmailTaskCreator.java:84)
com.arisglobal.ate.work.AbstractThreadPoolWorker.run(AbstractThreadPoolWorker.java:148)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:748)
at com.aspose.email.rc.a(SourceFile:286) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.rc.a(SourceFile:352) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.of.a(SourceFile:430) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.of.d(SourceFile:352) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.of.getMailboxInfo(SourceFile:297) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.getMessagesCount(EWSEmailProcessorImpl.java:123) ~[ate.jar:?]
at com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.saveAll(EWSEmailProcessorImpl.java:166) ~[ate.jar:?]
at com.arisglobal.ate.agx.irt.helper.IRTEmailAdapterHelper.readEmailCase(IRTEmailAdapterHelper.java:201) [ate.jar:?]
at com.arisglobal.ate.agx.irt.IRTEmailTaskCreator.poll(IRTEmailTaskCreator.java:84) [ate.jar:?]
at com.arisglobal.ate.work.AbstractThreadPoolWorker.run(AbstractThreadPoolWorker.java:148) [ate.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
Caused by: com.aspose.email.system.exceptions.WebException: The request timed out
at com.aspose.email.internal.o.ab.b(Unknown Source) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.internal.o.ab.y(Unknown Source) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.rc.a(SourceFile:260) ~[aspose-email-18.9-jdk16.jar:18.9]
… 12 more

java.lang.IllegalStateException: class com.aspose.email.system.exceptions.WebException: The request timed out
com.aspose.email.internal.o.ab.x(Unknown Source)
com.aspose.email.rc.a(SourceFile:254)
com.aspose.email.rc.a(SourceFile:352)
com.aspose.email.EWSClient.getEWSClient(SourceFile:329)
com.aspose.email.EWSClient.getEWSClient(SourceFile:277)
com.aspose.email.EWSClient.getEWSClient(SourceFile:79)
com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.getConnection(EWSEmailProcessorImpl.java:218)
com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.saveAll(EWSEmailProcessorImpl.java:162)
com.arisglobal.ate.agx.irt.helper.IRTEmailAdapterHelper.readEmailCase(IRTEmailAdapterHelper.java:201)
com.arisglobal.ate.agx.irt.IRTEmailTaskCreator.poll(IRTEmailTaskCreator.java:84)
com.arisglobal.ate.work.AbstractThreadPoolWorker.run(AbstractThreadPoolWorker.java:148)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:748)
at com.aspose.email.rc.a(SourceFile:286) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.rc.a(SourceFile:352) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.EWSClient.getEWSClient(SourceFile:329) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.EWSClient.getEWSClient(SourceFile:277) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.EWSClient.getEWSClient(SourceFile:79) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.getConnection(EWSEmailProcessorImpl.java:218) [ate.jar:?]
at com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.saveAll(EWSEmailProcessorImpl.java:162) [ate.jar:?]
at com.arisglobal.ate.agx.irt.helper.IRTEmailAdapterHelper.readEmailCase(IRTEmailAdapterHelper.java:201) [ate.jar:?]
at com.arisglobal.ate.agx.irt.IRTEmailTaskCreator.poll(IRTEmailTaskCreator.java:84) [ate.jar:?]
at com.arisglobal.ate.work.AbstractThreadPoolWorker.run(AbstractThreadPoolWorker.java:148) [ate.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
Caused by: com.aspose.email.system.exceptions.WebException: The request timed out
at com.aspose.email.internal.o.ab.x(Unknown Source) ~[aspose-email-18.9-jdk16.jar:18.9]
at com.aspose.email.rc.a(SourceFile:254) ~[aspose-email-18.9-jdk16.jar:18.9]
… 12 more

The issue is observed only in AWS environment’s , Non AWS environment’s same code works fine.

@anand_bhavi_arisglobal_com,

Thank you for your feedback.

As requested in our previous message, please test this scenario using Aspose.Email for Java 18.11 and share the respective stack trace and exception message if the issue persists. Please note that we cannot address the issue if it is not reproducible with the latest version of the API.

We are able to reproduce the issue even with the latest Aspose Email jar. Following is the stack trace

java.lang.Thread.run(Thread.java:748)
at com.aspose.email.rk.a(SourceFile:288) ~[aspose-email-18.11-jdk16.jar:18.11]
at com.aspose.email.rk.a(SourceFile:354) ~[aspose-email-18.11-jdk16.jar:18.11]
at com.aspose.email.EWSClient.getEWSClient(SourceFile:333) ~[aspose-email-18.11-jdk16.jar:18.11]
at com.aspose.email.EWSClient.getEWSClient(SourceFile:281) ~[aspose-email-18.11-jdk16.jar:18.11]
at com.aspose.email.EWSClient.getEWSClient(SourceFile:83) ~[aspose-email-18.11-jdk16.jar:18.11]
at com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.getConnection(EWSEmailProcessorImpl.java:72) [ate.jar:?]
at com.arisglobal.ate.agx.email.EWSEmailProcessorImpl.saveAll(EWSEmailProcessorImpl.java:157) [ate.jar:?]
at com.arisglobal.ate.agx.irt.helper.IRTEmailAdapterHelper.readEmailCase(IRTEmailAdapterHelper.java:201) [ate.jar:?]
at com.arisglobal.ate.agx.irt.IRTEmailTaskCreator.poll(IRTEmailTaskCreator.java:84) [ate.jar:?]
at com.arisglobal.ate.work.AbstractThreadPoolWorker.run(AbstractThreadPoolWorker.java:148) [ate.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
Caused by: com.aspose.email.system.exceptions.WebException: The request timed out
at com.aspose.email.internal.o.ab.x(Unknown Source) ~[aspose-email-18.11-jdk16.jar:18.11]
at com.aspose.email.rk.a(SourceFile:256) ~[aspose-email-18.11-jdk16.jar:18.11]
… 12 more

@anand_bhavi_arisglobal_com,

Thank you for sharing the stack trace using the latest version of the API.

We have logged a ticket in our issue tracking system as EMAILJAVA-34469 to investigate this scenario in detail. We will update you here as soon as additional information is available.

Any update on the issue.

@anand_bhavi_arisglobal_com,

Thank you for your inquiry

The issue is expected to be resolved with the release of Aspose.Email for Java 19.1. We will update you here as soon as the fix for the issue is available.

Hi ,

Thanks for the update.

Can i get an update like what was causing the issue and what will the excepted fix to resolve the issue.

@anand_bhavi_arisglobal_com,

Thank you for your inquiry.

The issue is still under investigation. We will definitely share the details as soon as the investigation is completed.

Will the fix for EMAILJAVA-34469 be available in March release.

@anand_bhavi_arisglobal_com,

I like to share this issue is going to be resolved tentatively in Aspose.Email 19.5. We will share good news with you soon. I request for your patience until issue gets resolved.

Is the issue addressed in 19.5?

@anand_bhavi_arisglobal_com,

I have verified from our issue tracking system and like to inform that issue is tentatively going to get resolved in upcoming Aspose.Email for Java 19.6. We will share good news with you as soon as the issue will be fixed.

For work-around i am trying to cache the connection in map, since connecting to O365 is working for first 3 - 4 hour. I have query , the connection which i am caching i don’t want it’s session to dead .
For that to achieve i can set timeout parameter as -1?