use of org.apache.commons.httpclient.methods.GetMethod in project zm-mailbox by Zimbra.
the class ElasticSearchIndexTest method indexStoreAvailable.
@Override
protected boolean indexStoreAvailable() {
String indexUrl = String.format("%s?_status", LC.zimbra_index_elasticsearch_url_base.value());
HttpMethod method = new GetMethod(indexUrl);
try {
ElasticSearchConnector connector = new ElasticSearchConnector();
connector.executeMethod(method);
} catch (HttpException e) {
ZimbraLog.index.error("Problem accessing the ElasticSearch Index store", e);
return false;
} catch (IOException e) {
ZimbraLog.index.error("Problem accessing the ElasticSearch Index store", e);
return false;
}
return true;
}
use of org.apache.commons.httpclient.methods.GetMethod 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();
}
}
use of org.apache.commons.httpclient.methods.GetMethod in project zm-mailbox by Zimbra.
the class WebDavClient method sendGet.
public HttpInputStream sendGet(String href) throws IOException {
GetMethod get = new GetMethod(mBaseUrl + href);
executeMethod(get, Depth.zero);
return new HttpInputStream(get);
}
use of org.apache.commons.httpclient.methods.GetMethod in project intellij-community by JetBrains.
the class YouTrackRepository method doREST.
HttpMethod doREST(String request, boolean post) throws Exception {
HttpClient client = login(new PostMethod(getUrl() + "/rest/user/login"));
String uri = getUrl() + request;
HttpMethod method = post ? new PostMethod(uri) : new GetMethod(uri);
configureHttpMethod(method);
int status = client.executeMethod(method);
if (status == 400) {
InputStream string = method.getResponseBodyAsStream();
Element element = new SAXBuilder(false).build(string).getRootElement();
TaskUtil.prettyFormatXmlToLog(LOG, element);
if ("error".equals(element.getName())) {
throw new Exception(element.getText());
}
}
return method;
}
use of org.apache.commons.httpclient.methods.GetMethod in project intellij-community by JetBrains.
the class JiraIntegrationTest method testSetTimeSpend.
public void testSetTimeSpend() throws Exception {
// only REST API 2.0 supports this feature
myRepository.setUrl(JIRA_5_TEST_SERVER_URL);
final String issueId = createIssueViaRestApi("BTTTU", "Test issue for time tracking updates (" + SHORT_TIMESTAMP_FORMAT.format(new Date()) + ")");
final Task task = myRepository.findTask(issueId);
assertNotNull("Test task not found", task);
// timestamp as comment
final String comment = "Timestamp: " + TaskUtil.formatDate(new Date());
final Couple<Integer> duration = generateWorkItemDuration();
final int hours = duration.getFirst(), minutes = duration.getSecond();
myRepository.updateTimeSpent(new LocalTaskImpl(task), String.format("%dh %dm", hours, minutes), comment);
final GetMethod request = new GetMethod(myRepository.getRestUrl("issue", task.getId(), "worklog"));
final String response = myRepository.executeMethod(request);
final JsonObject object = new Gson().fromJson(response, JsonObject.class);
final JsonArray worklogs = object.get("worklogs").getAsJsonArray();
final JsonObject last = worklogs.get(worklogs.size() - 1).getAsJsonObject();
assertEquals(comment, last.get("comment").getAsString());
// don't depend on concrete response format: zero hours stripping, zero padding and so on
assertEquals((hours * 60 + minutes) * 60, last.get("timeSpentSeconds").getAsInt());
}
Aggregations