org.apache.http.NameValuePair#getName ( )源码实例Demo

下面列出了org.apache.http.NameValuePair#getName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hop   文件: HttpPost.java
@VisibleForTesting
String getRequestBodyParamsAsStr( NameValuePair[] pairs, String charset ) throws HopException {
  StringBuffer buf = new StringBuffer();
  try {
    for ( int i = 0; i < pairs.length; ++i ) {
      NameValuePair pair = pairs[ i ];
      if ( pair.getName() != null ) {
        if ( i > 0 ) {
          buf.append( "&" );
        }

        buf.append( URLEncoder.encode( pair.getName(), !StringUtil.isEmpty( charset ) ? charset : DEFAULT_ENCODING ) );
        buf.append( "=" );
        if ( pair.getValue() != null ) {
          buf.append( URLEncoder.encode( pair.getValue(), !StringUtil.isEmpty( charset ) ? charset : DEFAULT_ENCODING ) );
        }
      }
    }
    return buf.toString();
  } catch ( UnsupportedEncodingException e ) {
    throw new HopException( e.getMessage(), e.getCause() );
  }
}
 
源代码2 项目: text_converter   文件: APKExpansionPolicy.java
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;
}
 
源代码3 项目: iGap-Android   文件: APKExpansionPolicy.java
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;
}
 
源代码4 项目: vpn-over-dns   文件: APKExpansionPolicy.java
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;
}
 
源代码5 项目: cosmic   文件: UriUtils.java
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);
}
 
源代码6 项目: patreon-java   文件: PatreonAPI.java
public String getNextCursorFromDocument(JSONAPIDocument document) {
  Links links = document.getLinks();
  if (links == null) {
    return null;
  }
  Link nextLink = links.getNext();
  if (nextLink == null) {
    return null;
  }
  String nextLinkString = nextLink.toString();
  try {
    List<NameValuePair> queryParameters = URLEncodedUtils.parse(new URI(nextLinkString), "utf8");
    for (NameValuePair pair : queryParameters) {
      String name = pair.getName();
      if (name.equals("page[cursor]")) {
        return pair.getValue();
      }
    }
  } catch (URISyntaxException e) {
    LOG.error(e.getMessage());
  }
  return null;
}
 
源代码7 项目: travelguide   文件: APKExpansionPolicy.java
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;
}
 
源代码8 项目: Alite   文件: APKExpansionPolicy.java
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;
}
 
源代码9 项目: Klyph   文件: APKExpansionPolicy.java
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;
}
 
源代码10 项目: Bats   文件: RecoverableRpcProxy.java
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;
}
 
源代码11 项目: cosmic   文件: NfsSecondaryStorageResource.java
protected String parseCifsMountOptions(final URI uri) {
    final List<NameValuePair> args = URLEncodedUtils.parse(uri, "UTF-8");
    boolean foundUser = false;
    boolean foundPswd = false;
    final StringBuilder extraOpts = new StringBuilder();
    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("password is present in uri");
        }

        extraOpts.append(name + "=" + nvp.getValue() + ",");
    }

    if (s_logger.isDebugEnabled()) {
        s_logger.error("extraOpts now " + extraOpts);
    }

    if (!foundUser || !foundPswd) {
        final String errMsg =
                "Missing user and password from URI. Make sure they" + "are in the query string and separated by '&'.  E.g. "
                        + "cifs://example.com/some_share?user=foo&password=bar";
        s_logger.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    return extraOpts.toString();
}
 
源代码12 项目: dr-elephant   文件: AzkabanWorkflowClient.java
/**
 * Sets the workflow execution id given the azkaban workflow url
 * @param azkabanWorkflowUrl The url of the azkaban workflow
 * @throws MalformedURLException
 * @throws URISyntaxException
 */
