Java Code Examples for org.apache.http.client.utils.URLEncodedUtils

The following examples show how to use org.apache.http.client.utils.URLEncodedUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-platform   Source File: QQOauthPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String getAccessToken(String code) {
	Assert.hasText(code);
	Map<String, Object> parameterMap = new HashMap<>();
	parameterMap.put("grant_type", "authorization_code");
	parameterMap.put("client_id", getClientId());
	parameterMap.put("client_secret", getClientSecret());
	parameterMap.put("code", code);
	parameterMap.put("redirect_uri", getRedirectUri());
	String responseString = get("https://graph.qq.com/oauth2.0/token", parameterMap);

	List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(responseString, Charset.forName("utf-8"));
	Map<String, Object> result = new HashMap<>();
	for (NameValuePair nameValuePair : nameValuePairs) {
		result.put(nameValuePair.getName(), nameValuePair.getValue());
	}

	return getParameter(nameValuePairs, "access_token");
}
 
Example 2
Source Project: anyline   Source File: HttpUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static HttpResult get(CloseableHttpClient client, Map<String, String> headers, String url, String encode, List<NameValuePair> pairs) { 
	if(null == client){ 
		if(url.contains("https://")){ 
			client = defaultSSLClient(); 
		}else{ 
			client =  defaultClient(); 
		} 
	} 
	if(url.startsWith("//")){ 
		url = "http:" + url; 
	} 
	HttpResult result = new HttpResult(); 
	if (null != pairs && !pairs.isEmpty()) { 
		String params = URLEncodedUtils.format(pairs,encode); 
		if (url.contains("?")) { 
			url += "&" + params; 
		} else { 
			url += "?" + params; 
		} 
	} 
	HttpGet method = new HttpGet(url); 
	setHeader(method, headers); 
	result = exe(client, method, encode); 
	return result; 
}
 
Example 3
Source Project: anyline   Source File: HttpUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static HttpResult delete(CloseableHttpClient client, Map<String, String> headers, String url, String encode, List<NameValuePair> pairs) { 
	if(null == client){ 
		if(url.contains("https://")){ 
			client = defaultSSLClient(); 
		}else{
			client =  defaultClient(); 
		} 
	} 
	if(url.startsWith("//")){ 
		url = "http:" + url; 
	} 
	HttpResult result = new HttpResult(); 
	if (null != pairs) { 
		String params = URLEncodedUtils.format(pairs,encode); 
		if (url.contains("?")) { 
			url += "&" + params; 
		} else { 
			url += "?" + params; 
		} 
	} 
	HttpDelete method = new HttpDelete(url); 
	setHeader(method, headers); 
	result = exe(client, method, encode); 
	return result; 
}
 
Example 4
Source Project: AuTe-Framework   Source File: UrlParametersExtractor.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public Map<String, Object> extractQueryParameters(URL url) {
  if (url == null) {
    return Collections.emptyMap();
  }
  List<NameValuePair> parameters = URLEncodedUtils.parse(url.getQuery(), StandardCharsets.UTF_8);
  Map<String, Object> result = new LinkedHashMap<>();
  for (NameValuePair parameter : parameters) {
    if (result.containsKey(parameter.getName())) {
      Object currentValue = result.get(parameter.getName());
      if (currentValue instanceof List) {
        ((List) currentValue).add(parameter.getValue());
      } else {
        List<Object> values = new ArrayList<>();
        values.add(currentValue);
        values.add(parameter.getValue());
        result.put(parameter.getName(), values);
      }
    } else {
      result.put(parameter.getName(), parameter.getValue());
    }
  }
  return result;
}
 
Example 5
Source Project: dr-elephant   Source File: Application.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parses the request for the queryString
 *
 * @return URL Encoded String of Parameter Value Pair
 */
