Search in sources :

Example 36 with URIException

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;
}
Also used : URIException(org.apache.commons.httpclient.URIException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) File(java.io.File)

Example 37 with URIException

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);
}
Also used : URIException(org.apache.commons.httpclient.URIException) HashMap(java.util.HashMap) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpState(org.apache.commons.httpclient.HttpState) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 38 with URIException

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;
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) HttpMethodBase(org.apache.commons.httpclient.HttpMethodBase) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HashMap(java.util.HashMap) EntityEnclosingMethod(org.apache.commons.httpclient.methods.EntityEnclosingMethod) URI(org.apache.commons.httpclient.URI) URIException(org.apache.commons.httpclient.URIException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod)

Example 39 with URIException

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();
}
Also used : URIException(org.apache.commons.httpclient.URIException) InputStreamReader(java.io.InputStreamReader) HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) GetMethod(org.apache.commons.httpclient.methods.GetMethod) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 40 with URIException

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();
}
Also used : URIException(org.apache.commons.httpclient.URIException) InputStreamReader(java.io.InputStreamReader) HttpClient(org.apache.commons.httpclient.HttpClient) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) GetMethod(org.apache.commons.httpclient.methods.GetMethod) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Aggregations

URIException (org.apache.commons.httpclient.URIException)52 URI (org.apache.commons.httpclient.URI)31 IOException (java.io.IOException)9 HttpMethod (org.apache.commons.httpclient.HttpMethod)8 Header (org.apache.commons.httpclient.Header)7 HttpClient (org.apache.commons.httpclient.HttpClient)6 ArrayList (java.util.ArrayList)5 Matcher (java.util.regex.Matcher)5 EntityEnclosingMethod (org.apache.commons.httpclient.methods.EntityEnclosingMethod)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 DatabaseException (org.parosproxy.paros.db.DatabaseException)5 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)4 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 InputStreamReader (java.io.InputStreamReader)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 HttpException (org.apache.commons.httpclient.HttpException)3 HttpMessage (org.parosproxy.paros.network.HttpMessage)3 InvalidParameterException (java.security.InvalidParameterException)2 HashMap (java.util.HashMap)2