Search in sources :

Example 91 with NameValuePair

use of org.apache.http.NameValuePair in project fdroidclient by f-droid.

the class WifiQrView method setUIFromWifi.

private void setUIFromWifi() {
    if (TextUtils.isEmpty(FDroidApp.repo.address)) {
        return;
    }
    String scheme = Preferences.get().isLocalRepoHttpsEnabled() ? "https://" : "http://";
    // the fingerprint is not useful on the button label
    String buttonLabel = scheme + FDroidApp.ipAddressString + ":" + FDroidApp.port;
    TextView ipAddressView = (TextView) findViewById(R.id.device_ip_address);
    ipAddressView.setText(buttonLabel);
    Uri sharingUri = Utils.getSharingUri(FDroidApp.repo);
    String qrUriString = scheme + sharingUri.getHost();
    if (sharingUri.getPort() != 80) {
        qrUriString += ":" + sharingUri.getPort();
    }
    qrUriString += sharingUri.getPath();
    boolean first = true;
    // Andorid provides an API for getting the query parameters and iterating over them:
    // Uri.getQueryParameterNames()
    // But it is only available on later Android versions. As such we use URLEncodedUtils instead.
    List<NameValuePair> parameters = URLEncodedUtils.parse(URI.create(sharingUri.toString()), "UTF-8");
    for (NameValuePair parameter : parameters) {
        if (!"ssid".equals(parameter.getName())) {
            if (first) {
                qrUriString += "?";
                first = false;
            } else {
                qrUriString += "&";
            }
            qrUriString += parameter.getName().toUpperCase(Locale.ENGLISH) + "=" + parameter.getValue().toUpperCase(Locale.ENGLISH);
        }
    }
    Utils.debugLog(TAG, "Encoded swap URI in QR Code: " + qrUriString);
    new QrGenAsyncTask(getActivity(), R.id.wifi_qr_code).execute(qrUriString);
}
Also used : NameValuePair(org.apache.http.NameValuePair) TextView(android.widget.TextView) Uri(android.net.Uri) QrGenAsyncTask(org.fdroid.fdroid.QrGenAsyncTask)

Example 92 with NameValuePair

use of org.apache.http.NameValuePair in project xwiki-platform by xwiki.

the class AbstractSxExportURLFactoryActionHandler method processSx.

private URL processSx(List<String> spaceNames, String name, String queryString, XWikiContext context, FilesystemExportContext exportContext) throws Exception {
    SxSource sxSource = null;
    // Check if we have the JAR_RESOURCE_REQUEST_PARAMETER parameter in the query string
    List<NameValuePair> params = URLEncodedUtils.parse(queryString, StandardCharsets.UTF_8);
    for (NameValuePair param : params) {
        if (param.getName().equals(JAR_RESOURCE_REQUEST_PARAMETER)) {
            sxSource = new SxResourceSource(param.getValue());
            break;
        }
    }
    if (sxSource == null) {
        sxSource = new SxDocumentSource(context, getExtensionType());
    }
    String content = getContent(sxSource, exportContext);
    // Write the content to file
    // We need a unique name for that SSX content
    String targetPath = String.format("%s/%s/%s", getSxPrefix(), StringUtils.join(spaceNames, '/'), name);
    File targetDirectory = new File(exportContext.getExportDir(), targetPath);
    if (!targetDirectory.exists()) {
        targetDirectory.mkdirs();
    }
    File targetLocation = File.createTempFile(getSxPrefix(), "." + getFileSuffix(), targetDirectory);
    FileUtils.writeStringToFile(targetLocation, content);
    // Rewrite the URL
    StringBuilder path = new StringBuilder("file://");
    // Adjust based on current document's location. We need to account for the fact that the current document
    // is stored in subdirectories inside the top level "pages" directory. Since the SX files are also in top
    // subdirectories, we need to compute the path to them.
    path.append(StringUtils.repeat("../", exportContext.getDocParentLevel()));
    path.append(getSxPrefix());
    path.append(URL_PATH_SEPARATOR);
    for (String spaceName : spaceNames) {
        path.append(encodeURLPart(spaceName));
        path.append(URL_PATH_SEPARATOR);
    }
    path.append(encodeURLPart(name));
    path.append(URL_PATH_SEPARATOR);
    path.append(encodeURLPart(targetLocation.getName()));
    return new URL(path.toString());
}
Also used : NameValuePair(org.apache.http.NameValuePair) SxSource(com.xpn.xwiki.web.sx.SxSource) File(java.io.File) SxResourceSource(com.xpn.xwiki.web.sx.SxResourceSource) SxDocumentSource(com.xpn.xwiki.web.sx.SxDocumentSource) URL(java.net.URL)

Example 93 with NameValuePair

use of org.apache.http.NameValuePair in project incubator-gobblin by apache.

the class SalesforceConnector method getAuthentication.