public static String getQueryString() {
  List<BasicNameValuePair> fields = new LinkedList<BasicNameValuePair>();
  final Set<Map.Entry<String, String[]>> entries = request().queryString().entrySet();
  for (Map.Entry<String, String[]> entry : entries) {
    final String key = entry.getKey();
    final String value = entry.getValue()[0];
    if (!key.equals(PAGE)) {
      fields.add(new BasicNameValuePair(key, value));
    }
  }
  if (fields.isEmpty()) {
    return null;
  } else {
    return URLEncodedUtils.format(fields, "utf-8");
  }
}
 
Example 6
Source Project: webapp-hardware-bridge   Source File: BridgeWebSocketServer.java    License: MIT License 6 votes vote down vote up
@Override
public void onOpen(WebSocket connection, ClientHandshake handshake) {
    try {
        String descriptor = handshake.getResourceDescriptor();

        URI uri = new URI(descriptor);
        String channel = uri.getPath();
        List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
        String token = getToken(params);

        if (settingService.getSetting().getAuthenticationEnabled() && (token == null || !token.equals(settingService.getSetting().getAuthenticationToken()))) {
            connection.close(CloseFrame.REFUSE, "Token Mismatch");
            return;
        }

        connection.setAttachment(new ConnectionAttachment(channel, params, token));
        addSocketToChannel(channel, connection);

        logger.info(connection.getRemoteSocketAddress().toString() + " connected to " + channel);
    } catch (URISyntaxException e) {
        logger.error(connection.getRemoteSocketAddress().toString() + " error", e);
        connection.close();
    }
}
 
Example 7
Source Project: common-project   Source File: HttpUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static Map<String, String> paraseURI(String uri) {
    try {
        if (!uri.startsWith("?")) {
            uri = "?".concat(uri);
        }
        HashMap<String, String> map = new HashMap<String, String>();
        List<NameValuePair> parse = URLEncodedUtils.parse(new URI(uri), CHARSET_NAME);
        for (NameValuePair nameValuePair : parse) {
            map.put(nameValuePair.getName(), nameValuePair.getValue());
        }
        return map;
    } catch (Exception e) {
        logger.error("parase uri error", e);
    }
    return null;
}
 
Example 8
Source Project: harbor-java-client   Source File: HarborClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Let user see the recent operation logs of the projects which he is member
 * of.</br>
 * <b>URL</b>: /logs</br>
 * <b>Method</b>: GET
 *
 * @param lines
 *            (The number of logs to be shown, default is 10 if lines,
 *            start_time, end_time are not provided)
 * @param startTime
 *            (The start time of logs to be shown in unix timestap)
 * @param endTime
 *            (The end time of logs to be shown in unix timestap)
 * @return required logs.
 * @throws IOException
 * @throws HarborClientException
 */
public List<Log> getLogs(String lines, String startTime, String endTime) throws IOException, HarborClientException {
	logger.debug("get logs lines %s, start time %s, end time %s", lines, startTime, endTime);
	List<NameValuePair> qparams = new ArrayList<>();
	qparams.add(new BasicNameValuePair("lines", lines));
	qparams.add(new BasicNameValuePair("start_time", startTime));
	qparams.add(new BasicNameValuePair("end_time", endTime));
	qparams.removeIf(o -> Objects.isNull(o.getValue()));
	String url = getBaseUrl() + "/logs?" + URLEncodedUtils.format(qparams, "UTF-8");
	Request request = new Request.Builder().url(url).get().build();
	Response response = okhttpClient.newCall(request).execute();
	logger.debug(String.format(REQUEST_RESPONSE_INFO, request, response));
	if (response.code() != 200) {
		throw new HarborClientException(String.valueOf(response.code()), response.message());
	}
	return mapper.readValue(response.body().string(), new TypeReference<List<Log>>() {
	});
}
 
