How to code a listener when I use SubscribeToPushNotifications() to get the new mails.
Hi all. Now I want to use SubscribeToPushNotifications() to let the server push new mails to my app.
/=====================================================/
Public PushSubscription subscribeToPushNotifications(
Iterable
is there a bug/problem on the readme using-push-notifications-with-the-ews-java-api? ref. #154
+1, what is a listener url ? socket url ?
any update ?
I just succeed to set up the push request, but I don't know how to deserialize the request from the Exchange Server :
<?xml version="1.0" encoding="utf-8"?>
<soap11:Envelope xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
<soap11:Header>
<t:RequestServerVersion xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" Version="Exchange2010_SP2" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" />
</soap11:Header>
<soap11:Body>
<m:SendNotification xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<m:ResponseMessages>
<m:SendNotificationResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:Notification>
<t:SubscriptionId>JwB2aTFwcjA1bWIxMDA4LmV1cnByZDA1LnByb2Qub3V0bG9vay5jb20QAAAA+l+lLQTaA06BVIWNwne7WF/DUcp2i9IIEAAAAAvWSXbzJs5Mgx6zO1iHfjE=</t:SubscriptionId>
<t:PreviousWatermark>AQAAAMFcdQJ5b45EkzokImftRv6WKucBAAAAAAA=</t:PreviousWatermark>
<t:MoreEvents>false</t:MoreEvents>
<t:StatusEvent>
<t:Watermark>AQAAAMFcdQJ5b45EkzokImftRv5kK+cBAAAAAAE=</t:Watermark>
</t:StatusEvent>
</m:Notification>
</m:SendNotificationResponseMessage>
</m:ResponseMessages>
</m:SendNotification>
</soap11:Body>
</soap11:Envelope>
:+1: I don't understand how to get notification either.
I assume I should use something like the following code, but
-
output of http request is "OK" for both AsyncCallback and IAsyncResult
-
callback is called immediately but only once
WellKnownFolderName wkFolder = WellKnownFolderName.Inbox; FolderId folderId = new FolderId(wkFolder); List<FolderId> folder = new ArrayList<FolderId>(); folder.add(folderId); String url = ... int frequency = 1; // minutes from 1 to 1440 AsyncCallback cb = new AsyncCallbackImplementation() { @Override public Object processMe(Future<?> task) { System.out.println("In AsyncCallback : " + task.isDone()); try { HttpClientWebRequest r = (HttpClientWebRequest)task.get(); System.out.println("AsyncCallbackImplementation : " + r.getResponseText()); return task.get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (EWSHttpException e) { e.printStackTrace(); } return null; } }; IAsyncResult result = service.beginSubscribeToPushNotifications(cb, null, folder, new URI(url), frequency, null, EventType.NewMail, EventType.Created, EventType.Deleted); System.out.println("IAsyncResult : " + ((HttpClientWebRequest)result.get()).getResponseText()); Thread.sleep(100000000); PushSubscription subscription = service.endSubscribeToPushNotifications(result);
Using 2.0-SNAPSHOT
Any advance on this topic?
No, I have been working on something else as I had no answer to make it work :(
Le mardi 17 novembre 2015, Alejandro Caride [email protected] a écrit :
Any advance on this topic?
— Reply to this email directly or view it on GitHub https://github.com/OfficeDev/ews-java-api/issues/151#issuecomment-157356786 .
I also managed to configure a push notification to work, but only one event (repeated 3 times) is received. It looks like I'm not returning something the server is expected and terminate the subscription. The doc https://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx#bk_eventtypes says something about returning, on the listener side, a StatusFrequency element in the SendNotificationResponseMessage.
Any clue how to build that soap response message ?
We see the same thing (although we're not trying to do async like you are - we just use service.SubscribeToPushNotifications()). You have to send a SOAP handshake of "OK" with the HTTP 200 response. Here is a packet capture of what it should look like (based on a capture of a .NET interaction):
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:SendNotificationResult>
<m:SubscriptionStatus>
OK
</m:SubscriptionStatus>
</m:SendNotificationResult>
</soap:Body>
</soap:Envelope>
It will retry 3 times if it does not receive this handshake.
@bobdrad thanks. Have been searching hours. Its ridiculous, the spec for this listener is not mentioned anywhere