Search in sources :

Example 61 with GetMethod

use of org.apache.commons.httpclient.methods.GetMethod in project intellij-community by JetBrains.

the class JiraLegacyApi method findTasks.

@NotNull
@Override
public List<Task> findTasks(@NotNull String query, int max) throws Exception {
    // Unfortunately, both SOAP and XML-RPC interfaces of JIRA don't allow fetching *all* tasks from server, but
    // only filtered by some search term (see http://stackoverflow.com/questions/764282/how-can-jira-soap-api-not-have-this-method).
    // JQL was added in SOAP only since JIRA 4.0 (see method JiraSoapService#getIssuesFromJqlSearch() at
    // https://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/index.html?com/atlassian/jira/rpc/soap/JiraSoapService.html)
    // So due to this limitation and the need to support these old versions of bug tracker (3.0, 4.2) we need the following ugly and hacky
    // solution with extracting issues from RSS feed.
    GetMethod method = new GetMethod(myRepository.getUrl() + RSS_SEARCH_PATH);
    method.setQueryString(new NameValuePair[] { new NameValuePair("tempMax", String.valueOf(max)), new NameValuePair("assignee", TaskUtil.encodeUrl(myRepository.getUsername())), new NameValuePair("reset", "true"), new NameValuePair("sorter/field", "updated"), new NameValuePair("sorter/order", "DESC"), new NameValuePair("pager/start", "0") });
    return processRSS(method);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) GetMethod(org.apache.commons.httpclient.methods.GetMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with GetMethod

use of org.apache.commons.httpclient.methods.GetMethod in project intellij-community by JetBrains.

the class LighthouseRepository method doREST.

private HttpMethod doREST(String request, boolean post, HttpClient client) throws Exception {
    String uri = getUrl() + request;
    HttpMethod method = post ? new PostMethod(uri) : new GetMethod(uri);
    configureHttpMethod(method);
    client.executeMethod(method);
    return method;
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 63 with GetMethod

use of org.apache.commons.httpclient.methods.GetMethod in project intellij-community by JetBrains.

the class LighthouseRepository method login.

private HttpClient login() throws Exception {
    HttpClient client = getHttpClient();
    GetMethod method = new GetMethod(getUrl() + "/projects.xml");
    configureHttpMethod(method);
    client.getParams().setContentCharset("UTF-8");
    client.executeMethod(method);
    if (method.getStatusCode() != 200) {
        throw new Exception("Cannot login: HTTP returned " + method.getStatusCode());
    }
    String response = method.getResponseBodyAsString();
    if (response == null) {
        throw new NullPointerException();
    }
    if (response.contains("<errors>")) {
        int pos = response.indexOf("</errors>");
        int length = "<errors>".length();
        if (pos > length) {
            response = response.substring(length, pos);
        }
        throw new Exception("Cannot login: " + response);
    }
    return client;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ParseException(java.text.ParseException)

Example 64 with GetMethod

use of org.apache.commons.httpclient.methods.GetMethod in project CloudStack-archive by CloudStack-extras.

the class StressTestDirectAttach method executeEventsAndBilling.

private static int executeEventsAndBilling(String server, String developerServer) throws HttpException, IOException {
    // test steps:
    // - get all the events in the system for all users in the system
    // - generate all the usage records in the system
    // - get all the usage records in the system
    // -----------------------------
    // GET EVENTS
    // -----------------------------
    String url = server + "?command=listEvents&page=1&account=" + _account.get();
    s_logger.info("Getting events for the account " + _account.get());
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(url);
    int responseCode = client.executeMethod(method);
    s_logger.info("get events response code: " + responseCode);
    if (responseCode == 200) {
        InputStream is = method.getResponseBodyAsStream();
        Map<String, List<String>> eventDescriptions = getMultipleValuesFromXML(is, new String[] { "description" });
        List<String> descriptionText = eventDescriptions.get("description");
        if (descriptionText == null) {
            s_logger.info("no events retrieved...");
        } else {
            for (String text : descriptionText) {
                s_logger.info("event: " + text);
            }
        }
    } else {
        s_logger.error("list events failed with error code: " + responseCode + ". Following URL was sent: " + url);
        return responseCode;
    }
    return responseCode;
}
Also used : InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 65 with GetMethod

use of org.apache.commons.httpclient.methods.GetMethod in project CloudStack-archive by CloudStack-extras.

the class StressTestDirectAttach method executeStop.

private static int executeStop(String server, String developerServer, String username) throws HttpException, IOException {
    // test steps:
    // - get userId for the given username
    // - list virtual machines for the user
    // - stop all virtual machines
    // - get ip addresses for the user
    // - release ip addresses
    // -----------------------------
    // GET USER
    // -----------------------------
    String userId = _userId.get().toString();
    String encodedUserId = URLEncoder.encode(userId, "UTF-8");
    String url = server + "?command=listUsers&id=" + encodedUserId;
    s_logger.info("Stopping resources for user: " + username);
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(url);
    int responseCode = client.executeMethod(method);
    s_logger.info("get user response code: " + responseCode);
    if (responseCode == 200) {
        InputStream is = method.getResponseBodyAsStream();
        Map<String, String> userIdValues = getSingleValueFromXML(is, new String[] { "id" });
        String userIdStr = userIdValues.get("id");
        if (userIdStr != null) {
            userId = userIdStr;
            if (userId == null) {
                s_logger.error("get user failed to retrieve a valid user id, aborting depolyment test" + ". Following URL was sent: " + url);
                return -1;
            }
        }
    } else {
        s_logger.error("get user failed with error code: " + responseCode + ". Following URL was sent: " + url);
        return responseCode;
    }
    {
        // ----------------------------------
        // LIST VIRTUAL MACHINES
        // ----------------------------------
        String encodedApiKey = URLEncoder.encode(_apiKey.get(), "UTF-8");
        String requestToSign = "apikey=" + encodedApiKey + "&command=listVirtualMachines";
        requestToSign = requestToSign.toLowerCase();
        String signature = signRequest(requestToSign, _secretKey.get());
        String encodedSignature = URLEncoder.encode(signature, "UTF-8");
        url = developerServer + "?command=listVirtualMachines&apikey=" + encodedApiKey + "&signature=" + encodedSignature;
        s_logger.info("Listing all virtual machines for the user with url " + url);
        String[] vmIds = null;
        client = new HttpClient();
        method = new GetMethod(url);
        responseCode = client.executeMethod(method);
        s_logger.info("list virtual machines response code: " + responseCode);
        if (responseCode == 200) {
            InputStream is = method.getResponseBodyAsStream();
            Map<String, List<String>> vmIdValues = getMultipleValuesFromXML(is, new String[] { "id" });
            if (vmIdValues.containsKey("id")) {
                List<String> vmIdList = vmIdValues.get("id");
                if (vmIdList != null) {
                    vmIds = new String[vmIdList.size()];
                    vmIdList.toArray(vmIds);
                    String vmIdLogStr = "";
                    if ((vmIds != null) && (vmIds.length > 0)) {
                        vmIdLogStr = vmIds[0];
                        for (int i = 1; i < vmIds.length; i++) {
                            vmIdLogStr = vmIdLogStr + "," + vmIds[i];
                        }
                    }
                    s_logger.info("got virtual machine ids: " + vmIdLogStr);
                }
            }
        } else {
            s_logger.error("list virtual machines test failed with error code: " + responseCode + ". Following URL was sent: " + url);
            return responseCode;
        }
        // ----------------------------------
        if (vmIds != null) {
            for (String vmId : vmIds) {
                requestToSign = "apikey=" + encodedApiKey + "&command=stopVirtualMachine&id=" + vmId;
                requestToSign = requestToSign.toLowerCase();
                signature = signRequest(requestToSign, _secretKey.get());
                encodedSignature = URLEncoder.encode(signature, "UTF-8");
                url = developerServer + "?command=stopVirtualMachine&id=" + vmId + "&apikey=" + encodedApiKey + "&signature=" + encodedSignature;
                client = new HttpClient();
                method = new GetMethod(url);
                responseCode = client.executeMethod(method);
                s_logger.info("StopVirtualMachine" + " [" + vmId + "] response code: " + responseCode);
                if (responseCode == 200) {
                    InputStream input = method.getResponseBodyAsStream();
                    Element el = queryAsyncJobResult(server, input);
                    Map<String, String> success = getSingleValueFromXML(el, new String[] { "success" });
                    s_logger.info("StopVirtualMachine..success? " + success.get("success"));
                } else {
                    s_logger.error("Stop virtual machine test failed with error code: " + responseCode + ". Following URL was sent: " + url);
                    return responseCode;
                }
            }
        }
    //			{
    //				url = server + "?command=deleteUser&id=" + userId;
    //				client = new HttpClient();
    //				method = new GetMethod(url);
    //				responseCode = client.executeMethod(method);
    //				s_logger.info("delete user response code: " + responseCode);
    //				if (responseCode == 200) {
    //					InputStream input = method.getResponseBodyAsStream();
    //					Element el = queryAsyncJobResult(server, input);
    //					s_logger
    //							.info("Deleted user successfully");
    //				} else  {
    //					s_logger.error("delete user failed with error code: " + responseCode + ". Following URL was sent: " + url);
    //					return responseCode;
    //				} 
    //			}
    }
    _linuxIP.set("");
    _linuxVmId.set("");
    _linuxPassword.set("");
    _windowsIP.set("");
    _secretKey.set("");
    _apiKey.set("");
    _userId.set(Long.parseLong("0"));
    _account.set("");
    _domainRouterId.set("");
    return responseCode;
}
Also used : InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) Element(org.w3c.dom.Element) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HttpMethod(org.apache.commons.httpclient.HttpMethod)

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