Example 9
Source Project: kyoko   Source File: NicoAudioTrack.java    License: MIT License 6 votes vote down vote up
private String loadPlaybackUrl(HttpInterface httpInterface) throws IOException {
    HttpGet request = new HttpGet("http://flapi.nicovideo.jp/api/getflv/" + trackInfo.identifier);

    try (CloseableHttpResponse response = httpInterface.execute(request)) {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            throw new IOException("Unexpected status code from playback parameters page: " + statusCode);
        }

        String text = EntityUtils.toString(response.getEntity());
        Map<String, String> format = convertToMapLayout(URLEncodedUtils.parse(text, StandardCharsets.UTF_8));

        String url = format.get("url");
        try (CloseableHttpResponse testResponse = httpInterface.execute(new HttpGet(url))) {
            int testStatusCode = testResponse.getStatusLine().getStatusCode();
            if (testStatusCode != 200) {
                url = url.replace("/smile?v=", "/smile?m=");
                url += "low";
            }
        }
        return url;
    }
}
 
Example 10
private Map<String, String> decodeExtras(String extras) {
    Map<String, String> results = new HashMap<String, String>();
    try {
        URI rawExtras = new URI("?" + extras);
        List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8");
        for (NameValuePair item : extraList) {
            String name = item.getName();
            int i = 0;
            while (results.containsKey(name)) {
                name = item.getName() + ++i;
            }
            results.put(name, item.getValue());
        }
    } catch (URISyntaxException e) {
        Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
    }
    return results;
}
 
Example 11
private String genAddressWithoutSchema(String addressWithoutSchema, Map<String, String> pairs) {
  if (addressWithoutSchema == null || pairs == null || pairs.isEmpty()) {
    return addressWithoutSchema;
  }

  int idx = addressWithoutSchema.indexOf('?');
  if (idx == -1) {
    addressWithoutSchema += "?";
  } else {
    addressWithoutSchema += "&";
  }

  String encodedQuery = URLEncodedUtils.format(pairs.entrySet().stream().map(entry -> {
    return new BasicNameValuePair(entry.getKey(), entry.getValue());
  }).collect(Collectors.toList()), StandardCharsets.UTF_8.name());

  addressWithoutSchema += encodedQuery;

  return addressWithoutSchema;
}
 
