ews-java-api: StreamingSubscription - Error: Connection is still allocated
For the following code:
WellKnownFolderName sd = WellKnownFolderName.Inbox;
FolderId folderId = new FolderId(sd);
List<FolderId> folder = new ArrayList<FolderId>();
folder.add(folderId);
StreamingSubscription subscription = service.subscribeToStreamingNotifications(folder, EventType.NewMail);
StreamingSubscriptionConnection conn = new StreamingSubscriptionConnection(service, 30);
conn.addSubscription(subscription);
EventDelegate delegate = new EventDelegate(service);
conn.addOnNotificationEvent(delegate);
conn.addOnDisconnect(delegate);
conn.open();
EmailMessage msg = new EmailMessage(service);
msg.setSubject("Testing Streaming Notification on " + new Date());
msg.setBody(MessageBody.getMessageBodyFromText("Streaming Notification Test"));
msg.getToRecipients().add("someone@somewhere.com");
msg.send();
I get the following error:
microsoft.exchange.webservices.data.exception.ServiceRequestException: The request failed. Connection is still allocated
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:80)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:160)
at microsoft.exchange.webservices.data.core.ExchangeService.internalCreateItems(ExchangeService.java:592)
at microsoft.exchange.webservices.data.core.ExchangeService.createItem(ExchangeService.java:651)
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 test.TestEWS.main(TestEWS.java:287)
Caused by: java.lang.IllegalStateException: Connection is still allocated
at org.apache.http.util.Asserts.check(Asserts.java:34)
at org.apache.http.impl.conn.BasicHttpClientConnectionManager.getConnection(BasicHttpClientConnectionManager.java:248)
at org.apache.http.impl.conn.BasicHttpClientConnectionManager$1.get(BasicHttpClientConnectionManager.java:199)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:173)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
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:291)
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:780)
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:719)
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:68)
... 7 more
I should note that this used to work in the past.
Continuing with some tests on this, creating a separate ExchangeService object for sending the email works. However, the following code still does not work.
StreamingSubscription subscription = service.subscribeToStreamingNotifications(folder, EventType.NewMail);
StreamingSubscriptionConnection conn = new StreamingSubscriptionConnection(service, 30);
conn.addSubscription(subscription);
conn.open();
subscription.unsubscribe();
if (conn.getIsOpen())
conn.close();
The line subscription.unsubscribe(); will still result in an “Connection is still allocated” error. Also, if I comment it out, the line conn.close(); hangs.
About this issue
- Original URL
- State: open
- Created 9 years ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- Fix #276 Fixes issues with subscriptions (e.g. streaming) and now uses a PoolingHttpClientConnectionManager instead of BasicHttpClientConnectionManager. — committed to avromf/ews-java-api by deleted user 9 years ago
- Merge pull request #2 from avromf/Issue276 Fix #276 — committed to kentongray/ews-java-api by kentongray 9 years ago
- Fix for Issue #276 — committed to avromf/ews-java-api by deleted user 9 years ago
- Merge pull request #336 from avromf/Issue276 Fix for Issue #276 Streaming subscription throws connection error — committed to OfficeDev/ews-java-api by serious6 9 years ago
Issue is still there in 2018. Happy 3 year anniversary (almost)!