ews-java-api
ews-java-api copied to clipboard
The request failed. The request failed. Connection reset
Dear Team, Below is my code :
public static void main(String[] args) {
String smtpAddress = "[email protected]";
String toAddress = "[email protected]";
String ewsWSURL = "https://mail.abc.com/EWS/Exchange.asmx";
// https://mail.abc.com/ews/Services.wsdl
String userName = "000000";
String password = "xxxxxx";
String domain = "abc";
try {
System.out.println("1. setting EWS");
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials(userName, password); //, domain);
service.setCredentials(credentials);
service.setUrl(new URI(ewsWSURL));
service.setTraceEnabled(Boolean.TRUE);
System.out.println("2. setting message");
EmailMessage emailMessage = new EmailMessage(service);
emailMessage.setFrom(new EmailAddress(smtpAddress));
emailMessage.setSubject("Hello world!");
emailMessage.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
emailMessage.getToRecipients().add(toAddress);
System.out.println("3. sending mail...");
emailMessage.send();
System.out.println("message sent successfully!");
} catch (Exception exception) {
System.err.println("ERROR :: " + exception.getMessage());
exception.printStackTrace();
}
}
I have tested the web-service url via browser and could authenticate and I am able to view the services.wsdl, But my code has been given the below error:
ERROR :: The request failed. The request failed. Connection reset
microsoft.exchange.webservices.data.exception.ServiceRequestException: The request failed. The request failed. Connection reset
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:76)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158)
at microsoft.exchange.webservices.data.core.ExchangeService.internalCreateItems(ExchangeService.java:593)
at microsoft.exchange.webservices.data.core.ExchangeService.createItem(ExchangeService.java:652)
at microsoft.exchange.webservices.data.core.service.item.Item.internalCreate(Item.java:247)
at microsoft.exchange.webservices.data.core.service.item.EmailMessage.internalSend(EmailMessage.java:147)
at microsoft.exchange.webservices.data.core.service.item.EmailMessage.send(EmailMessage.java:258)
at com.ms.email.main.TestEmail.main(TestEmail.java:48)
Caused by: microsoft.exchange.webservices.data.exception.ServiceRequestException: The request failed. Connection reset
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:782)
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:711)
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:64)
... 7 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:911)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at microsoft.exchange.webservices.data.core.request.HttpClientWebRequest.executeRequest(HttpClientWebRequest.java:296)
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:773)
Appreciate your help. Please correct me.
Thanks, Aravind
Dear Team, FYI. This program is intended to send a mail from MS exchange server to some recipient such as gmail. Regards, Aravind
Dear Team, Below are the set of jar files that I have used for this program: commons-codec-1.9.jar commons-logging-1.2.jar ews-java-api-2.0-SNAPSHOT-javadoc.jar ews-java-api-2.0-SNAPSHOT-sources.jar ews-java-api-2.0-SNAPSHOT.jar httpclient-4.4.1.jar httpcore-4.4.1.jar
Regards, Aravind
should be a server-side problem with resolving the request. Maybe step into the trace to see the underlying request.
Dear Team, Thanks for the response, I have followed exactly the way the readme text has provided., Please observe my approach on high level:
- I have given hit the url in normal browser https://mail.abc.com/EWS/Exchange.asmx
- I have provided the valid credentials., there by I am able to see https://mail.abc.com/EWS/Service.wsdl valid page
Hence I am suspecting if my code(that has posted above in this thread) need to be revised., Please suggest. OR If there is any samples provided on this API which I can connect to MS Exchange server and able to send mail to other recipients? Please suggest.
It's likely that Java is failing to negotiate the SSL connection parameters and version. Java has disabled support for less secure SSL versions, but all you get from EWS api is a connection reset. If you add this to your code
System.setProperty("javax.net.debug", "ssl");
then Java will dump a very verbose log of the SSL connection negotiation process. I was able to fix a similar issue in a test environment by doing the following:
- Install all patches and updates on the exchange server
- Use the latest version of Java 8 to run your program.
@dokala Hello, Were you able to find a resolution to this issue?
I'm having a similar problem. I'm trying to get all email items from a list of subfolders. Everything is working fine, as long as the current subfolder does not contain more than ~ 500 mail items. The first subfolder which does contain more than ~ 500 mail items throws the following exception:
Exception in thread "main" microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The request failed. Connection reset
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158)
at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:985)
at microsoft.exchange.webservices.data.core.service.folder.Folder.internalFindItems(Folder.java:421)
at microsoft.exchange.webservices.data.core.service.folder.Folder.findItems(Folder.java:473)
at ewstest.Handler.getItems(Handler.java:93)
at ewstest.ExchangeTestClass.main(ExchangeTestClass.java:37)
Caused by: microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Connection reset
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.readResponse(ServiceRequestBase.java:412)
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:63)
... 6 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:266)
at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:227)
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:186)
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:215)
at org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:316)
at org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:128)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:174)
at java.util.zip.InflaterInputStream.close(Unknown Source)
at java.util.zip.GZIPInputStream.close(Unknown Source)
at org.apache.http.client.entity.LazyDecompressingInputStream.close(LazyDecompressingInputStream.java:97)
at java.io.BufferedInputStream.close(Unknown Source)
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.readResponse(ServiceRequestBase.java:397)
... 7 more
Anything I can do about this? I suppose this is a server-side problem, i.e. Exchange terminates the conncetion after sending a fixed amount of items?
@hoalex - did you find a solution or workaround for this? Thanks