Example 12
Source Project: smockin   Source File: GeneralUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Map<String, String> extractAllRequestParams(final Request req) {

        final Map<String, String> allParams = req.queryMap()
                .toMap()
                .entrySet()
                .stream()
                .collect(HashMap::new,
                        (m,v) ->
                            m.put(v.getKey(), (v.getValue() != null && v.getValue().length != 0) ? v.getValue()[0] : null),
                        HashMap::putAll);

        if (req.contentType() != null
            && (req.contentType().contains(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
            ||  req.contentType().contains(MediaType.MULTIPART_FORM_DATA_VALUE))) {

            if (req.body() != null) {
                allParams.putAll(URLEncodedUtils.parse(req.body(), Charset.defaultCharset())
                                    .stream()
                                    .collect(HashMap::new, (m,v) -> m.put(v.getName(), v.getValue()), HashMap::putAll));
            }
        }

        return allParams;
    }
 
Example 13
Source Project: smockin   Source File: JavaScriptResponseHandlerImpl.java    License: Apache License 2.0 6 votes vote down vote up
Map<String, String> extractAllRequestParams(final Request req) {

        // Java Spark does not provide a convenient way of extracting form based request parameters,
        // so have to parse these manually.
        if (req.contentType() != null
                && (req.contentType().contains(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
                ||  req.contentType().contains(MediaType.MULTIPART_FORM_DATA_VALUE))) {

            return URLEncodedUtils.parse(req.body(), Charset.defaultCharset())
                    .stream()
                    .collect(HashMap::new, (m, v) -> m.put(v.getName(), v.getValue()), HashMap::putAll);
        }

        return req.queryParams()
                .stream()
                .collect(Collectors.toMap(k -> k, k -> req.queryParams(k)));
    }
 
Example 14
Source Project: Cognizant-Intelligent-Test-Scripter   Source File: Entry.java    License: Apache License 2.0 6 votes vote down vote up
public JSONArray getParams(ResourceTimings e) {
    JSONArray paramList = new JSONArray();
    try {
        List<NameValuePair> params = URLEncodedUtils.parse(new URI(e.name), "UTF-8");
        for (NameValuePair pair : params) {
            JSONObject jsonPair = new JSONObject();
            jsonPair.put("name", pair.getName());
            jsonPair.put("value", pair.getValue());
            paramList.add(jsonPair);
        }

    } catch (Exception ex) {
        return paramList;
    }
    return paramList;
}
 
Example 15
Source Project: Shour   Source File: HttpUtil.java    License: MIT License 6 votes vote down vote up
private static HttpGet buildGet(String url, Map<String, String> params) {
    StringBuilder sb = new StringBuilder(url);
    if (params != null && params.size() > 0) {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        Iterator iterator = params.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = (Map.Entry) iterator.next();
            nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
        sb.append("?");
        sb.append(URLEncodedUtils.format(nameValuePairs, DEFAULT_CHARSET));
    }
    HttpGet httpGet = new HttpGet(sb.toString());
    httpGet.setHeader("Accept-Encoding", "");
    return httpGet;
}
 
Example 16
private Map<String, String> decodeExtras(String extras) {
    Map<String, String> results = new HashMap<String, String>();
    try {
        URI rawExtras = new URI("?" + extras);
        List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8");
        for (NameValuePair item : extraList) {
            String name = item.getName();
            int i = 0;
            while (results.containsKey(name)) {
                name = item.getName() + ++i;
            }
            results.put(name, item.getValue());
        }
    } catch (URISyntaxException e) {
        Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
    }
    return results;
}
 
Example 17
Source Project: WePush   Source File: HwYunMsgSender.java    License: MIT License 6 votes vote down vote up
/**
 * 构造请求Body体
 *
 * @param sender
 * @param receiver
 * @param templateId
 * @param templateParas
 * @param statusCallbackUrl
 * @param signature         | 签名名称,使用国内短信通用模板时填写
 * @return
 */
static String buildRequestBody(String sender, String receiver, String templateId, String templateParas,
                               String statusCallbackUrl, String signature) {
    if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty()
            || templateId.isEmpty()) {
        System.out.println("buildRequestBody(): sender, receiver or templateId is null.");
        return null;
    }
    List<NameValuePair> keyValues = new ArrayList<>();

    keyValues.add(new BasicNameValuePair("from", sender));
    keyValues.add(new BasicNameValuePair("to", receiver));
    keyValues.add(new BasicNameValuePair("templateId", templateId));
    if (null != templateParas && !templateParas.isEmpty()) {
        keyValues.add(new BasicNameValuePair("templateParas", templateParas));
    }
    if (null != statusCallbackUrl && !statusCallbackUrl.isEmpty()) {
        keyValues.add(new BasicNameValuePair("statusCallback", statusCallbackUrl));
    }
    if (null != signature && !signature.isEmpty()) {
        keyValues.add(new BasicNameValuePair("signature", signature));
    }

    return URLEncodedUtils.format(keyValues, Charset.forName("UTF-8"));
}
 
Example 18
Source Project: q   Source File: SolrSearcher.java    License: Apache License 2.0 6 votes vote down vote up
public String getUrlForGettingDoc(String q, List<String> languages, String dataSetId)
{
	List<NameValuePair> parameters = Lists.newArrayList();

	parameters.add(new BasicNameValuePair("q", getPhraseQueryString(q)));
	parameters.add(new BasicNameValuePair("defType", "edismax"));
	parameters.add(new BasicNameValuePair("lowercaseOperators", "false"));
	parameters.add(new BasicNameValuePair("rows", "100000"));
	parameters.add(new BasicNameValuePair("qs", "10"));
	parameters.add(new BasicNameValuePair("fl", Properties.idField.get() + ", " + Properties.titleFields.get().get(0) + "_en"));
	parameters.add(new BasicNameValuePair("sort", Properties.idField.get() + " DESC"));
	parameters.add(new BasicNameValuePair("qf", getQueryFields(languages)));
	parameters.add(new BasicNameValuePair("fq", Properties.docTypeFieldName.get() + ":" + dataSetId));
	parameters.add(new BasicNameValuePair("wt", "json"));

	return getServerUrl() + "/select?" + URLEncodedUtils.format(parameters, BaseIndexer.ENCODING);
}
 
Example 19
Source Project: bobcat   Source File: RequestPredicateImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean accepts(HttpRequest request) {
  boolean result = false;
  URI uri = URI.create(request.getUri());
  String path = uri.getPath();
  if (path != null && path.startsWith(urlPrefix)) {
    String query = uri.getQuery();
    if (expectedParams.isEmpty() && StringUtils.isEmpty(query)) {
      result = true;
    } else if (StringUtils.isNotEmpty(query)) {
      List<NameValuePair> params = URLEncodedUtils.parse(query, Charsets.UTF_8);
      result = hasAllExpectedParams(expectedParams, params);
    }
  }
  return result;
}
 
Example 20
Source Project: gitlab-oauth-plugin   Source File: GitLabSecurityRealm.java    License: MIT License 6 votes vote down vote up
public HttpResponse doCommenceLogin(StaplerRequest request, @QueryParameter String from, @Header("Referer") final String referer) throws IOException {
    // 2. Requesting authorization :
    // http://doc.gitlab.com/ce/api/oauth2.html

    String redirectOnFinish;
    if (from != null && Util.isSafeToRedirectTo(from)) {
        redirectOnFinish = from;
    } else if (referer != null && (referer.startsWith(Jenkins.getInstance().getRootUrl()) || Util.isSafeToRedirectTo(referer))) {
        redirectOnFinish = referer;
    } else {
        redirectOnFinish = Jenkins.getInstance().getRootUrl();
    }

    List<NameValuePair> parameters = new ArrayList<>();
    parameters.add(new BasicNameValuePair("redirect_uri", buildRedirectUrl(request, redirectOnFinish)));
    parameters.add(new BasicNameValuePair("response_type", "code"));
    parameters.add(new BasicNameValuePair("client_id", clientID));

    return new HttpRedirect(gitlabWebUri + "/oauth/authorize?" + URLEncodedUtils.format(parameters, StandardCharsets.UTF_8));
}
 
Example 21
private Map<String, String> decodeExtras(String extras) {
    Map<String, String> results = new HashMap<String, String>();
    try {
        URI rawExtras = new URI("?" + extras);
        List<NameValuePair> extraList = URLEncodedUtils.parse(rawExtras, "UTF-8");
        for (NameValuePair item : extraList) {
            String name = item.getName();
            int i = 0;
            while (results.containsKey(name)) {
                name = item.getName() + ++i;
            }
            results.put(name, item.getValue());
        }
    } catch (URISyntaxException e) {
        Log.w(TAG, "Invalid syntax error while decoding extras data from server.");
    }
    return results;
}
 
Example 22
Source Project: xnx3   Source File: HuaweiSMSUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 构造请求Body体
 * @param sender
 * @param receiver
 * @param templateId
 * @param templateParas
 * @param statusCallbackUrl
 * @param signature | 签名名称,使用国内短信通用模板时填写
 * @return
 */
static String buildRequestBody(String sender, String receiver, String templateId, String templateParas,
                               String statusCallbackUrl, String signature) {
    if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty()
            || templateId.isEmpty()) {
        System.out.println("buildRequestBody(): sender, receiver or templateId is null.");
        return null;
    }
    List<NameValuePair> keyValues = new ArrayList<NameValuePair>();

    keyValues.add(new BasicNameValuePair("from", sender));
    keyValues.add(new BasicNameValuePair("to", receiver));
    keyValues.add(new BasicNameValuePair("templateId", templateId));
    if (null != templateParas && !templateParas.isEmpty()) {
        keyValues.add(new BasicNameValuePair("templateParas", templateParas));
    }
    if (null != statusCallbackUrl && !statusCallbackUrl.isEmpty()) {
        keyValues.add(new BasicNameValuePair("statusCallback", statusCallbackUrl));
    }
    if (null != signature && !signature.isEmpty()) {
        keyValues.add(new BasicNameValuePair("signature", signature));
    }

    return URLEncodedUtils.format(keyValues, Charset.forName("UTF-8"));
}
 