private void setExecutionId(String azkabanWorkflowUrl)
    throws MalformedURLException, URISyntaxException {
  List<NameValuePair> params = URLEncodedUtils.parse(new URI(azkabanWorkflowUrl), "UTF-8");
  for (NameValuePair param : params) {
    if (param.getName() == "execid") {
      this._executionId = param.getValue();
    }
  }
}
 
源代码13 项目: attic-apex-core   文件: RecoverableRpcProxy.java
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;
}
 
public String parametersAsQueryString() {
    String s = "";
    for (Iterator<NameValuePair> i = this.params.iterator(); i.hasNext(); ) {
        NameValuePair nv = i.next();
        s += "&" + nv.getName() + "=" + nv.getValue();
    }
    if (s.length() > 0) {
        return "?" + s.substring(1);
    }
    return s;
}
 
源代码15 项目: navex   文件: NavigationDatabaseNode.java
@Override
public Map<String, Object> createProperties() {
	Map<String, Object> properties = new HashMap<String, Object>();
	if (node != null)
	{
		int docid = this.docid;//node.getWebURL().getDocid();
		properties.put(NodeKeys.ID, docid);

		String url = this.url;//node.getWebURL().getURL();
		if (url != null)
			properties.put(NodeKeys.URL, url);

		String domain = this.domain;//node.get()
		if (domain != null)
			properties.put(NodeKeys.DOMAIN, domain);

		String path = this.path;//node.getWebURL().getPath();
		if (path != null)
			properties.put(NodeKeys.PATH, path);

		String parentUrl = this.parent;//node.getWebURL().getParentUrl();
		if (parentUrl != null)
			properties.put(NodeKeys.PARENT, parentUrl);

		if (data != null){
			int links = data.getOutgoingUrls().size();
			properties.put(NodeKeys.LINKS, links);

			int forms = data.getForms().size();
			properties.put(NodeKeys.FORMS, forms);
		}

		List<NameValuePair> p = this.params;//node.get()
		if (p != null){
			String str="";
			for (NameValuePair pair : p)
			{
				str+=pair.getName()+"="+pair.getValue()+",";
			}

			properties.put(NodeKeys.PARAMS, str);
		}

		if (CrawlConfig.getRole() != null)
			properties.put(NodeKeys.ROLE, CrawlConfig.getRole());


	}

	return properties;
}
 
源代码16 项目: sofa-lookout   文件: MetricsHttpExporter.java
@Override
public void handle(HttpExchange exchange)
                                         throws IOException {
    try {
        if (!isAccessAllowed(exchange)) {
            sendErrResponse(exchange, 403,
                "Forbidden");
            return;
        }

        // 解析参数
        Set<Long> success = Collections.emptySet();
        long newStep = controller.getStep();
        int newSlotCount = controller.getSlotCount();

        try {
            for (NameValuePair nvp : parseParams(exchange)) {
                String name = nvp.getName();
                String value = nvp.getValue();
                if ("step".equalsIgnoreCase(name)) {
                    newStep = Long.parseLong(value);
                } else if ("slotCount"
                    .equalsIgnoreCase(name)) {
                    newSlotCount = Integer
                        .parseInt(value);
                } else if ("success"
                    .equalsIgnoreCase(name)) {
                    success = parseCursors(value);
                }
            }
        } catch (NumberFormatException nfe) {
            sendErrResponse(exchange, 400,
                nfe.getMessage());
            return;
        }

        Object data = controller
            .getNextData(success);

        JSONObject bodyEntity = new JSONObject();
        // 这里返回newStep给用户 表明我们已经接受了用户修改的step
        bodyEntity.put("step", newStep);
        bodyEntity.put("slotCount", newSlotCount);
        bodyEntity.put("data", data);
        sendResponse(exchange, bodyEntity);

        controller.update(newStep, newSlotCount);

        // if (oldRate != newStep || oldSlotCount != newSlotCount) {
        // }
    } catch (Throwable e) {
        logger.warn("pull metrics failed."
                    + e.getMessage());
    } finally {
        exchange.close();
    }
}
 
