Java Code Examples for org.apache.http.NameValuePair#getValue()
The following examples show how to use
org.apache.http.NameValuePair#getValue() .
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 File: HttpWorker.java From IGUANA with GNU Affero General Public License v3.0 | 6 votes |
public static String getContentTypeVal(Header header) { System.out.println("[DEBUG] HEADER: " + header); for (HeaderElement el : header.getElements()) { NameValuePair cTypePair = el.getParameterByName("Content-Type"); if (cTypePair != null && !cTypePair.getValue().isEmpty()) { return cTypePair.getValue(); } } int index = header.toString().indexOf("Content-Type"); if (index >= 0) { String ret = header.toString().substring(index + "Content-Type".length() + 1); if (ret.contains(";")) { return ret.substring(0, ret.indexOf(";")).trim(); } return ret.trim(); } return "application/sparql-results+json"; }
Example 2
Source File: HttpClient.java From hsac-fitnesse-fixtures with Apache License 2.0 | 6 votes |
protected String getAttachmentFileName(org.apache.http.HttpResponse resp) { String fileName = null; Header[] contentDisp = resp.getHeaders("content-disposition"); if (contentDisp != null && contentDisp.length > 0) { HeaderElement[] headerElements = contentDisp[0].getElements(); if (headerElements != null) { for (HeaderElement headerElement : headerElements) { if ("attachment".equals(headerElement.getName())) { NameValuePair param = headerElement.getParameterByName("filename"); if (param != null) { fileName = param.getValue(); break; } } } } } return fileName; }
Example 3
Source File: HttpResponseConsumer.java From cs-actions with Apache License 2.0 | 6 votes |
public void consume(Map<String, String> result) throws IOException { if (httpResponse.getEntity() != null) { if (responseCharacterSet == null || responseCharacterSet.isEmpty()) { Header contentType = httpResponse.getEntity().getContentType(); if (contentType != null) { String value = contentType.getValue(); NameValuePair[] nameValuePairs = BasicHeaderValueParser.parseParameters(value, BasicHeaderValueParser.INSTANCE); for (NameValuePair nameValuePair : nameValuePairs) { if (nameValuePair.getName().equalsIgnoreCase("charset")) { responseCharacterSet = nameValuePair.getValue(); break; } } } if (responseCharacterSet == null || responseCharacterSet.isEmpty()) { responseCharacterSet = Consts.ISO_8859_1.name(); } } consumeResponseContent(result); } }
Example 4
Source File: HttpClient4EntityExtractor.java From pinpoint with Apache License 2.0 | 6 votes |
/** * copy: EntityUtils Obtains character set of the entity, if known. * * @param entity must not be null * @return the character set, or null if not found * @throws ParseException if header elements cannot be parsed * @throws IllegalArgumentException if entity is null */ private static String getContentCharSet(final HttpEntity entity) throws ParseException { if (entity == null) { throw new IllegalArgumentException("HTTP entity must not be null"); } String charset = null; if (entity.getContentType() != null) { HeaderElement values[] = entity.getContentType().getElements(); if (values.length > 0) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } return charset; }
Example 5
Source File: CaseModelsResource.java From flowable-engine with Apache License 2.0 | 6 votes |
@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 6
Source File: PatreonAPI.java From patreon-java with Apache License 2.0 | 6 votes |
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; }
Example 7
Source File: WXPayUtil.java From common-project with Apache License 2.0 | 6 votes |
public static String getSign(List<NameValuePair> params) { ArrayList<String> list = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); for(NameValuePair pair:params){ if (pair.getValue()!=""&& !pair.getValue().equalsIgnoreCase("sign")) list.add(pair.getName() + "=" + pair.getValue() + "&"); } int size = list.size(); String [] arrayToSort = list.toArray(new String[size]); Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); for(int i = 0; i < size; i ++) { sb.append(arrayToSort[i]); } String result = sb.toString(); result += "key=" +KEY; byte[] data=null; try { data = result.getBytes("utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String appSign = MD5Util.sign(data).toUpperCase(); return appSign; }
Example 8
Source File: OtherUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
public static String getFileNameFromHttpResponse(final HttpResponse response) { if (response == null) return null; String result = null; Header header = response.getFirstHeader("Content-Disposition"); if (header != null) { for (HeaderElement element : header.getElements()) { NameValuePair fileNamePair = element.getParameterByName("filename"); if (fileNamePair != null) { result = fileNamePair.getValue(); // try to get correct encoding str result = CharsetUtils.toCharset(result, HTTP.UTF_8, result.length()); break; } } } return result; }
Example 9
Source File: DecisionTablesResource.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@RequestMapping(method = RequestMethod.GET, produces = "application/json") public ResultListDataRepresentation getDecisionTables(HttpServletRequest request) { // need to parse the filterText parameter ourselves, due to encoding issues with the default parsing. String filter = 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(); } } } return decisionTableService.getDecisionTables(filter); }
Example 10
Source File: RecoverableRpcProxy.java From attic-apex-core with Apache License 2.0 | 5 votes |
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 11
Source File: Plugin.java From java-platform with Apache License 2.0 | 5 votes |
protected String getParameter(List<NameValuePair> nameValuePairs, String param) { for (NameValuePair nameValuePair : nameValuePairs) { if (Objects.equal(param, nameValuePair.getName())) { return nameValuePair.getValue(); } } return null; }
Example 12
Source File: Servlets.java From atlas with Apache License 2.0 | 5 votes |
public static String getDoAsUser(HttpServletRequest request) { if (StringUtils.isNoneEmpty(request.getQueryString())) { List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET); if (list != null) { for (NameValuePair nv : list) { if (DO_AS.equals(nv.getName())) { return nv.getValue(); } } } } return null; }
Example 13
Source File: HttpParamDelegationTokenPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
private static String getHttpParam(HttpServletRequest request, String param) { List<NameValuePair> pairs = URLEncodedUtils.parse(request.getQueryString(), Charset.forName("UTF-8")); for (NameValuePair nvp : pairs) { if (param.equals(nvp.getName())) { return nvp.getValue(); } } return null; }
Example 14
Source File: SlackNotificationImpl.java From tcSlackBuildNotifier with MIT License | 5 votes |
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; }
Example 15
Source File: DriverImpl.java From lucene-solr with Apache License 2.0 | 5 votes |
private void loadParams(URI uri, Properties props) throws SQLException { List<NameValuePair> parsedParams = URLEncodedUtils.parse(uri, "UTF-8"); for (NameValuePair pair : parsedParams) { if (pair.getValue() != null) { props.put(pair.getName(), pair.getValue()); } else { props.put(pair.getName(), ""); } } }
Example 16
Source File: FlowableModelQueryService.java From flowable-engine with Apache License 2.0 | 5 votes |
public ResultListDataRepresentation getModels(String filter, String sort, Integer modelType, HttpServletRequest request) { // need to parse the filterText parameter ourselves, due to encoding issues with the default parsing. String filterText = null; List<NameValuePair> params = URLEncodedUtils.parse(request.getQueryString(), Charset.forName("UTF-8")); if (params != null) { for (NameValuePair nameValuePair : params) { if ("filterText".equalsIgnoreCase(nameValuePair.getName())) { filterText = nameValuePair.getValue(); } } } List<ModelRepresentation> resultList = new ArrayList<>(); List<Model> models = null; String validFilter = makeValidFilterText(filterText); if (validFilter != null) { models = modelRepository.findByModelTypeAndFilter(modelType, validFilter, sort); } else { models = modelRepository.findByModelType(modelType, sort); } if (CollectionUtils.isNotEmpty(models)) { List<String> addedModelIds = new ArrayList<>(); for (Model model : models) { if (!addedModelIds.contains(model.getId())) { addedModelIds.add(model.getId()); ModelRepresentation representation = createModelRepresentation(model); resultList.add(representation); } } } ResultListDataRepresentation result = new ResultListDataRepresentation(resultList); return result; }
Example 17
Source File: HttpRequestHelper.java From esigate with Apache License 2.0 | 5 votes |
public static String getParameter(DriverRequest request, String name) { String characterEncoding = request.getCharacterEncoding(); if (characterEncoding == null) { characterEncoding = "ISO-8859-1"; } List<NameValuePair> parameters = UriUtils.parse(request.getOriginalRequest().getRequestLine().getUri(), characterEncoding); for (NameValuePair nameValuePair : parameters) { if (nameValuePair.getName().equals(name)) { return nameValuePair.getValue(); } } return null; }
Example 18
Source File: DelegationTokenAuthenticationFilter.java From big-c with Apache License 2.0 | 5 votes |
@VisibleForTesting static String getDoAs(HttpServletRequest request) { List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET); if (list != null) { for (NameValuePair nv : list) { if (DelegationTokenAuthenticatedURL.DO_AS. equalsIgnoreCase(nv.getName())) { return nv.getValue(); } } } return null; }
Example 19
Source File: BasicURLNormalizer.java From ache with Apache License 2.0 | 4 votes |
/** * Basic filter to remove query parameters from urls so parameters that * don't change the content of the page can be removed. An example would be * a google analytics query parameter like "utm_campaign" which might have * several different values for a url that points to the same content. This * is also called when removing attributes where the value is a hash. */ private String processQueryElements(String urlToFilter) { try { // Handle illegal characters by making a url first // this will clean illegal characters like | URL url = new URL(urlToFilter); String path = url.getPath(); String query = url.getQuery(); // check if the last element of the path contains parameters // if so convert them to query elements if (path.contains(";")) { String[] pathElements = path.split("/"); String last = pathElements[pathElements.length - 1]; // replace last value by part without params int semicolon = last.indexOf(";"); if (semicolon != -1) { pathElements[pathElements.length - 1] = last.substring(0, semicolon); String params = last.substring(semicolon + 1).replaceAll( ";", "&"); if (query == null) { query = params; } else { query += "&" + params; } // rebuild the path StringBuilder newPath = new StringBuilder(); for (String p : pathElements) { if (StringUtils.isNotBlank(p)) { newPath.append("/").append(p); } } path = newPath.toString(); } } if (StringUtils.isEmpty(query)) { return urlToFilter; } List<NameValuePair> pairs = URLEncodedUtils.parse(query, StandardCharsets.UTF_8); Iterator<NameValuePair> pairsIterator = pairs.iterator(); while (pairsIterator.hasNext()) { NameValuePair param = pairsIterator.next(); if (queryElementsToRemove.contains(param.getName())) { pairsIterator.remove(); } else if (removeHashes && param.getValue() != null) { Matcher m = thirtytwobithash.matcher(param.getValue()); if (m.matches()) { pairsIterator.remove(); } } } StringBuilder newFile = new StringBuilder(); if (StringUtils.isNotBlank(path)) { newFile.append(path); } if (!pairs.isEmpty()) { Collections.sort(pairs, parametersComparator); String newQueryString = URLEncodedUtils.format(pairs, StandardCharsets.UTF_8); newFile.append('?').append(newQueryString); } if (url.getRef() != null) { newFile.append('#').append(url.getRef()); } return new URL(url.getProtocol(), url.getHost(), url.getPort(), newFile.toString()).toString(); } catch (MalformedURLException e) { LOG.warn("Invalid urlToFilter {}. {}", urlToFilter, e); return null; } }
Example 20
Source File: UrlParser.java From r2m-plugin-android with Apache License 2.0 | 4 votes |
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; }