Example 23
Source Project: vertx-s3-client   Source File: UrlEncodingUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String addParamsSortedToUrl(String url, Map<String, String> params) {
    checkNotNull(url, "url must not be null");
    checkNotNull(!url.isEmpty(), "url must not be empty");
    checkNotNull(params, "params must not be null");
    checkNotNull(!params.isEmpty(), "params must not be empty");

    final String baseUrl = extractBaseUrl(url);
    final String urlParams = baseUrl.equals(url) ? "" : url.replace(baseUrl + "?", "");
    final List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(urlParams, Charsets.UTF_8);

    for (Map.Entry<String, String> paramToUrlEncode : params.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey)).collect(Collectors.toList())) {
        nameValuePairs.add(new BasicNameValuePair(paramToUrlEncode.getKey(), paramToUrlEncode.getValue()));
    }

    return baseUrl + "?" + URLEncodedUtils.format(nameValuePairs, Charsets.UTF_8);
}
 
Example 24
Source Project: flowable-engine   Source File: CaseModelsResource.java    License: Apache License 2.0 6 votes vote down vote up
@GetMapping(produces = "application/json")
public ResultListDataRepresentation getCaseModels(HttpServletRequest request) {
    // need to parse the filterText parameter ourselves, due to encoding issues with the default parsing.
    String filter = null;
    String excludeId = null;
    List<NameValuePair> params = URLEncodedUtils.parse(request.getQueryString(), Charset.forName("UTF-8"));
    if (params != null) {
        for (NameValuePair nameValuePair : params) {
            if ("filter".equalsIgnoreCase(nameValuePair.getName())) {
                filter = nameValuePair.getValue();
            } else if ("excludeId".equalsIgnoreCase(nameValuePair.getName())) {
                excludeId = nameValuePair.getValue();
            }
        }
    }
    return caseService.getCases(filter, excludeId);
}
 
