use of org.apache.commons.httpclient.methods.GetMethod in project h2o-2 by h2oai.
the class HttpTest method get.
public Get get(String uri, Class c) {
GetMethod get = new GetMethod("http://127.0.0.1:54321/" + uri);
Get res = new Get();
try {
res._status = _client.executeMethod(get);
if (res._status == 200) {
Gson gson = new Gson();
res._res = gson.fromJson(new InputStreamReader(get.getResponseBodyAsStream()), c);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
get.releaseConnection();
return res;
}
use of org.apache.commons.httpclient.methods.GetMethod in project tdi-studio-se by Talend.
the class ExchangeUtils method sendGetRequest.
public static String sendGetRequest(String urlAddress) throws Exception {
HttpClient httpclient = new HttpClient();
GetMethod getMethod = new GetMethod(urlAddress);
TransportClientProperties tcp = TransportClientPropertiesFactory.create("http");
if (tcp.getProxyHost().length() != 0) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(tcp.getProxyUser() != null ? tcp.getProxyUser() : "", tcp.getProxyPassword() != null ? tcp.getProxyUser() : "");
httpclient.getState().setProxyCredentials(AuthScope.ANY, creds);
HostConfiguration hcf = new HostConfiguration();
hcf.setProxy(tcp.getProxyHost(), Integer.parseInt(tcp.getProxyPort()));
httpclient.executeMethod(hcf, getMethod);
} else {
httpclient.executeMethod(getMethod);
}
String response = getMethod.getResponseBodyAsString();
getMethod.releaseConnection();
return response;
}
use of org.apache.commons.httpclient.methods.GetMethod in project tdi-studio-se by Talend.
the class MDMTransactionClient method getSessionID.
public static String getSessionID(String url, String username, String password) throws IOException {
HttpClient client = new HttpClient();
client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
client.getParams().setAuthenticationPreemptive(true);
GetMethod get = new GetMethod(url);
get.setDoAuthentication(true);
String sessionID;
try {
client.executeMethod(get);
sessionID = parseSessionID(get);
} catch (HttpException e) {
throw e;
} catch (IOException e) {
throw e;
} finally {
get.releaseConnection();
}
return sessionID;
}
use of org.apache.commons.httpclient.methods.GetMethod in project tdi-studio-se by Talend.
the class WSDLLocatorImpl method getImportInputSource.
public InputSource getImportInputSource(String parentLocation, String importLocation) {
try {
String contextURI = parentLocation;
URL contextURL = (contextURI != null) ? getURL(null, contextURI) : null;
URL url = getURL(contextURL, importLocation);
latestImportUri = url.toExternalForm();
GetMethod get = createGedMethod(latestImportUri);
httpClient.executeMethod(get);
InputStream is = get.getResponseBodyAsStream();
inputStreams.add(is);
return new InputSource(is);
} catch (MalformedURLException ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.commons.httpclient.methods.GetMethod in project zm-mailbox by Zimbra.
the class ZMailbox method getRESTResource.
private InputStream getRESTResource(String relativePath, String startTimeArg, String endTimeArg, int msecTimeout, String alternateUrl) throws ServiceException {
GetMethod get = null;
URI uri = null;
int statusCode;
try {
if (startTimeArg != null) {
String encodedArg = URLEncoder.encode(startTimeArg, "UTF-8");
if (!relativePath.contains("?")) {
relativePath = relativePath + "?start=" + encodedArg;
} else {
relativePath = relativePath + "&start=" + encodedArg;
}
}
if (endTimeArg != null) {
String encodedArg = URLEncoder.encode(endTimeArg, "UTF-8");
if (!relativePath.contains("?")) {
relativePath = relativePath + "?end=" + encodedArg;
} else {
relativePath = relativePath + "&end=" + encodedArg;
}
}
uri = getRestURI(relativePath, alternateUrl);
HttpClient client = getHttpClient(uri);
get = new GetMethod(uri.toString());
if (msecTimeout > -1) {
get.getParams().setSoTimeout(msecTimeout);
}
statusCode = HttpClientUtil.executeMethod(client, get);
// parse the response
if (statusCode == HttpServletResponse.SC_OK) {
return new GetMethodInputStream(get);
} else {
String msg = String.format("GET from %s failed, status=%d. %s", uri.toString(), statusCode, get.getStatusText());
throw ServiceException.FAILURE(msg, null);
}
} catch (IOException e) {
String fromUri = "";
if (uri != null) {
fromUri = " from " + uri.toString();
}
String msg = String.format("Unable to get REST resource%s: %s", fromUri, e.getMessage());
throw ZClientException.IO_ERROR(msg, e);
}
}
Aggregations