Example usage for org.apache.commons.httpclient.util ParameterParser ParameterParser

List of usage examples for org.apache.commons.httpclient.util ParameterParser ParameterParser

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util ParameterParser ParameterParser.

Prototype

ParameterParser

Source Link

Usage

From source file:com.sun.syndication.propono.atom.client.OAuthStrategy.java

public void addAuthentication(HttpClient httpClient, HttpMethodBase method) throws ProponoException {

    if (state != State.ACCESS_TOKEN) {
        throw new ProponoException("ERROR: authentication strategy failed init");
    }//from w  w w . j a va 2 s . com

    // add OAuth name/values to request query string

    // wish we didn't have to parse them apart first, ugh
    List originalqlist = null;
    if (method.getQueryString() != null) {
        String qstring = method.getQueryString().trim();
        qstring = qstring.startsWith("?") ? qstring.substring(1) : qstring;
        originalqlist = new ParameterParser().parse(qstring, '&');
    } else {
        originalqlist = new ArrayList();
    }

    // put query string into hashmap form to please OAuth.net classes
    Map params = new HashMap();
    for (Iterator it = originalqlist.iterator(); it.hasNext();) {
        NameValuePair pair = (NameValuePair) it.next();
        params.put(pair.getName(), pair.getValue());
    }

    // add OAuth params to query string
    params.put("xoauth_requestor_id", username);
    params.put("oauth_consumer_key", consumerKey);
    params.put("oauth_signature_method", keyType);
    params.put("oauth_timestamp", Long.toString(timestamp));
    params.put("oauth_nonce", nonce);
    params.put("oauth_token", accessToken);
    params.put("oauth_token_secret", tokenSecret);

    // sign complete URI
    String finalUri = null;
    OAuthServiceProvider provider = new OAuthServiceProvider(reqUrl, authzUrl, accessUrl);
    OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, consumerSecret, provider);
    OAuthAccessor accessor = new OAuthAccessor(consumer);
    accessor.tokenSecret = tokenSecret;
    OAuthMessage message;
    try {
        message = new OAuthMessage(method.getName(), method.getURI().toString(), params.entrySet());
        message.sign(accessor);

        finalUri = OAuth.addParameters(message.URL, message.getParameters());

    } catch (Exception ex) {
        throw new ProponoException("ERROR: OAuth signing request", ex);
    }

    // pull query string off and put it back onto method
    method.setQueryString(finalUri.substring(finalUri.lastIndexOf("?")));
}

From source file:com.rometools.propono.atom.client.OAuthStrategy.java

@Override
public void addAuthentication(final HttpClient httpClient, final HttpMethodBase method)
        throws ProponoException {

    if (state != State.ACCESS_TOKEN) {
        throw new ProponoException("ERROR: authentication strategy failed init");
    }//w  w w . j a va  2s  . com

    // add OAuth name/values to request query string

    // wish we didn't have to parse them apart first, ugh
    List<NameValuePair> originalqlist = null;
    if (method.getQueryString() != null) {
        String qstring = method.getQueryString().trim();
        qstring = qstring.startsWith("?") ? qstring.substring(1) : qstring;
        @SuppressWarnings("unchecked")
        final List<NameValuePair> parameters = new ParameterParser().parse(qstring, '&');
        originalqlist = parameters;
    } else {
        originalqlist = new ArrayList<NameValuePair>();
    }

    // put query string into hashmap form to please OAuth.net classes
    final Map<String, String> params = new HashMap<String, String>();
    for (final Object element : originalqlist) {
        final NameValuePair pair = (NameValuePair) element;
        params.put(pair.getName(), pair.getValue());
    }

    // add OAuth params to query string
    params.put("xoauth_requestor_id", username);
    params.put("oauth_consumer_key", consumerKey);
    params.put("oauth_signature_method", keyType);
    params.put("oauth_timestamp", Long.toString(timestamp));
    params.put("oauth_nonce", nonce);
    params.put("oauth_token", accessToken);
    params.put("oauth_token_secret", tokenSecret);

    // sign complete URI
    String finalUri = null;
    final OAuthServiceProvider provider = new OAuthServiceProvider(reqUrl, authzUrl, accessUrl);
    final OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, consumerSecret, provider);
    final OAuthAccessor accessor = new OAuthAccessor(consumer);
    accessor.tokenSecret = tokenSecret;
    OAuthMessage message;
    try {
        message = new OAuthMessage(method.getName(), method.getURI().toString(), params.entrySet());
        message.sign(accessor);

        finalUri = OAuth.addParameters(message.URL, message.getParameters());

    } catch (final Exception ex) {
        throw new ProponoException("ERROR: OAuth signing request", ex);
    }

    // pull query string off and put it back onto method
    method.setQueryString(finalUri.substring(finalUri.lastIndexOf("?")));
}

From source file:be.ibridge.kettle.url.UrlInput.java

