Search in sources :

Example 51 with GetMethod

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;
}
Also used : ElasticSearchConnector(com.zimbra.cs.index.elasticsearch.ElasticSearchConnector) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 52 with GetMethod

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();
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) LmcSoapClientException(com.zimbra.cs.client.soap.LmcSoapClientException) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpState(org.apache.commons.httpclient.HttpState) IOException(java.io.IOException) ZAuthToken(com.zimbra.common.auth.ZAuthToken) Map(java.util.Map)

Example 53 with GetMethod

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);
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpInputStream(com.zimbra.cs.service.UserServlet.HttpInputStream)

Example 54 with GetMethod

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;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) PostMethod(org.apache.commons.httpclient.methods.PostMethod) InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) Element(org.jdom.Element) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpMethod(org.apache.commons.httpclient.HttpMethod) JDOMException(org.jdom.JDOMException)

Example 55 with GetMethod

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());
}
Also used : JsonArray(com.google.gson.JsonArray) LocalTaskImpl(com.intellij.tasks.impl.LocalTaskImpl) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Aggregations

GetMethod (org.apache.commons.httpclient.methods.GetMethod)357 HttpClient (org.apache.commons.httpclient.HttpClient)216 HttpMethod (org.apache.commons.httpclient.HttpMethod)93 IOException (java.io.IOException)82 Test (org.junit.Test)70 InputStream (java.io.InputStream)65 HttpException (org.apache.commons.httpclient.HttpException)41 Map (java.util.Map)39 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)36 JSONParser (org.json.simple.parser.JSONParser)34 JSONObject (org.json.simple.JSONObject)31 Header (org.apache.commons.httpclient.Header)22 Element (org.w3c.dom.Element)22 PostMethod (org.apache.commons.httpclient.methods.PostMethod)21 TypeToken (com.google.gson.reflect.TypeToken)20 List (java.util.List)19 HttpState (org.apache.commons.httpclient.HttpState)18 URI (java.net.URI)17 JSONArray (org.json.simple.JSONArray)17