Ouvinte de notificações por push Java APi + RESTful do Exchange Web Services
Estou tentando fazer meu ouvinte trabalhar com a API Java do ews, mas não posso. Espero que você possa me ajudar!
Eu fiz as seguintes etapas:
1) Conecte-se ao serviço da web do Exchange
ExchangeService newService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
newService.setUrl("https://myurl/ews/Exchange.asmx");
ExchangeCredentials credentials = new WebCredentials("user","password");
newService.setCredentials(credentials);
2) Em seguida, assine as notificações por push:
@Override
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(), callback , 5, null,
EventType.NewMail, EventType.Created, EventType.Deleted, EventType.Modified, EventType.Moved);
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;
}
3) Em seguida, desenvolvi meu Listener como um serviço da Web Restful (testei com um método fictício e ele está funcionando)
Primeiro defina o 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.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>
Depois disso, crie a classe Listener para mapear os URLs definidos no servlet (o que eu passei para o ExchangeService)
@Path("/emailnotification")
public class ExchangeNotificationListener {
private static final Log logger = LogFactory.getLog(ExchangeNotificationListener.class);
@Path("/incomingevent")
@POST()
@Produces(MediaType.TEXT_XML)
public Response onNotificationReceived() throws Exception {
logger.info("Received EWS notification !!!");
return Response.ok().build();
}
@GET
@Path("/{param}")
public Response getMsg(@PathParam("param") String msg) {
String output = "Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
}
MAS eu defino o ponto de interrupção e depois me envie um email, mas nada acontece .. O que estou fazendo de errado / faltando ??? Por favor ajude !
P.S: o método fictício getMsg () funciona, portanto o serviço restante está funcionando
Desde já, obrigado !!