Search in sources :

Example 11 with URIException

use of org.apache.commons.httpclient.URIException in project knime-core by knime.

the class ListFilesNodeDialog method saveSettingsTo.

/**
 * {@inheritDoc}
 */
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
    // check if all entered Locations are valid
    String location = m_locations.getEditor().getItem().toString();
    if (location.trim().isEmpty()) {
        throw new InvalidSettingsException("Please select a file!");
    }
    String[] files = location.split(";");
    for (int i = 0; i < files.length; i++) {
        File currentFile = new File(files[i]);
        if (!currentFile.isDirectory()) {
            // check if it was an URL;
            String s = files[i];
            try {
                if (s.startsWith("file:")) {
                    s = s.substring(5);
                }
                currentFile = new File(URIUtil.decode(s));
            } catch (URIException ex) {
                throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory", ex);
            }
            if (!currentFile.isDirectory()) {
                throw new InvalidSettingsException("\"" + s + "\" does not exist or is not a directory");
            }
        }
    }
    ListFilesSettings set = new ListFilesSettings();
    set.setLocationString(location);
    set.setRecursive(m_recursive.isSelected());
    set.setCaseSensitive(m_caseSensitive.isSelected());
    String extensions = m_extensionField.getEditor().getItem().toString();
    set.setExtensionsString(extensions);
    // save the selected radio-Button
    Filter filter;
    if (m_filterALLRadio.isSelected()) {
        filter = Filter.None;
    } else if (m_filterExtensionsRadio.isSelected()) {
        filter = Filter.Extensions;
    } else if (m_filterRegExpRadio.isSelected()) {
        if (extensions.trim().isEmpty()) {
            throw new InvalidSettingsException("Enter valid regular expressin pattern");
        }
        try {
            String pattern = extensions;
            Pattern.compile(pattern);
        } catch (PatternSyntaxException pse) {
            throw new InvalidSettingsException("Error in pattern: ('" + pse.getMessage(), pse);
        }
        filter = Filter.RegExp;
    } else if (m_filterWildCardsRadio.isSelected()) {
        if ((extensions).length() <= 0) {
            throw new InvalidSettingsException("Enter valid wildcard pattern");
        }
        try {
            String pattern = extensions;
            pattern = WildcardMatcher.wildcardToRegex(pattern);
            Pattern.compile(pattern);
        } catch (PatternSyntaxException pse) {
            throw new InvalidSettingsException("Error in pattern: '" + pse.getMessage(), pse);
        }
        filter = Filter.Wildcards;
    } else {
        // one button must be selected though
        filter = Filter.None;
    }
    set.setFilter(filter);
    set.saveSettingsTo(settings);
}
Also used : URIException(org.apache.commons.httpclient.URIException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Filter(org.knime.base.node.io.listfiles.ListFiles.Filter) File(java.io.File) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 12 with URIException

use of org.apache.commons.httpclient.URIException in project knime-core by knime.

the class MultipleURLList method getSelectedURLs.

/**
 * Returns a list with all selected URLs. Empty file selection panels are
 * ignored. The list may contain invalid URLs the user has entered.
 *
 * @return a list with URLs
 */
public List<String> getSelectedURLs() {
    List<String> urls = new ArrayList<String>();
    // ConcurrentModificationExceptions; therefore the list is copied
    for (MyFilePanel fp : new ArrayList<MyFilePanel>(m_filePanels)) {
        if (fp.getSelectedFile().length() > 0) {
            URL u = null;
            String encUrl = fp.getSelectedFile();
            try {
                encUrl = URIUtil.encodePath(encUrl, "UTF-8");
                u = new URL(encUrl);
            } catch (MalformedURLException ex) {
                if (!encUrl.startsWith("/")) {
                    encUrl = "/" + encUrl;
                }
                try {
                    u = new URL("file:" + encUrl);
                    encUrl = "file:" + encUrl;
                    fp.setSelectedFile(u);
                } catch (MalformedURLException ex1) {
                // ignore it
                }
            } catch (URIException ex) {
            // ignore it
            }
            if (u != null) {
                urls.add(encUrl);
            }
        }
    }
    return urls;
}
Also used : MalformedURLException(java.net.MalformedURLException) URIException(org.apache.commons.httpclient.URIException) ArrayList(java.util.ArrayList) URL(java.net.URL)

Example 13 with URIException

use of org.apache.commons.httpclient.URIException in project xwiki-platform by xwiki.

the class Utils method createURI.

/**
 * Creates an URI to access the specified resource. The given path elements are encoded before being inserted into
 * the resource path.
 * <p>
 * NOTE: We added this method because {@link UriBuilder#build(Object...)} doesn't encode all special characters. See
 * https://github.com/restlet/restlet-framework-java/issues/601 .
 *
 * @param baseURI the base URI
 * @param resourceClass the resource class, used to get the URI path
 * @param pathElements the path elements to insert in the resource path
 * @return an URI that can be used to access the specified resource
 */
public static URI createURI(URI baseURI, java.lang.Class<?> resourceClass, java.lang.Object... pathElements) {
    UriBuilder uriBuilder = UriBuilder.fromUri(baseURI).path(resourceClass);
    List<String> pathVariableNames = null;
    if (pathElements.length > 0) {
        // uriBuilder.toString() returns the path (see AbstractUriBuilder#toString())
        // but it means UriBuilder must use AbstractUriBuilder from restlet.
        // TODO: find a more generic way to not depend heavily on restlet.
        pathVariableNames = getVariableNamesFromPathTemplate(uriBuilder.toString());
    }
    Object[] encodedPathElements = new String[pathElements.length];
    for (int i = 0; i < pathElements.length; i++) {
        Object pathElement = pathElements[i];
        if (pathElement != null) {
            try {
                // see generateEncodedSpacesURISegment() to understand why we manually handle "spaceName"
                if (i < pathVariableNames.size() && "spaceName".equals(pathVariableNames.get(i))) {
                    if (!(pathElement instanceof List)) {
                        throw new RuntimeException("The 'spaceName' parameter must be a list!");
                    }
                    encodedPathElements[i] = generateEncodedSpacesURISegment((List) pathElements[i]);
                } else if (pathElement instanceof EncodedElement) {
                    encodedPathElements[i] = pathElement.toString();
                } else {
                    encodedPathElements[i] = URIUtil.encodePath(pathElement.toString());
                }
            } catch (URIException e) {
                throw new RuntimeException("Failed to encode path element: " + pathElements[i], e);
            }
        } else {
            encodedPathElements[i] = null;
        }
    }
    return uriBuilder.buildFromEncoded(encodedPathElements);
}
Also used : URIException(org.apache.commons.httpclient.URIException) BaseObject(com.xpn.xwiki.objects.BaseObject) ArrayList(java.util.ArrayList) List(java.util.List) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 14 with URIException

use of org.apache.commons.httpclient.URIException in project airavata by apache.

the class JSDLUtils method addDataStagingTargetElement.

public static void addDataStagingTargetElement(JobDefinitionType value, String fileSystem, String file, String uri, int flags) {
    JobDescriptionType jobDescr = getOrCreateJobDescription(value);
    DataStagingType newDS = jobDescr.addNewDataStaging();
    CreationFlagEnumeration.Enum creationFlag = CreationFlagEnumeration.DONT_OVERWRITE;
    if ((flags & FLAG_OVERWRITE) != 0)
        creationFlag = CreationFlagEnumeration.OVERWRITE;
    if ((flags & FLAG_APPEND) != 0)
        creationFlag = CreationFlagEnumeration.APPEND;
    boolean deleteOnTerminate = (flags & FLAG_DELETE_ON_TERMINATE) != 0;
    newDS.setCreationFlag(creationFlag);
    newDS.setDeleteOnTermination(deleteOnTerminate);
    SourceTargetType target = newDS.addNewTarget();
    try {
        if (uri != null) {
            URIUtils.encodeAll(uri);
            target.setURI(uri);
        }
    } catch (URIException e) {
    }
    newDS.setFileName(file);
    if (fileSystem != null && !fileSystem.equals("Work")) {
        // $NON-NLS-1$
        newDS.setFilesystemName(fileSystem);
    }
}
Also used : DataStagingType(org.ggf.schemas.jsdl.x2005.x11.jsdl.DataStagingType) SourceTargetType(org.ggf.schemas.jsdl.x2005.x11.jsdl.SourceTargetType) URIException(org.apache.commons.httpclient.URIException) JobDescriptionType(org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDescriptionType) CreationFlagEnumeration(org.ggf.schemas.jsdl.x2005.x11.jsdl.CreationFlagEnumeration)

Example 15 with URIException

use of org.apache.commons.httpclient.URIException in project dianping-open-sdk by dianping.

the class DemoApiTool method requestApi.

/**
 * 请求API
 *
 * @param apiUrl
 * @param appKey
 * @param secret
 * @param paramMap
 * @return
 */
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 (queryString != null && !queryString.isEmpty()) {
            // Encode query string with UTF-8
            String encodeQuery = URIUtil.encodeQuery(queryString, "UTF-8");
            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) {
    } catch (IOException 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