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);
}
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());
}
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);
}
}
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);
}
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);
}
}
Aggregations