ews-java-api
ews-java-api copied to clipboard
HELP !! Restful Push Notifications Listener
Hi guys, i'm trying to make my listener work with the ews java API but i can't.. I hope you can help me !
I do the following steps:
1)Connect to the exchange web service
ExchangeService newService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
newService.setUrl("https://myurl/ews/Exchange.asmx");
ExchangeCredentials credentials = new WebCredentials("user","password");
newService.setCredentials(credentials);
- Then subscribe to the push notifications:
public PushSubscription subscribeToPushNotifications(){
URI callback = null;
PushSubscription pushSubscription = null;
try{
logger.info("Subscribing to push notifications.. Endpoint Listener URI = " + config.getNotificationListenerURI());
callback = new URI(config.getNotificationListenerURI());
pushSubscription = service.subscribeToPushNotifications(
getFoldersForSubscription(), /* The folders we want to suscribe. */
callback /* The endpoint of the listener. */,
1 /* Get a status event every 1 minutes if no new events are available. */,
null /* null to start a new subscription. */,
EventType.NewMail, EventType.Deleted); /* The subscribing event type. */
logger.info("Done! --> PushSubscription ID= " + pushSubscription.getId());
}catch(URISyntaxException e){
logger.error("EWS ==> Invalid Notification Listener URL = " + config.getNotificationListenerURI() +". Please, verify <integration-modules>");
Throwables.propagate(e);
}catch (Exception e){
logger.error("EWS ==> Error subscribing to push notifications", e);
Throwables.propagate(e);
}
return pushSubscription;
}
- Then developed my Listener as a Restful webservice (i've tested with a dummy method and it's working)
First define the servlet:
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.icbc.intranet.integration.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
After that, create the Listener class to map the urls defined in the servlet (the one i passed to the ExchangeService)
@Path("/emailnotification") public class ExchangeNotificationListener {
@Path("/incomingevent")
@POST()
@Produces(MediaType.TEXT_XML)
public Response onNotificationReceived() throws Exception {
//my code here
return Response.ok().build();
}
@GET
@Path("/{param}")
public Response getMsg(@PathParam("param") String msg) {
String output = "Dummy test : " + msg;
return Response.status(200).entity(output).build();
}
}
BUT i set the breakpoint and then send me an email but nothings happens.. What i am doing wrong / missing ??? Please help !
P.S : the dumme method getMsg works, so the rest service is working
Thanks in advance !!
possible dublicate of #151