use of com.zimbra.cs.client.soap.LmcSoapClientException in project zm-mailbox by Zimbra.
the class LmcMessage method downloadAttachment.
public byte[] downloadAttachment(String partNo, String baseURL, LmcSession session, String cookieDomain, int msTimeout) throws LmcSoapClientException, IOException {
// set the cookie.
if (session == null)
System.err.println(System.currentTimeMillis() + " " + Thread.currentThread() + " LmcMessage.downloadAttachment session=null");
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
String url = baseURL + "?id=" + getID() + "&part=" + partNo;
GetMethod get = new GetMethod(url);
ZAuthToken zat = session.getAuthToken();
Map<String, String> cookieMap = zat.cookieMap(false);
if (cookieMap != null) {
HttpState initialState = new HttpState();
for (Map.Entry<String, String> ck : cookieMap.entrySet()) {
Cookie cookie = new Cookie(cookieDomain, ck.getKey(), ck.getValue(), "/", -1, false);
initialState.addCookie(cookie);
}
client.setState(initialState);
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
}
get.getParams().setSoTimeout(msTimeout);
int statusCode = -1;
try {
statusCode = HttpClientUtil.executeMethod(client, get);
// parse the response
if (statusCode == 200) {
return get.getResponseBody();
} else {
throw new LmcSoapClientException("Attachment download failed, status=" + statusCode);
}
} catch (IOException e) {
System.err.println("Attachment download failed");
e.printStackTrace();
throw e;
} finally {
get.releaseConnection();
}
}
Aggregations