none
EWS无法设置时区,求解! RRS feed

  • 问题

  • 各位,近日在做到Exchange集成,需要将OA中的日程同步到exchange的个人日程中去!目前程序已可以写到exchange中去,但是当设置了日程时间后,运行程序后,要求设置相应的时区!而无论我设置哪个时区,都不能成功,均报The time zone definition is invalid or unsupported.
    异常,求解!代码和异常如下:

     public static void main(String[] args) throws Exception {
      ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);// 创建service实例
      ExchangeCredentials credentials = new WebCredentials("test", "12345678");
      service.setCredentials(credentials);
      service.setPreAuthenticate(true);

      try {
       service.setUrl(new URI("https://mail.yuexiu.com/EWS/exchange.asmx"));
       Appointment appointment = new Appointment(service);
       appointment.setSubject("abcd");
       
       appointment.setBody(MessageBody.getMessageBodyFromText("ABCDEFGHIJKLMN"));
       SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       Date startDate = formatter.parse("2011-12-25 14:20:12");
       Date endDate = formatter.parse("2011-12-25 16:20:12");
       appointment.setStart(startDate);
       appointment.setEnd(endDate);

      
       Collection<TimeZoneDefinition> t = service.getServerTimeZones();
       TimeZoneDefinition tf = null;
       for (TimeZoneDefinition timeZoneDefinition : t) {
        if (timeZoneDefinition.getId().equalsIgnoreCase("Asia/Shanghai")) {
         tf = timeZoneDefinition;
         break;
        }
        
       }
       
       appointment.setStartTimeZone(tf);
       
      
       //必须参加的人员
       appointment.getRequiredAttendees().add("Oamail001@yuexiu.com");
       //可参加的人员
       appointment.getOptionalAttendees().add("Oamail002@yuexiu.com");
       //会议资源
       appointment.getResources().add("资源");
       appointment.setLocation("会议室地点");
       appointment.save();


      } catch (Exception e) {
       e.printStackTrace();
      }

     运行程序后,抛出时区不支持的异常,循环遍历所有的时区,均不能正常支持,都抛同样的异常,异常如下:

    microsoft.exchange.webservices.data.ServiceLocalException: The time zone definition is invalid or unsupported.
     at microsoft.exchange.webservices.data.TimeZoneDefinition.validate(Unknown Source)
     at microsoft.exchange.webservices.data.PropertyBag.validatePropertyValue(Unknown Source)
     at microsoft.exchange.webservices.data.PropertyBag.validate(Unknown Source)
     at microsoft.exchange.webservices.data.ServiceObject.validate(Unknown Source)
     at microsoft.exchange.webservices.data.Item.validate(Unknown Source)
     at microsoft.exchange.webservices.data.Appointment.validate(Unknown Source)
     at microsoft.exchange.webservices.data.CreateItemRequest.validate(Unknown Source)
     at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(Unknown Source)
     at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(Unknown Source)
     at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
     at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(Unknown Source)
     at microsoft.exchange.webservices.data.ExchangeService.createItem(Unknown Source)
     at microsoft.exchange.webservices.data.Item.internalCreate(Unknown Source)
     at microsoft.exchange.webservices.data.Appointment.save(Unknown Source)
     at com.landray.kmss.third.exchange.SynMeetingToExchange.main(SynMeetingToExchange.java:120)

    请求相关人士可以解释其中的原因,并给出相应的解决方法!

    2011年12月24日 9:04

全部回复

  • 通过调试,发现periods.size(),  transitionGroups.size() 以及 transitions.size()的值均为0,而可能正是这几个值为0,所以在运行validate()的

            if(periods.size() < 1 || transitions.size() < 1 || transitionGroups.size() < 1 || transitionGroups.size() != transitions.size())
                throw new ServiceLocalException(Strings.InvalidOrUnsupportedTimeZoneDefinition);

    语句时,才抛出如上异常的!

    谁能帮解答一下呢?可以告诉引起的原因吗?

    2011年12月26日 1:48