use of org.apache.commons.httpclient.URIException in project knime-core by knime.
the class ListFilesSettings method getDirectoriesFromLocationString.
/**
* Split location string by ";" and return individual directories.
*
* @return A list of files representing directories.
* @throws InvalidSettingsException If the argument is invalid or does not
* represent a list of existing directories.
*/
public Collection<File> getDirectoriesFromLocationString() throws InvalidSettingsException {
if (m_locationString == null || m_locationString.equals("")) {
throw new InvalidSettingsException("Please select a folder!");
}
String[] subs = m_locationString.split(";");
List<File> result = new ArrayList<File>();
for (String s : subs) {
File f = new File(s);
if (!f.isDirectory()) {
try {
if (s.startsWith("file:")) {
s = s.substring(5);
}
f = new File(URIUtil.decode(s));
} catch (URIException ex) {
throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory");
}
if (!f.isDirectory()) {
throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory");
}
}
result.add(f);
}
return result;
}
use of org.apache.commons.httpclient.URIException in project uavstack by uavorg.
the class ApacheHttpClient3IT method doStart.
/**
* for http client
*
* @param args
* @return
*/
@SuppressWarnings({ "unused", "unchecked" })
public void doStart(Object[] args) {
HostConfiguration hostconfig = (HostConfiguration) args[0];
HttpMethod method = (HttpMethod) args[1];
HttpState state = (HttpState) args[2];
String httpAction = "";
method.setRequestHeader("UAV-Client-Src", MonitorServerUtil.getUAVClientSrc(this.applicationId));
try {
httpAction = method.getName();
targetURL = method.getURI().toString();
} catch (URIException e) {
// ignore
}
Map<String, Object> params = new HashMap<String, Object>();
params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, targetURL);
params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, httpAction);
params.put(CaptureConstants.INFO_CLIENT_APPID, this.applicationId);
params.put(CaptureConstants.INFO_CLIENT_TYPE, "apache.http.Client");
if (logger.isDebugable()) {
logger.debug("Invoke START:" + targetURL + "," + httpAction + "," + this.applicationId, null);
}
UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT, Monitor.CapturePhase.PRECAP, params);
// register adapter
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "registerAdapter", ApacheHttpClient3Adapter.class);
ivcContextParams = (Map<String, Object>) UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap", InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params, ApacheHttpClient3Adapter.class, args);
}
use of org.apache.commons.httpclient.URIException in project dataverse by IQSS.
the class HttpSendReceiveClientStep method buildMethod.
HttpMethodBase buildMethod(boolean rollback, WorkflowContext ctxt) throws Exception {
String methodName = params.getOrDefault("method" + (rollback ? "-rollback" : ""), "GET").trim().toUpperCase();
HttpMethodBase m = null;
switch(methodName) {
case "GET":
m = new GetMethod();
m.setFollowRedirects(true);
break;
case "POST":
m = new PostMethod();
break;
case "PUT":
m = new PutMethod();
break;
case "DELETE":
m = new DeleteMethod();
m.setFollowRedirects(true);
break;
default:
throw new IllegalStateException("Unsupported HTTP method: '" + methodName + "'");
}
Map<String, String> templateParams = new HashMap<>();
templateParams.put("invocationId", ctxt.getInvocationId());
templateParams.put("dataset.id", Long.toString(ctxt.getDataset().getId()));
templateParams.put("dataset.identifier", ctxt.getDataset().getIdentifier());
templateParams.put("dataset.globalId", ctxt.getDataset().getGlobalId());
templateParams.put("dataset.displayName", ctxt.getDataset().getDisplayName());
templateParams.put("dataset.citation", ctxt.getDataset().getCitation());
templateParams.put("minorVersion", Long.toString(ctxt.getNextMinorVersionNumber()));
templateParams.put("majorVersion", Long.toString(ctxt.getNextVersionNumber()));
templateParams.put("releaseStatus", (ctxt.getType() == TriggerType.PostPublishDataset) ? "done" : "in-progress");
m.addRequestHeader("Content-Type", params.getOrDefault("contentType", "text/plain"));
String urlKey = rollback ? "rollbackUrl" : "url";
String url = params.get(urlKey);
try {
m.setURI(new URI(process(url, templateParams), true));
} catch (URIException ex) {
throw new IllegalStateException("Illegal URL: '" + url + "'");
}
String bodyKey = (rollback ? "rollbackBody" : "body");
if (params.containsKey(bodyKey) && m instanceof EntityEnclosingMethod) {
String body = params.get(bodyKey);
((EntityEnclosingMethod) m).setRequestEntity(new StringRequestEntity(process(body, templateParams)));
}
return m;
}
use of org.apache.commons.httpclient.URIException 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();
}
use of org.apache.commons.httpclient.URIException 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();
}
Aggregations