Search in sources :

Example 1 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project tdi-studio-se by Talend.

the class ExchangeUtils method sendPostRequest.

public static String sendPostRequest(String urlAddress, Map<String, String> parameters) throws Exception {
    HttpClient httpclient = new HttpClient();
    PostMethod postMethod = new PostMethod(urlAddress);
    if (parameters != null) {
        NameValuePair[] postData = new NameValuePair[parameters.size()];
        int i = 0;
        for (String key : parameters.keySet()) {
            String value = parameters.get(key);
            postData[i++] = new NameValuePair(key, value);
        }
        postMethod.addParameters(postData);
    }
    httpclient.executeMethod(postMethod);
    String response = postMethod.getResponseBodyAsString();
    postMethod.releaseConnection();
    return response;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 2 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair 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 3 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project sling by apache.

the class HttpTestBase method getContent.

/** retrieve the contents of given URL and assert its content type
     * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked
     * @param httpMethod supports just GET and POST methods
     * @throws IOException
     * @throws HttpException */
public String getContent(String url, String expectedContentType, List<NameValuePair> params, int expectedStatusCode, String httpMethod) throws IOException {
    HttpMethodBase method = null;
    if (HTTP_METHOD_GET.equals(httpMethod)) {
        method = new GetMethod(url);
    } else if (HTTP_METHOD_POST.equals(httpMethod)) {
        method = new PostMethod(url);
    } else {
        fail("Http Method not supported in this test suite, method: " + httpMethod);
    }
    if (params != null) {
        final NameValuePair[] nvp = new NameValuePair[0];
        method.setQueryString(params.toArray(nvp));
    }
    final int status = httpClient.executeMethod(method);
    final String content = getResponseBodyAsStream(method, 0);
    assertEquals("Expected status " + expectedStatusCode + " for " + url + " (content=" + content + ")", expectedStatusCode, status);
    final Header h = method.getResponseHeader("Content-Type");
    if (expectedContentType == null) {
        if (h != null) {
            fail("Expected null Content-Type, got " + h.getValue());
        }
    } else if (CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
    // no check
    } else if (h == null) {
        fail("Expected Content-Type that starts with '" + expectedContentType + " but got no Content-Type header at " + url);
    } else {
        assertTrue("Expected Content-Type that starts with '" + expectedContentType + "' for " + url + ", got '" + h.getValue() + "'", h.getValue().startsWith(expectedContentType));
    }
    return content.toString();
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) HttpMethodBase(org.apache.commons.httpclient.HttpMethodBase) Header(org.apache.commons.httpclient.Header) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod)

Example 4 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project camel by apache.

the class HttpRouteTest method testPostParameter.

@Test
public void testPostParameter() throws Exception {
    NameValuePair[] data = { new NameValuePair("request", "PostParameter"), new NameValuePair("others", "bloggs") };
    HttpClient client = new HttpClient();
    PostMethod post = new PostMethod("http://localhost:" + port1 + "/parameter");
    post.setRequestBody(data);
    client.executeMethod(post);
    InputStream response = post.getResponseBodyAsStream();
    String out = context.getTypeConverter().convertTo(String.class, response);
    assertEquals("Get a wrong output ", "PostParameter", out);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test)

Example 5 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project uavstack by uavorg.

the class HttpService method httpClient3PostTest.

/**
 * 同步客户端3.X版本
 *
 * @return
 */
@GET
@Path("httpclient3Posttest")
public String httpClient3PostTest() {
    HttpClient httpClient = new HttpClient();
    PostMethod method = new PostMethod("http://localhost:8080/com.creditease.uav.monitorframework.buildFat/rs/TestRestService/methodPath2?user=httpclient3Posttest");
    NameValuePair nameValuePair = new NameValuePair("name", "tom");
    NameValuePair[] pairs = { nameValuePair };
    method.setRequestBody(pairs);
    try {
        httpClient.executeMethod(method);
        System.out.println(method.getURI());
        System.out.println(method.getStatusLine());
        System.out.println(method.getName());
        System.out.println(method.getResponseHeader("Server").getValue());
        System.out.println(method.getResponseBodyAsString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        return method.getResponseBodyAsString();
    } catch (IOException e) {
        return e.toString();
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

NameValuePair (org.apache.commons.httpclient.NameValuePair)217 ArrayList (java.util.ArrayList)114 Credentials (org.apache.commons.httpclient.Credentials)64 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)64 Test (org.junit.Test)61 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)49 JsonObject (javax.json.JsonObject)43 PostMethod (org.apache.commons.httpclient.methods.PostMethod)41 HashMap (java.util.HashMap)28 IOException (java.io.IOException)23 Header (org.apache.commons.httpclient.Header)21 JsonArray (javax.json.JsonArray)20 HttpClient (org.apache.commons.httpclient.HttpClient)19 HashSet (java.util.HashSet)17 HttpMethod (org.apache.commons.httpclient.HttpMethod)16 GetMethod (org.apache.commons.httpclient.methods.GetMethod)16 Cookie (org.apache.commons.httpclient.Cookie)13 GetRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest)10 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8