Example 25
Source Project: cosmic   Source File: UriUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean cifsCredentialsPresent(final URI uri) {
    final List<NameValuePair> args = URLEncodedUtils.parse(uri, "UTF-8");
    boolean foundUser = false;
    boolean foundPswd = false;
    for (final NameValuePair nvp : args) {
        final String name = nvp.getName();
        if (name.equals("user")) {
            foundUser = true;
            s_logger.debug("foundUser is" + foundUser);
        } else if (name.equals("password")) {
            foundPswd = true;
            s_logger.debug("foundPswd is" + foundPswd);
        }
    }
    return (foundUser && foundPswd);
}
 
Example 26
Source Project: java-platform   Source File: GithubOauthPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getAccessToken(String code) {
	Assert.hasText(code);
	Map<String, Object> parameterMap = new HashMap<>();
	parameterMap.put("client_id", getClientId());
	parameterMap.put("client_secret", getClientSecret());
	parameterMap.put("code", code);
	String accessTokenResponse = post("https://github.com/login/oauth/access_token", parameterMap);
	List<NameValuePair> nameValuePairs = URLEncodedUtils.parse(accessTokenResponse, Charset.forName("utf-8"));
	Map<String, Object> result = new HashMap<>();
	for (NameValuePair nameValuePair : nameValuePairs) {
		result.put(nameValuePair.getName(), nameValuePair.getValue());
	}
	return getParameter(nameValuePairs, "access_token");
}
 