源代码17 项目: sndml3   文件: Parameters.java
public Parameters(List<NameValuePair> list) {
	super();
	for (NameValuePair nvp : list) {
		super.put(nvp.getName(), nvp.getValue());
	}
}
 
源代码18 项目: sndml3   文件: Parameters.java
public void add(NameValuePair nvp) {
	super.put(nvp.getName(), nvp.getValue());
}
 
源代码19 项目: openvidu   文件: ComposedRecordingService.java
private String processCustomLayoutUrlFormat(URL url, String shortSessionId) {
	String finalUrl = url.getProtocol() + "://" + url.getAuthority();
	if (!url.getPath().isEmpty()) {
		finalUrl += url.getPath();
	}
	finalUrl = finalUrl.endsWith("/") ? finalUrl.substring(0, finalUrl.length() - 1) : finalUrl;
	if (url.getQuery() != null) {
		URI uri;
		try {
			uri = url.toURI();
			finalUrl += "?";
		} catch (URISyntaxException e) {
			String error = "\"customLayout\" property has URL format and query params (" + url.toString()
					+ "), but does not comply with RFC2396 URI format";
			log.error(error);
			throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, error);
		}
		List<NameValuePair> params = URLEncodedUtils.parse(uri, Charset.forName("UTF-8"));
		Iterator<NameValuePair> it = params.iterator();
		boolean hasSessionId = false;
		boolean hasSecret = false;
		while (it.hasNext()) {
			NameValuePair param = it.next();
			finalUrl += param.getName() + "=" + param.getValue();
			if (it.hasNext()) {
				finalUrl += "&";
			}
			if (!hasSessionId) {
				hasSessionId = param.getName().equals("sessionId");
			}
			if (!hasSecret) {
				hasSecret = param.getName().equals("secret");
			}
		}
		if (!hasSessionId) {
			finalUrl += "&sessionId=" + shortSessionId;
		}
		if (!hasSecret) {
			finalUrl += "&secret=" + openviduConfig.getOpenViduSecret();
		}
	}

	if (url.getRef() != null) {
		finalUrl += "#" + url.getRef();
	}

	return finalUrl;
}
 
源代码20 项目: r2m-plugin-android   文件: UrlParser.java
public static ParsedUrl parseUrl(String url) {
    List<PathPart> pathParts = new ArrayList<PathPart>();
    List<Query> queries = new ArrayList<Query>();
    ParsedUrl parsedUrl;
    String base;

    try {
        URL aURL = new URL(url);
        base = aURL.getAuthority();
        String protocol = aURL.getProtocol();
        parsedUrl = new ParsedUrl();
        parsedUrl.setPathWithEndingSlash(aURL.getPath().endsWith("/"));
        parsedUrl.setBaseUrl(protocol + "://" + base);
        List<NameValuePair> pairs = URLEncodedUtils.parse(aURL.getQuery(),
                Charset.defaultCharset());
        for (NameValuePair pair : pairs) {
            Query query = new Query(pair.getName(), pair.getValue());
            queries.add(query);
        }
        parsedUrl.setQueries(queries);

        String[] pathStrings = aURL.getPath().split("/");
        for (String pathPart : pathStrings) {
          Matcher m = PATH_PARAM_PATTERN.matcher(pathPart);
          if (m.find()) {
            String paramDef = m.group(1);
            String[] paramParts = paramDef.split(":");
            if (paramParts.length > 1) {
              pathParts.add(new PathPart(paramParts[1].trim(), paramParts[0].trim()));
            } else {
              pathParts.add(new PathPart(paramParts[0].trim()));
            }
          } else {
            if(!pathPart.isEmpty()) {
              pathParts.add(new PathPart(pathPart));
            }
          }
        }
        parsedUrl.setPathParts(pathParts);
    } catch (Exception ex) {
        Logger.error(UrlParser.class, R2MMessages.getMessage("CANNOT_PARSE_URL", url));
        return null;
    }
    return parsedUrl;
}
 
 同类方法