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;
}
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);
}
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();
}
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);
}
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();
}
}
Aggregations