private Object[] buildRow() throws KettleException {

    Object[] outputRowData = RowDataUtil.resizeArray(data.readrow, data.convertRowMeta.size());

    // Read fields...
    for (int i = 0; i < data.nrInputFields; i++) {
        // Get field
        UrlInputField field = meta.getInputFields()[i];

        // get url array for field
        ParameterParser p = new ParameterParser();
        List l = p.parse(data.urlToParse.getQuery(), '&');

        String nodevalue = "";
        Iterator iter = l.iterator();
        while (iter.hasNext()) {
            NameValuePair param = (NameValuePair) iter.next();
            if (param.getName().equalsIgnoreCase(field.getValue())) {
                nodevalue = param.getValue();
            }// w w w.ja v  a2  s . c  o  m
        }

        // Do trimming
        switch (field.getTrimType()) {
        case UrlInputField.TYPE_TRIM_LEFT:
            nodevalue = Const.ltrim(nodevalue);
            break;
        case UrlInputField.TYPE_TRIM_RIGHT:
            nodevalue = Const.rtrim(nodevalue);
            break;
        case UrlInputField.TYPE_TRIM_BOTH:
            nodevalue = Const.trim(nodevalue);
            break;
        default:
            break;
        }

        // Do conversions
        //
        ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(data.totalpreviousfields + i);
        ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(data.totalpreviousfields + i);
        outputRowData[data.totalpreviousfields + i] = targetValueMeta.convertData(sourceValueMeta, nodevalue);

        // Do we need to repeat this field if it is null?
        if (meta.getInputFields()[i].isRepeated()) {
            if (data.previousRow != null && Const.isEmpty(nodevalue)) {
                outputRowData[data.totalpreviousfields + i] = data.previousRow[data.totalpreviousfields + i];
            }
        }
    } // End of loop over fields...   

    int rowIndex = data.totalpreviousfields + data.nrInputFields;

    if (meta.getAuthorityField() != null && meta.getAuthorityField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getAuthority();
    }
    if (meta.getDefaultPortField() != null && meta.getDefaultPortField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getDefaultPort();
    }
    if (meta.getFileField() != null && meta.getFileField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getFile();
    }
    if (meta.getHostField() != null && meta.getHostField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getHost();
    }
    if (meta.getPathField() != null && meta.getPathField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getPath();
    }
    if (meta.getPortField() != null && meta.getPortField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getPort();
    }
    if (meta.getProtocolField() != null && meta.getProtocolField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getProtocol();
    }
    if (meta.getQueryField() != null && meta.getQueryField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getQuery();
    }
    if (meta.getRefField() != null && meta.getRefField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getRef();
    }
    if (meta.getUserInfoField() != null && meta.getUserInfoField().length() > 0) {
        outputRowData[rowIndex++] = data.urlToParse.getUserInfo();
    }
    if (meta.getUriNameField() != null && meta.getUriNameField().length() > 0) {
        try {
            outputRowData[rowIndex++] = data.urlToParse.toURI().toString();
        } catch (URISyntaxException ex) {
            throw new KettleException(ex);
        }
    }
    data.recordnr++;

    RowMetaInterface irow = getInputRowMeta();

    data.previousRow = irow == null ? outputRowData : (Object[]) irow.cloneRow(outputRowData); // copy it to make
    // surely the next step doesn't change it in between...

    return outputRowData;
}

From source file:ddf.catalog.source.opensearch.TestOpenSearchSource.java

private List<NameValuePair> extractQueryParams(FirstArgumentCapture answer)
        throws MalformedURLException, URISyntaxException {
    URL url = new URI(answer.getInputArg()).toURL();
    ParameterParser paramParser = new ParameterParser();
    List<NameValuePair> pairs = paramParser.parse(url.getQuery(), '&');
    return pairs;
}

From source file:org.ibeans.impl.InternalInvocationContext.java

public Map<String, String> getCallSpecificUriParams() {
    if (isCallMethod()) {
        Call call = getMethod().getAnnotation(Call.class);
        final String fullUri = call.uri();
        String uri = fullUri.substring(fullUri.indexOf('?') + 1);

        // reparse the query string, we'll need to omit this 'signature' param
        final List<NameValuePair> queryParams = new ParameterParser().parse(uri, '&');

        // filter and sort the queryParams
        final SortedMap<String, String> filteredParams = new TreeMap<String, String>();

        for (NameValuePair param : queryParams) {
            filteredParams.put(param.getName(), invocationData.getUriParams().get(param.getName()).toString());
        }/*w  w w  .j  a  v a 2 s .  c o  m*/
        return filteredParams;

    }
    return Collections.emptyMap();
}

From source file:org.ibeans.impl.InternalInvocationContext.java

public Map<String, String> getTemplateSpecificUriParams() {
    if (isTemplateMethod()) {
        Template call = getMethod().getAnnotation(Template.class);
        final String fullUri = call.value();
        String uri = fullUri.substring(fullUri.indexOf('?') + 1);
        if (uri.length() == 0) {
            return Collections.emptyMap();
        }// ww  w .j ava2 s  .  c om
        //TODO remove dep on Http client

        // reparse the query string, we'll need to omit this 'signature' param
        final List<NameValuePair> queryParams = new ParameterParser().parse(uri, '&');

        // filter and sort the queryParams
        final SortedMap<String, String> filteredParams = new TreeMap<String, String>();

        for (NameValuePair param : queryParams) {
            filteredParams.put(param.getName(), (String) invocationData.getUriParams().get(param.getName()));
        }
        return filteredParams;

    }
    return Collections.emptyMap();
}