Example 27
Source Project: Bats   Source File: RecoverableRpcProxy.java    License: Apache License 2.0 5 votes vote down vote up
private long connect(long timeMillis) throws IOException
{
  String uriStr = fsRecoveryHandler.readConnectUri();
  if (!uriStr.equals(lastConnectURI)) {
    LOG.debug("Got new RPC connect address {}", uriStr);
    lastConnectURI = uriStr;
    if (umbilical != null) {
      RPC.stopProxy(umbilical);
    }

    retryTimeoutMillis = Long.getLong(RETRY_TIMEOUT, RETRY_TIMEOUT_DEFAULT);
    retryDelayMillis = Long.getLong(RETRY_DELAY, RETRY_DELAY_DEFAULT);
    rpcTimeout = Integer.getInteger(RPC_TIMEOUT, RPC_TIMEOUT_DEFAULT);

    URI heartbeatUri = URI.create(uriStr);

    String queryStr = heartbeatUri.getQuery();
    if (queryStr != null) {
      List<NameValuePair> queryList = URLEncodedUtils.parse(queryStr, Charset.defaultCharset());
      if (queryList != null) {
        for (NameValuePair pair : queryList) {
          String value = pair.getValue();
          String key = pair.getName();
          if (QP_rpcTimeout.equals(key)) {
            this.rpcTimeout = Integer.parseInt(value);
          } else if (QP_retryTimeoutMillis.equals(key)) {
            this.retryTimeoutMillis = Long.parseLong(value);
          } else if (QP_retryDelayMillis.equals(key)) {
            this.retryDelayMillis = Long.parseLong(value);
          }
        }
      }
    }
    InetSocketAddress address = NetUtils.createSocketAddrForHost(heartbeatUri.getHost(), heartbeatUri.getPort());
    umbilical = RPC.getProxy(StreamingContainerUmbilicalProtocol.class, StreamingContainerUmbilicalProtocol.versionID, address, currentUser, conf, defaultSocketFactory, rpcTimeout);
    // reset timeout
    return System.currentTimeMillis() + retryTimeoutMillis;
  }
  return timeMillis;
}
 
Example 28
protected Map<String, String> loadTrackArgsFromVideoInfoPage(HttpInterface httpInterface, String videoId, String sts) throws IOException {
  String videoApiUrl = "https://youtube.googleapis.com/v/" + videoId;
  String encodedApiUrl = URLEncoder.encode(videoApiUrl, UTF_8.name());
  String url = "https://www.youtube.com/get_video_info?video_id=" + videoId + "&eurl=" + encodedApiUrl +
          "hl=en_GB";

  if (sts != null) {
    url += "&sts=" + sts;
  }

  try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(url))) {
    HttpClientTools.assertSuccessWithContent(response, "video info response");
    return convertToMapLayout(URLEncodedUtils.parse(response.getEntity()));
  }
}
 
Example 29
Source Project: charging_pile_cloud   Source File: HttpClientUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 封装HTTP GET方法
 *
 * @param
 * @param
 * @return
 */
public static String get(String url, Map<String, String> paramMap)
        throws ClientProtocolException, IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet();
    List<NameValuePair> formparams = setHttpParams(paramMap);
    String param = URLEncodedUtils.format(formparams, "UTF-8");
    httpGet.setURI(URI.create(url + "?" + param));
    HttpResponse response = httpClient.execute(httpGet);
    String httpEntityContent = getHttpEntityContent(response);
    httpGet.abort();
    return httpEntityContent;
}
 
Example 30
Source Project: charging_pile_cloud   Source File: HttpClientUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 封装HTTP DELETE方法
 *
 * @param
 * @param
 * @return
 */
public static String delete(String url, Map<String, String> paramMap)
        throws ClientProtocolException, IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpDelete httpDelete = new HttpDelete();
    List<NameValuePair> formparams = setHttpParams(paramMap);
    String param = URLEncodedUtils.format(formparams, "UTF-8");
    httpDelete.setURI(URI.create(url + "?" + param));
    HttpResponse response = httpClient.execute(httpDelete);
    String httpEntityContent = getHttpEntityContent(response);
    httpDelete.abort();
    return httpEntityContent;
}