@Override
public HttpEntity getAuthentication() throws RestApiConnectionException {
    log.debug("Authenticating salesforce");
    String clientId = this.state.getProp(ConfigurationKeys.SOURCE_CONN_CLIENT_ID);
    String clientSecret = this.state.getProp(ConfigurationKeys.SOURCE_CONN_CLIENT_SECRET);
    String host = this.state.getProp(ConfigurationKeys.SOURCE_CONN_HOST_NAME);
    List<NameValuePair> formParams = Lists.newArrayList();
    formParams.add(new BasicNameValuePair("client_id", clientId));
    formParams.add(new BasicNameValuePair("client_secret", clientSecret));
    if (refreshToken == null) {
        log.info("Authenticating salesforce with username/password");
        String userName = this.state.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME);
        String password = PasswordManager.getInstance(this.state).readPassword(this.state.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD));
        String securityToken = this.state.getProp(ConfigurationKeys.SOURCE_CONN_SECURITY_TOKEN);
        formParams.add(new BasicNameValuePair("grant_type", "password"));
        formParams.add(new BasicNameValuePair("username", userName));
        formParams.add(new BasicNameValuePair("password", password + securityToken));
    } else {
        log.info("Authenticating salesforce with refresh_token");
        formParams.add(new BasicNameValuePair("grant_type", "refresh_token"));
        formParams.add(new BasicNameValuePair("refresh_token", refreshToken));
    }
    try {
        HttpPost post = new HttpPost(host + DEFAULT_AUTH_TOKEN_PATH);
        post.setEntity(new UrlEncodedFormEntity(formParams));
        HttpResponse httpResponse = getHttpClient().execute(post);
        HttpEntity httpEntity = httpResponse.getEntity();
        return httpEntity;
    } catch (Exception e) {
        throw new RestApiConnectionException("Failed to authenticate salesforce host:" + host + "; error-" + e.getMessage(), e);
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) RestApiConnectionException(org.apache.gobblin.source.extractor.exception.RestApiConnectionException) RestApiConnectionException(org.apache.gobblin.source.extractor.exception.RestApiConnectionException)

Example 94 with NameValuePair

use of org.apache.http.NameValuePair in project incubator-gobblin by apache.

the class SalesforceExtractor method getSoqlUrl.

public static String getSoqlUrl(String soqlQuery) throws RestApiClientException {
    String path = SOQL_RESOURCE + "/";
    NameValuePair pair = new BasicNameValuePair("q", soqlQuery);
    List<NameValuePair> qparams = new ArrayList<>();
    qparams.add(pair);
    return buildUrl(path, qparams);
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 95 with NameValuePair

use of org.apache.http.NameValuePair in project iaf by ibissource.

the class HttpSender method getPostMethodWithParamsInBody.

protected HttpPost getPostMethodWithParamsInBody(URIBuilder uri, String message, ParameterValueList parameters, Map<String, String> headersParamsMap, IPipeLineSession session) throws SenderException {
    try {
        HttpPost hmethod = new HttpPost(uri.build());
        if (!isMultipart() && StringUtils.isEmpty(getMultipartXmlSessionKey())) {
            List<NameValuePair> Parameters = new ArrayList<NameValuePair>();
            if (StringUtils.isNotEmpty(getInputMessageParam())) {
                Parameters.add(new BasicNameValuePair(getInputMessageParam(), message));
                log.debug(getLogPrefix() + "appended parameter [" + getInputMessageParam() + "] with value [" + message + "]");
            }
            if (parameters != null) {
                for (int i = 0; i < parameters.size(); i++) {
                    ParameterValue pv = parameters.getParameterValue(i);
                    String name = pv.getDefinition().getName();
                    String value = pv.asStringValue("");
                    if (headersParamsMap.keySet().contains(name)) {
                        hmethod.addHeader(name, value);
                        if (log.isDebugEnabled())
                            log.debug(getLogPrefix() + "appended header [" + name + "] with value [" + value + "]");
                    } else {
                        Parameters.add(new BasicNameValuePair(name, value));
                        if (log.isDebugEnabled())
                            log.debug(getLogPrefix() + "appended parameter [" + name + "] with value [" + value + "]");
                    }
                }
            }
            try {
                hmethod.setEntity(new UrlEncodedFormEntity(Parameters));
            } catch (UnsupportedEncodingException e) {
                throw new SenderException(getLogPrefix() + "unsupported encoding for one or more post parameters");
            }
        } else {
            HttpEntity requestEntity = createMultiPartEntity(message, parameters, session);
            hmethod.setEntity(requestEntity);
        }
        return hmethod;
    } catch (URISyntaxException e) {
        throw new SenderException(getLogPrefix() + "cannot find path from url [" + getUrl() + "]", e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) HttpEntity(org.apache.http.HttpEntity) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) URISyntaxException(java.net.URISyntaxException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

NameValuePair (org.apache.http.NameValuePair)713 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)592 ArrayList (java.util.ArrayList)478 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)256 HttpPost (org.apache.http.client.methods.HttpPost)218 HttpResponse (org.apache.http.HttpResponse)150 IOException (java.io.IOException)125 HttpEntity (org.apache.http.HttpEntity)108 Test (org.junit.Test)85 URI (java.net.URI)79 Map (java.util.Map)72 HashMap (java.util.HashMap)68 HttpGet (org.apache.http.client.methods.HttpGet)66 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)59 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)55 URISyntaxException (java.net.URISyntaxException)52 Document (org.jsoup.nodes.Document)51 URIBuilder (org.apache.http.client.utils.URIBuilder)50 HttpClient (org.apache.http.client.HttpClient)46