none
[E2010] [EWS Java API 1.1][JAVA] - Unparsable Date Exception coming when getting a recurring appointment. RRS feed

  • Question

  • Hi,

    I created an recurring appointment using outlook. Then when I try to get all the appointments from the user, I am getting the following exception.

    Exception in thread "main" microsoft.exchange.webservices.data.ServiceRequestException: The request failed. Unparseable date: "2012-01-01+05:30"
    	at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:51)
    	at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:140)
    	at microsoft.exchange.webservices.data.ExchangeService.internalBindToItems(ExchangeService.java:1390)
    	at microsoft.exchange.webservices.data.ExchangeService.bindToItem(ExchangeService.java:1433)
    	at microsoft.exchange.webservices.data.ExchangeService.bindToItem(ExchangeService.java:1457)
    	at microsoft.exchange.webservices.data.Appointment.bind(Appointment.java:70)
    	at microsoft.exchange.webservices.data.Appointment.bind(Appointment.java:88)
    	at DeleteAllAppointments.main(DeleteAllAppointments.java:26)
    Caused by: java.text.ParseException: Unparseable date: "2012-01-01+05:30"
    	at java.text.DateFormat.parse(Unknown Source)
    	at microsoft.exchange.webservices.data.ExchangeServiceBase.convertStartDateToUnspecifiedDateTime(ExchangeServiceBase.java:550)
    	at microsoft.exchange.webservices.data.EwsServiceXmlReader.convertStringToUnspecifiedDate(EwsServiceXmlReader.java:63)
    	at microsoft.exchange.webservices.data.EwsServiceXmlReader.readElementValueAsUnspecifiedDate(EwsServiceXmlReader.java:84)
    	at microsoft.exchange.webservices.data.RecurrenceRange.tryReadElementFromXml(RecurrenceRange.java:120)
    	at microsoft.exchange.webservices.data.ComplexProperty.loadFromXml(ComplexProperty.java:182)
    	at microsoft.exchange.webservices.data.ComplexProperty.loadFromXml(ComplexProperty.java:211)
    	at microsoft.exchange.webservices.data.RecurrencePropertyDefinition.loadPropertyValueFromXml(RecurrencePropertyDefinition.java:126)
    	at microsoft.exchange.webservices.data.PropertyBag.loadFromXml(PropertyBag.java:487)
    	at microsoft.exchange.webservices.data.ServiceObject.loadFromXml(ServiceObject.java:268)
    	at microsoft.exchange.webservices.data.EwsServiceXmlReader.readServiceObjectsCollectionFromXml(EwsServiceXmlReader.java:212)
    	at microsoft.exchange.webservices.data.GetItemResponse.readElementsFromXml(GetItemResponse.java:56)
    	at microsoft.exchange.webservices.data.ServiceResponse.loadFromXml(ServiceResponse.java:102)
    	at microsoft.exchange.webservices.data.MultiResponseServiceRequest.parseResponse(MultiResponseServiceRequest.java:52)
    	at microsoft.exchange.webservices.data.ServiceRequestBase.readResponse(ServiceRequestBase.java:459)
    	at microsoft.exchange.webservices.data.SimpleServiceRequestBase.readResponse(SimpleServiceRequestBase.java:110)
    	at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:38)
    	... 7 more
    


    The code I am using to get all the appointments is

            ExchangeService service = new ExchangeService();
            service.setUrl( new URI( "http://10.192.37.30/ews/Exchange.asmx" ) );
            service.setCredentials( new WebCredentials( "delegate", "P@$$w0rd" ) );
    
            ItemView itemView = new ItemView( 100 );
            FindItemsResults < Item > results = service.findItems( WellKnownFolderName.Calendar, itemView );
            Iterator < Item > iterator = results.iterator();
            ItemId id = new ItemId( "TheId" );
            while ( iterator.hasNext() )
            {
                Appointment appointment = ( Appointment ) iterator.next();
                Appointment appt = Appointment.bind( service, appointment.getId() );
                System.out.println( appt.getId() );
            }


    I think the error is occuring wjen the WebService reponse is parsed. I am attaching the response trace also, in case if some one needs it.

    <?xml version="1.0" encoding="utf-8"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    	<s:Header>
    		<h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="218" MinorBuildNumber="14" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
    	</s:Header>
    	<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    		<m:GetItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
    			<m:ResponseMessages>
    				<m:GetItemResponseMessage ResponseClass="Success">
    					<m:ResponseCode>NoError</m:ResponseCode>
    					<m:Items>
    						<t:CalendarItem>
    							<t:ItemId Id="AAMkADJlMmZhNzMzLTkzYWMtNGYwMS1hOWMzLWZhMmZiYWE3ZDRmOABGAAAAAADcwakJTw9uSo+4epKv6aToBwA44aEYNM18Q60vRXyPtXwGAAAAEbwGAAAyu1u1zJmyQKMNK8GCu7GsAAAAAACuAAA=" ChangeKey="DwAAABYAAAAyu1u1zJmyQKMNK8GCu7GsAAAAAJvL"/>
    							<t:ParentFolderId Id="AAMkADJlMmZhNzMzLTkzYWMtNGYwMS1hOWMzLWZhMmZiYWE3ZDRmOAAuAAAAAADcwakJTw9uSo+4epKv6aToAQA44aEYNM18Q60vRXyPtXwGAAAAEbwGAAA=" ChangeKey="AQAAAA=="/>
    							<t:ItemClass>IPM.Appointment</t:ItemClass>
    							<t:Subject/>
    							<t:Sensitivity>Normal</t:Sensitivity>
    							<t:Body BodyType="HTML">&lt;html&gt;&#xD;
    &lt;head&gt;&#xD;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;&#xD;
    &lt;meta name="Generator" content="Microsoft Exchange Server"&gt;&#xD;
    &lt;!-- converted from rtf --&gt;&#xD;
    &lt;style&gt;&lt;!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --&gt;&lt;/style&gt;&#xD;
    &lt;/head&gt;&#xD;
    &lt;body&gt;&#xD;
    &lt;font face="Times New Roman" size="3"&gt;&lt;span style="font-size:12pt;"&gt;&lt;a name="BM_BEGIN"&gt;&lt;/a&gt;&#xD;
    &lt;div&gt;&lt;br&gt;&#xD;
    &#xD;
    &lt;/div&gt;&#xD;
    &lt;/span&gt;&lt;/font&gt;&#xD;
    &lt;/body&gt;&#xD;
    &lt;/html&gt;&#xD;
    							</t:Body>
    							<t:DateTimeReceived>2012-01-03T05:33:27Z</t:DateTimeReceived>
    							<t:Size>2495</t:Size>
    							<t:Importance>Normal</t:Importance>
    							<t:IsSubmitted>false</t:IsSubmitted>
    							<t:IsDraft>false</t:IsDraft>
    							<t:IsFromMe>false</t:IsFromMe>
    							<t:IsResend>false</t:IsResend>
    							<t:IsUnmodified>false</t:IsUnmodified>
    							<t:DateTimeSent>2012-01-03T05:33:27Z</t:DateTimeSent>
    							<t:DateTimeCreated>2012-01-03T05:33:27Z</t:DateTimeCreated>
    							<t:ResponseObjects>
    								<t:ForwardItem/>
    							</t:ResponseObjects>
    							<t:ReminderDueBy>2012-01-08T06:00:00Z</t:ReminderDueBy>
    							<t:ReminderIsSet>true</t:ReminderIsSet>
    							<t:ReminderMinutesBeforeStart>15</t:ReminderMinutesBeforeStart>
    							<t:DisplayCc/>
    							<t:DisplayTo/>
    							<t:HasAttachments>false</t:HasAttachments>
    							<t:Culture>en-US</t:Culture>
    							<t:EffectiveRights>
    								<t:CreateAssociated>false</t:CreateAssociated>
    								<t:CreateContents>false</t:CreateContents>
    								<t:CreateHierarchy>false</t:CreateHierarchy>
    								<t:Delete>true</t:Delete>
    								<t:Modify>true</t:Modify>
    								<t:Read>true</t:Read>
    								<t:ViewPrivateItems>true</t:ViewPrivateItems>
    							</t:EffectiveRights>
    							<t:LastModifiedName>delegate</t:LastModifiedName>
    							<t:LastModifiedTime>2012-01-03T05:33:27Z</t:LastModifiedTime>
    							<t:IsAssociated>false</t:IsAssociated>
    							<t:WebClientReadFormQueryString>?ae=Item&amp;t=IPM.Appointment&amp;id=RgAAAADcwakJTw9uSo%2b4epKv6aToBwA44aEYNM18Q60vRXyPtXwGAAAAEbwGAAAyu1u1zJmyQKMNK8GCu7GsAAAAAACuAAAP&amp;exvsurl=1</t:WebClientReadFormQueryString>
    							<t:WebClientEditFormQueryString>?ae=Item&amp;a=Open&amp;t=IPM.Appointment&amp;id=RgAAAADcwakJTw9uSo%2b4epKv6aToBwA44aEYNM18Q60vRXyPtXwGAAAAEbwGAAAyu1u1zJmyQKMNK8GCu7GsAAAAAACuAAAP&amp;exvsurl=1</t:WebClientEditFormQueryString>
    							<t:ConversationId Id="AAQkADJlMmZhNzMzLTkzYWMtNGYwMS1hOWMzLWZhMmZiYWE3ZDRmOAAQANGP/mcg7U/Eiw6w4Wp/VAQ="/>
    							<t:UID>040000008200E00074C5B7101A82E0080000000065950138D9C9CC01000000000000000010000000AFE6BAAB5133E04A85DD5C3E9CE5F753</t:UID>
    							<t:DateTimeStamp>2012-01-03T05:33:27Z</t:DateTimeStamp>
    							<t:Start>2012-01-01T06:00:00Z</t:Start>
    							<t:End>2012-01-01T07:00:00Z</t:End>
    							<t:IsAllDayEvent>false</t:IsAllDayEvent>
    							<t:LegacyFreeBusyStatus>Busy</t:LegacyFreeBusyStatus>
    							<t:Location/>
    							<t:IsMeeting>false</t:IsMeeting>
    							<t:IsCancelled>false</t:IsCancelled>
    							<t:IsRecurring>false</t:IsRecurring>
    							<t:MeetingRequestWasSent>false</t:MeetingRequestWasSent>
    							<t:IsResponseRequested>true</t:IsResponseRequested>
    							<t:CalendarItemType>RecurringMaster</t:CalendarItemType>
    							<t:MyResponseType>Organizer</t:MyResponseType>
    							<t:Organizer>
    								<t:Mailbox>
    									<t:Name>delegate</t:Name>
    									<t:EmailAddress>delegate@cfadobe.com</t:EmailAddress>
    									<t:RoutingType>SMTP</t:RoutingType>
    									<t:MailboxType>Mailbox</t:MailboxType>
    								</t:Mailbox>
    							</t:Organizer>
    							<t:Duration>PT1H</t:Duration>
    							<t:TimeZone>(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi</t:TimeZone>
    							<t:AppointmentSequenceNumber>0</t:AppointmentSequenceNumber>
    							<t:AppointmentState>0</t:AppointmentState>
    							<t:Recurrence>
    								<t:WeeklyRecurrence>
    									<t:Interval>1</t:Interval>
    									<t:DaysOfWeek>Sunday</t:DaysOfWeek>
    									<t:FirstDayOfWeek>Sunday</t:FirstDayOfWeek>
    								</t:WeeklyRecurrence>
    								<t:NoEndRecurrence>
    									<t:StartDate>2012-01-01+05:30</t:StartDate>
    								</t:NoEndRecurrence>
    							</t:Recurrence>
    							<t:FirstOccurrence>
    								<t:ItemId Id="AAMkADJlMmZhNzMzLTkzYWMtNGYwMS1hOWMzLWZhMmZiYWE3ZDRmOAFRAAgIzpYvcHKAAEYAAAAA3MGpCU8PbkqPuHqSr+mk6AcAOOGhGDTNfEOtL0V8j7V8BgAAABG8BgAAMrtbtcyZskCjDSvBgruxrAAAAAAArgAAEA==" ChangeKey="DwAAABYAAAAyu1u1zJmyQKMNK8GCu7GsAAAAAJvL"/>
    								<t:Start>2012-01-01T06:00:00Z</t:Start>
    								<t:End>2012-01-01T07:00:00Z</t:End>
    								<t:OriginalStart>2012-01-01T06:00:00Z</t:OriginalStart>
    							</t:FirstOccurrence>
    						</t:CalendarItem>
    					</m:Items>
    				</m:GetItemResponseMessage>
    			</m:ResponseMessages>
    		</m:GetItemResponse>
    	</s:Body>
    </s:Envelope>

    If anyone came across this particular issue and solved it please help me too. 

    Thanks,

    Paul

     

     

    Tuesday, January 3, 2012 5:50 AM

All replies

  • This error does not happen if the meeting is not a recurring one.
    Tuesday, January 3, 2012 5:51 AM
  • I'm having the same issue, have you found any solutions?  It looks like the "StartDate" value for the Recurrence>NoEndRecurrence xml node is being returned as an invalid date (2012-01-10-05:00).  It is returning just the date value but appends the TZ offset (-05:00) value to the end with no time value.  I would think either removing the -5:00 time zone information completely or adding 0 based time "2012-01-10T00:00:00-05:00" would correct this but this has to do with how Exchange is returning the data, not how the EWS API is parsing the date I believe.

    From my EWS trace: 

    <t:Recurrence>
    <t:WeeklyRecurrence>
    <t:Interval>1</t:Interval>
    <t:DaysOfWeek>Monday Tuesday Wednesday Thursday Friday</t:DaysOfWeek>
    <t:FirstDayOfWeek>Sunday</t:FirstDayOfWeek>
    </t:WeeklyRecurrence>
    <t:NoEndRecurrence>
    <t:StartDate>2012-01-10-05:00</t:StartDate>
    </t:NoEndRecurrence>
    </t:Recurrence>

     

    Thanks,

    - Shaun

    Wednesday, January 11, 2012 4:57 PM
  • Hi Shaun,

    For me the issue was coming in the line,

    Appointment appt = Appointment.bind( service, appointment.getId() );

    When we do this, it actually gets all the properties of the appointment. The issue comes when the response returned contains the "Reccurrence" element. If you don't need this element, you can define a Cutom property set and use that custom propertySet for binding.

    PropertySet propSet = new PropertySet( BasePropertySet.IdOnly, AppointmentSchema.Organizer,
                    AppointmentSchema.Body, AppointmentSchema.RequiredAttendees, AppointmentSchema.OptionalAttendees,
                    AppointmentSchema.Subject, AppointmentSchema.Location, AppointmentSchema.Resources,
                    AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.DateTimeReceived );
    
    Appointment fullAppt = Appointment.bind( service, appointment.getId(), propSet );

    You can specify all the properties you need in the propSet. But then again, if you need "Reccurence", this will not work.

     

    Hope this helps.

     

     

     

    Tuesday, January 17, 2012 11:15 AM
  • Thanks Paul,

    Unfortunately I do need the Recurrence information.  The problem was how the ExchangeServiceBase.java class was handling the StartDate value within <NoEndRecurrence> field.  What I ended up doing was actually fixing this issue within the .java file itself and recompiling the API back into a JAR so that is now working. 

    The issue was that the date being sent by Exchange was formatted like "2012-01-01 -05:00" however the DateFormat explicitly defined in the code is expecting a date and then a trailing 'Z' string indicating UTC.  So what I did is strip the date of anything after the date and appended a 'Z' to the end to make it happy and it is all working correctly now.  I've included the function I updated below indicating the line I added and of course updated the variable name that it parses.

     

        protected Date convertStartDateToUnspecifiedDateTime(String value) throws ParseException {
            if (value == null || value.isEmpty()) {

                return null;

            } else {
    ===>     String value2 = value.substring(0, 10) + 'Z';
             DateFormat df = new SimpleDateFormat("yyyy-MM-dd'Z'");
    return df.parse(value2);
            }
        }

     

    - Shaun

    Wednesday, January 18, 2012 9:14 PM