mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-07 03:38:05 -05:00
Improve contact picture error handling
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2240 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
a16ae1203b
commit
c3dabcdfe4
@ -2279,41 +2279,39 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
@Override
|
@Override
|
||||||
public ExchangeSession.ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException {
|
public ExchangeSession.ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException {
|
||||||
ContactPhoto contactPhoto = null;
|
ContactPhoto contactPhoto = null;
|
||||||
if ("true".equals(contact.get("haspicture"))) {
|
final GetMethod method = new GetMethod(URIUtil.encodePath(contact.getHref()) + "/ContactPicture.jpg");
|
||||||
final GetMethod method = new GetMethod(URIUtil.encodePath(contact.getHref()) + "/ContactPicture.jpg");
|
method.setRequestHeader("Translate", "f");
|
||||||
method.setRequestHeader("Translate", "f");
|
method.setRequestHeader("Accept-Encoding", "gzip");
|
||||||
method.setRequestHeader("Accept-Encoding", "gzip");
|
|
||||||
|
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
|
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
|
||||||
if (DavGatewayHttpClientFacade.isGzipEncoded(method)) {
|
if (DavGatewayHttpClientFacade.isGzipEncoded(method)) {
|
||||||
inputStream = (new GZIPInputStream(method.getResponseBodyAsStream()));
|
inputStream = (new GZIPInputStream(method.getResponseBodyAsStream()));
|
||||||
} else {
|
} else {
|
||||||
inputStream = method.getResponseBodyAsStream();
|
inputStream = method.getResponseBodyAsStream();
|
||||||
}
|
|
||||||
|
|
||||||
contactPhoto = new ContactPhoto();
|
|
||||||
contactPhoto.contentType = "image/jpeg";
|
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
InputStream partInputStream = inputStream;
|
|
||||||
byte[] bytes = new byte[8192];
|
|
||||||
int length;
|
|
||||||
while ((length = partInputStream.read(bytes)) > 0) {
|
|
||||||
baos.write(bytes, 0, length);
|
|
||||||
}
|
|
||||||
contactPhoto.content = new String(Base64.encodeBase64(baos.toByteArray()));
|
|
||||||
} finally {
|
|
||||||
if (inputStream != null) {
|
|
||||||
try {
|
|
||||||
inputStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.debug(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
method.releaseConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contactPhoto = new ContactPhoto();
|
||||||
|
contactPhoto.contentType = "image/jpeg";
|
||||||
|
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
InputStream partInputStream = inputStream;
|
||||||
|
byte[] bytes = new byte[8192];
|
||||||
|
int length;
|
||||||
|
while ((length = partInputStream.read(bytes)) > 0) {
|
||||||
|
baos.write(bytes, 0, length);
|
||||||
|
}
|
||||||
|
contactPhoto.content = new String(Base64.encodeBase64(baos.toByteArray()));
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.debug(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
method.releaseConnection();
|
||||||
}
|
}
|
||||||
return contactPhoto;
|
return contactPhoto;
|
||||||
}
|
}
|
||||||
|
@ -2011,22 +2011,23 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
getItemMethod.addAdditionalProperty(Field.get("attachments"));
|
getItemMethod.addAdditionalProperty(Field.get("attachments"));
|
||||||
executeMethod(getItemMethod);
|
executeMethod(getItemMethod);
|
||||||
EWSMethod.Item item = getItemMethod.getResponseItem();
|
EWSMethod.Item item = getItemMethod.getResponseItem();
|
||||||
if (item != null) {
|
if (item == null) {
|
||||||
FileAttachment attachment = item.getAttachmentByName("ContactPicture.jpg");
|
throw new IOException("Missing contact picture");
|
||||||
if (attachment == null) {
|
}
|
||||||
throw new IOException("Missing contact picture");
|
FileAttachment attachment = item.getAttachmentByName("ContactPicture.jpg");
|
||||||
}
|
if (attachment == null) {
|
||||||
// get attachment content
|
throw new IOException("Missing contact picture");
|
||||||
GetAttachmentMethod getAttachmentMethod = new GetAttachmentMethod(attachment.attachmentId);
|
}
|
||||||
executeMethod(getAttachmentMethod);
|
// get attachment content
|
||||||
|
GetAttachmentMethod getAttachmentMethod = new GetAttachmentMethod(attachment.attachmentId);
|
||||||
|
executeMethod(getAttachmentMethod);
|
||||||
|
|
||||||
contactPhoto = new ContactPhoto();
|
contactPhoto = new ContactPhoto();
|
||||||
contactPhoto.content = getAttachmentMethod.getResponseItem().get("Content");
|
contactPhoto.content = getAttachmentMethod.getResponseItem().get("Content");
|
||||||
if (attachment.contentType == null) {
|
if (attachment.contentType == null) {
|
||||||
contactPhoto.contentType = "image/jpeg";
|
contactPhoto.contentType = "image/jpeg";
|
||||||
} else {
|
} else {
|
||||||
contactPhoto.contentType = attachment.contentType;
|
contactPhoto.contentType = attachment.contentType;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return contactPhoto;
|
return contactPhoto;
|
||||||
|
Loading…
Reference in New Issue
Block a user