use of org.apache.commons.httpclient.params.HttpClientParams in project maven-plugins by apache.
the class ClassicJiraDownloader method doExecute.
/**
* Execute the query on the JIRA server.
*
* @throws Exception on error
*/
public void doExecute() throws Exception {
try {
HttpClient client = new HttpClient();
// MCHANGES-89 Allow circular redirects
HttpClientParams clientParams = client.getParams();
clientParams.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
// MCHANGES-237
clientParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
HttpState state = new HttpState();
HostConfiguration hc = new HostConfiguration();
client.setHostConfiguration(hc);
client.setState(state);
String baseUrl = JiraHelper.getBaseUrl(project.getIssueManagement().getUrl());
getLog().debug("JIRA lives at: " + baseUrl);
// Here we only need the host part of the URL
determineProxy(baseUrl, client);
prepareBasicAuthentication(client);
boolean jiraAuthenticationSuccessful = false;
if (isJiraAuthenticationConfigured()) {
// Here we only need the parts up to and including the host part of the URL
jiraAuthenticationSuccessful = doJiraAuthentication(client, baseUrl);
}
if ((isJiraAuthenticationConfigured() && jiraAuthenticationSuccessful) || !isJiraAuthenticationConfigured()) {
String fullUrl;
if (useJql) {
fullUrl = getJqlQueryURL();
} else {
fullUrl = getParameterBasedQueryURL(client);
}
if (log.isDebugEnabled()) {
log.debug("download jira issues from url " + fullUrl);
}
// execute the GET
download(client, fullUrl);
}
} catch (Exception e) {
if (project.getIssueManagement() != null) {
getLog().error("Error accessing " + project.getIssueManagement().getUrl(), e);
} else {
getLog().error("Error accessing mock project issues", e);
}
}
}
use of org.apache.commons.httpclient.params.HttpClientParams in project bamboobsc by billchen198318.
the class ApplicationSiteUtils method checkTestConnection.
private static boolean checkTestConnection(String host, String contextPath, HttpServletRequest request) {
boolean test = false;
String basePath = request.getScheme() + "://" + host + "/" + contextPath;
String urlStr = basePath + "/pages/system/testJsonResult.action";
try {
logger.info("checkTestConnection , url=" + urlStr);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(urlStr);
HttpClientParams params = new HttpClientParams();
params.setConnectionManagerTimeout(TEST_JSON_HTTP_TIMEOUT);
client.setParams(params);
client.executeMethod(method);
byte[] responseBody = method.getResponseBody();
if (null == responseBody) {
test = false;
return test;
}
String content = new String(responseBody, Constants.BASE_ENCODING);
ObjectMapper mapper = new ObjectMapper();
@SuppressWarnings("unchecked") Map<String, Object> dataMap = (Map<String, Object>) mapper.readValue(content, HashMap.class);
if (YesNo.YES.equals(dataMap.get("success"))) {
test = true;
}
} catch (JsonParseException e) {
logger.error(e.getMessage().toString());
} catch (JsonMappingException e) {
logger.error(e.getMessage().toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (!test) {
logger.warn("checkTestConnection : " + String.valueOf(test));
} else {
logger.info("checkTestConnection : " + String.valueOf(test));
}
}
return test;
}
use of org.apache.commons.httpclient.params.HttpClientParams in project dianping-open-sdk by dianping.
the class ApiTool method requestApi.
public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
String queryString = getQueryString(appKey, secret, paramMap);
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
HttpMethod method = new GetMethod(apiUrl);
try {
if (StringUtils.isNotBlank(queryString)) {
// Encode query string with UTF-8
String encodeQuery = URIUtil.encodeQuery(queryString, "UTF-8");
LOGGER.debug("Encoded Query:" + encodeQuery);
method.setQueryString(encodeQuery);
}
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (URIException e) {
LOGGER.error("Can not encode query: " + queryString + " with charset UTF-8. ", e);
} catch (IOException e) {
LOGGER.error("Request URL: " + apiUrl + " failed. ", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
use of org.apache.commons.httpclient.params.HttpClientParams in project dianping-open-sdk by dianping.
the class DemoApiTool method requestApi.
public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
String queryString = getQueryString(appKey, secret, paramMap);
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
HttpMethod method = new GetMethod(apiUrl);
try {
if (StringUtils.isNotBlank(queryString)) {
// Encode query string with UTF-8
String encodeQuery = URIUtil.encodeQuery(queryString, "UTF-8");
LOGGER.debug("Encoded Query:" + encodeQuery);
method.setQueryString(encodeQuery);
}
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (URIException e) {
LOGGER.error("Can not encode query: " + queryString + " with charset UTF-8. ", e);
} catch (IOException e) {
LOGGER.error("Request URL: " + apiUrl + " failed. ", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
Aggregations