Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWebServices for Exchange
>
Tutorial
> Streaming event notification
The following example shows you how to use streaming event notification.
import java.io.InputStream; import com.independentsoft.exchange.ConnectionStatus; import com.independentsoft.exchange.EventType; import com.independentsoft.exchange.RequestServerVersion; import com.independentsoft.exchange.ResponseClass; import com.independentsoft.exchange.Service; import com.independentsoft.exchange.ServiceException; import com.independentsoft.exchange.StandardFolder; import com.independentsoft.exchange.StreamingEventsResponse; import com.independentsoft.exchange.StreamingSubscription; import com.independentsoft.exchange.SubscribeResponse; public class Example { public static void main(String[] args) { try { Service service = new Service("https://myserver/ews/Exchange.asmx", "username", "password"); service.setRequestServerVersion(RequestServerVersion.EXCHANGE_2010_SP1); StreamingSubscription subscription = new StreamingSubscription(StandardFolder.INBOX, EventType.NEW_MAIL); SubscribeResponse response = service.subscribe(subscription); InputStream responseStream = service.getStreamingEvents(response.getSubscriptionId(), 30); while (true) { StreamingEventsResponse eventsResponse = new StreamingEventsResponse(responseStream); System.out.println("New mails:" + eventsResponse.getNotifications().size()); //exit when connection is closed or error occurs. if (eventsResponse.getConnectionStatus() == ConnectionStatus.CLOSED) { break; } else if (eventsResponse.getResponseClass() == ResponseClass.ERROR) { System.out.println(eventsResponse.getXmlMessage()); System.out.println(eventsResponse.getMessage()); break; } } } catch (ServiceException e) { System.out.println(e.getMessage()); System.out.println(e.getXmlMessage()); e.printStackTrace(); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*