简体   繁体   English

ews-java-api 创建新约会

[英]ews-java-api create new appointment

I want to create a simple java program that creates a new appointment for my outlook calendar, but I don't know what went wrong.我想创建一个简单的 java 程序来为我的 outlook 日历创建一个新约会,但我不知道出了什么问题。

I also tried to send a simple email but it gives the same error.我也尝试发送一封简单的电子邮件,但它给出了同样的错误。

source code: https://github.com/OfficeDev/ews-java-api/wiki/Getting-Started-Guide源代码: https ://github.com/OfficeDev/ews-java-api/wiki/Getting-Started-Guide

public class test {
    static class RedirectionUrlCallback implements IAutodiscoverRedirectionUrl {
        public boolean autodiscoverRedirectionUrlValidationCallback(
                String redirectionUrl) {
            return redirectionUrl.toLowerCase().startsWith("https://");
        }
    }
    public static void main(String[] args){
        try {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            ExchangeCredentials credentials = new WebCredentials("email@bc.ac.id", "password");
            service.setCredentials(credentials);
            service.autodiscoverUrl("email@bc.ac.id", new RedirectionUrlCallback());
            Appointment appointment = new Appointment(service);
            appointment.setSubject("Appointment for JAVA XML TEST");
            appointment.setBody(MessageBody.getMessageBodyFromText("Test Body Msg in JAVA"));
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startDate = formatter.parse("2019-04-16 12:00:00");
            Date endDate = formatter.parse("2019-04-16 13:00:00");
            appointment.setStart(startDate);//new Date(2010-1900,5-1,20,20,00));
            appointment.setEnd(endDate); //new Date(2010-1900,5-1,20,21,00));
            appointment.save();
        }
        catch (Exception e){
            System.out.println(e);
        }
    }
}

Error code:错误代码:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/ws/http/HTTPException
    at microsoft.exchange.webservices.data.core.ExchangeService.internalCreateItems(ExchangeService.java:593)
    at microsoft.exchange.webservices.data.core.ExchangeService.createItem(ExchangeService.java:657)
    at microsoft.exchange.webservices.data.core.service.item.Item.internalCreate(Item.java:245)
    at microsoft.exchange.webservices.data.core.service.item.Item.save(Item.java:386)
    at test.main(test.java:33)
Caused by: java.lang.ClassNotFoundException: javax.xml.ws.http.HTTPException
   at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
   at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
   at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
   ... 5 more

Turn out Java 11 doesn't include jaxws-api.jar anymore and I have to download the jar onhttps://mvnrepository.com/artifact/javax.xml.ws/jaxws-api/2.2.1 then import it to my project.结果 Java 11 不再包含 jaxws-api.jar,我必须在https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api/2.2.1下载 jar,然后将其导入我的项目。

Eris Suryaputra, why are you using such out-of-date stuff? Eris Suryaputra,你为什么要使用这些过时的东西?

Plus, for you and anyone using EWS, please beware that by Oct. 13, 2020, Microsoft expects that all administrators with third-party tools that rely on Exchange Web Services for Office 365 integration will have switched to Microsoft Graph.此外,对于你和任何使用 EWS 的人,请注意,到 2020 年 10 月 13 日,Microsoft 预计所有拥有依赖于 Office 365 集成的 Exchange Web 服务的第三方工具的管理员都将切换到 Microsoft Graph。 On that same date, support for Basic Authentication in EWS will fully stop as you can see at https://www.codementor.io/@anananet/using-java-to-integrate-with-microsoft-exchange-server-15h1qq0lzg .在同一天,EWS 中对基本身份验证的支持将完全停止,如您在https://www.codementor.io/@anananet/using-java-to-integrate-with-microsoft-exchange-server-15h1qq0lzg中所见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM