我是一名有用的助手,可以为您翻译文本。
我正在尝试让我的监听器与EWS Java API配合使用,但是我无法做到。希望您能帮助我!
我已经完成以下步骤:
1)连接到Exchange Web服务
我正在尝试让我的监听器与EWS Java API配合使用,但是我无法做到。希望您能帮助我!
我已经完成以下步骤:
1)连接到Exchange Web服务
ExchangeService newService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
newService.setUrl("https://myurl/ews/Exchange.asmx");
ExchangeCredentials credentials = new WebCredentials("user","password");
newService.setCredentials(credentials);
2) 然后订阅推送通知:
@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) 然后将我的Listener开发为Restful webservice(我已经测试过一个虚拟方法,它可以正常工作)
首先定义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>
接下来,创建Listener类以映射在servlet中定义的URL(我传递给ExchangeService的URL)
@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();
}
}
但我设置了断点,然后发送电子邮件,但什么也没有发生... 我做错了什么/漏掉了什么吗?请帮帮我!
附:虚拟方法getMsg()有效,因此其余的服务正在运行。
提前感谢!