mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05:00
Ews: improve invalid item in calendar error handling
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1520 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
7180507a2b
commit
18584e259d
@ -912,10 +912,19 @@ public abstract class EWSMethod extends PostMethod {
|
||||
protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) {
|
||||
Header contentTypeHeader = getResponseHeader("Content-Type");
|
||||
if (contentTypeHeader != null && "text/xml; charset=utf-8".equals(contentTypeHeader.getValue())) {
|
||||
try {
|
||||
processResponseStream(getResponseBodyAsStream());
|
||||
} catch (IOException e) {
|
||||
logger.error("Error while parsing soap response: " + e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void processResponseStream(InputStream inputStream) {
|
||||
responseItems = new ArrayList<Item>();
|
||||
XMLStreamReader reader;
|
||||
try {
|
||||
reader = XMLStreamUtil.createXMLStreamReader(getResponseBodyAsStream());
|
||||
reader = XMLStreamUtil.createXMLStreamReader(inputStream);
|
||||
while (reader.hasNext()) {
|
||||
reader.next();
|
||||
handleErrors(reader);
|
||||
@ -933,8 +942,6 @@ public abstract class EWSMethod extends PostMethod {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("Error while parsing soap response: " + e, e);
|
||||
} catch (XMLStreamException e) {
|
||||
logger.error("Error while parsing soap response: " + e, e);
|
||||
}
|
||||
@ -942,7 +949,6 @@ public abstract class EWSMethod extends PostMethod {
|
||||
logger.debug(errorDetail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"NoopMethodInAbstractClass"})
|
||||
protected void handleCustom(XMLStreamReader reader) throws XMLStreamException {
|
||||
|
@ -79,7 +79,6 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
super(url, userName, password);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check endpoint url.
|
||||
*
|
||||
@ -109,6 +108,9 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
@Override
|
||||
protected void buildSessionInfo(HttpMethod method) throws DavMailException {
|
||||
// no need to check logon method body
|
||||
method.releaseConnection();
|
||||
|
||||
// also need to retrieve email and alias
|
||||
getEmailAndAliasFromOptions();
|
||||
if (email == null || alias == null) {
|
||||
@ -1038,10 +1040,13 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
protected class Event extends ExchangeSession.Event {
|
||||
// item id
|
||||
ItemId itemId;
|
||||
String type;
|
||||
|
||||
protected Event(EWSMethod.Item response) {
|
||||
itemId = new ItemId(response);
|
||||
|
||||
type = response.type;
|
||||
|
||||
permanentUrl = response.get(Field.get("permanenturl").getResponseName());
|
||||
etag = response.get(Field.get("etag").getResponseName());
|
||||
displayName = response.get(Field.get("displayname").getResponseName());
|
||||
@ -1191,12 +1196,14 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
}
|
||||
try {
|
||||
GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, itemId, true);
|
||||
if (!"Message".equals(type)) {
|
||||
getItemMethod.addAdditionalProperty(Field.get("reminderset"));
|
||||
getItemMethod.addAdditionalProperty(Field.get("calendaruid"));
|
||||
getItemMethod.addAdditionalProperty(Field.get("requiredattendees"));
|
||||
getItemMethod.addAdditionalProperty(Field.get("optionalattendees"));
|
||||
getItemMethod.addAdditionalProperty(Field.get("xmozlastack"));
|
||||
getItemMethod.addAdditionalProperty(Field.get("xmozsnoozetime"));
|
||||
}
|
||||
|
||||
executeMethod(getItemMethod);
|
||||
content = getItemMethod.getMimeContent();
|
||||
@ -1259,7 +1266,19 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
condition,
|
||||
FolderQueryTraversal.SHALLOW, 0);
|
||||
for (EWSMethod.Item response : responses) {
|
||||
events.add(new Event(response));
|
||||
Event event = new Event(response);
|
||||
if ("Message".equals(event.type)) {
|
||||
// need to check body
|
||||
try {
|
||||
event.getEventContent();
|
||||
events.add(event);
|
||||
} catch (HttpException e) {
|
||||
LOGGER.warn("Ignore invalid event "+event.getHref());
|
||||
}
|
||||
} else {
|
||||
events.add(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return events;
|
||||
@ -1319,7 +1338,9 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
}
|
||||
return new Contact(item);
|
||||
} else if ("CalendarItem".equals(itemType)
|
||||
|| "MeetingRequest".equals(itemType)) {
|
||||
|| "MeetingRequest".equals(itemType)
|
||||
// VTODOs appear as Messages
|
||||
|| "Message".equals(itemType)) {
|
||||
return new Event(item);
|
||||
} else {
|
||||
throw new DavMailException("EXCEPTION_ITEM_NOT_FOUND");
|
||||
|
@ -98,6 +98,21 @@ public class TestExchangeSessionCalendar extends AbstractExchangeSessionTestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void testReportCalendar() throws IOException {
|
||||
List<ExchangeSession.Event> events = null;
|
||||
try {
|
||||
events = session.getAllEvents("/users/" + session.getEmail() + "/calendar");
|
||||
for (ExchangeSession.Event event : events) {
|
||||
System.out.println(event.subject);
|
||||
ExchangeSession.Item item = session.getItem("/users/" + session.getEmail() + "/calendar", event.itemName);
|
||||
System.out.println(item.getBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetFreeBusyData() throws IOException, MessagingException {
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
cal.set(Calendar.MONTH, 7);
|
||||
|
Loading…
Reference in New Issue
Block a user