下面列出了org.springframework.util.MultiValueMap#keySet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected MultiValueMap<PartitionKey, Document> partitionDocumentsForSecurity(List<Document> documents,
SecuritySession securitySession) {
MultiValueMap<PartitionKey, Document> partitions = new LinkedMultiValueMap<PartitionKey, Document>();
for (Document document : documents) {
DocumentTypeSecurity security = getDocumentTypeSecurity(document.getDocumentTypeName(), securitySession);
MultiValueMap<String, ExtensionDefinition> securityAttributeExtensionDefinitions = loadExtensionDefinitions(
security, securitySession);
for (String applicationId : securityAttributeExtensionDefinitions.keySet()) {
List<ExtensionDefinition> extensionDefinitions = securityAttributeExtensionDefinitions.get(
applicationId);
PartitionKey key = new PartitionKey(applicationId, extensionDefinitions);
partitions.add(key, document);
}
}
return partitions;
}
/**
* Whether the given FlashMap matches the current request.
* Uses the expected request path and query parameters saved in the FlashMap.
*/
protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) {
String expectedPath = flashMap.getTargetRequestPath();
if (expectedPath != null) {
String requestUri = getUrlPathHelper().getOriginatingRequestUri(request);
if (!requestUri.equals(expectedPath) && !requestUri.equals(expectedPath + "/")) {
return false;
}
}
MultiValueMap<String, String> actualParams = getOriginatingRequestParams(request);
MultiValueMap<String, String> expectedParams = flashMap.getTargetRequestParams();
for (String expectedName : expectedParams.keySet()) {
List<String> actualValues = actualParams.get(expectedName);
if (actualValues == null) {
return false;
}
for (String expectedValue : expectedParams.get(expectedName)) {
if (!actualValues.contains(expectedValue)) {
return false;
}
}
}
return true;
}
/**
* Return a handler mapping with the mapped ViewControllers; or {@code null}
* in case of no registrations.
*/
public AbstractHandlerMapping getHandlerMapping() {
Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) {
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
for (HttpRequestHandler httpHandler : mappings.keySet()) {
for (String pattern : mappings.get(httpHandler)) {
urlMap.put(pattern, httpHandler);
}
}
}
WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
hm.setUrlMap(urlMap);
hm.setOrder(this.order);
if (this.urlPathHelper != null) {
hm.setUrlPathHelper(this.urlPathHelper);
}
return hm;
}
/**
* Return a {@link HandlerMapping} with mapped {@link HttpRequestHandler}s.
*/
public AbstractHandlerMapping getHandlerMapping() {
Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
for (ServletWebSocketHandlerRegistration registration : this.registrations) {
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
for (HttpRequestHandler httpHandler : mappings.keySet()) {
for (String pattern : mappings.get(httpHandler)) {
urlMap.put(pattern, httpHandler);
}
}
}
WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
hm.setUrlMap(urlMap);
hm.setOrder(this.order);
if (this.urlPathHelper != null) {
hm.setUrlPathHelper(this.urlPathHelper);
}
return hm;
}
/**
* Whether the given FlashMap matches the current request.
* Uses the expected request path and query parameters saved in the FlashMap.
*/
protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) {
String expectedPath = flashMap.getTargetRequestPath();
if (expectedPath != null) {
String requestUri = getUrlPathHelper().getOriginatingRequestUri(request);
if (!requestUri.equals(expectedPath) && !requestUri.equals(expectedPath + "/")) {
return false;
}
}
MultiValueMap<String, String> actualParams = getOriginatingRequestParams(request);
MultiValueMap<String, String> expectedParams = flashMap.getTargetRequestParams();
for (String expectedName : expectedParams.keySet()) {
List<String> actualValues = actualParams.get(expectedName);
if (actualValues == null) {
return false;
}
for (String expectedValue : expectedParams.get(expectedName)) {
if (!actualValues.contains(expectedValue)) {
return false;
}
}
}
return true;
}
private Map<String, Object> resolveParam(ServerWebExchange exchange) {
JSONObject param = new JSONObject();
MultiValueMap<String, String> pathParams = exchange.getRequest().getQueryParams();
for (String key : pathParams.keySet()) {
param.put(key, pathParams.getFirst(key));
}
String base64 = exchange.getRequest().getHeaders().getFirst(GatewayConstant.DUBBO_PARAM_HEADER);
if(StringUtils.isNotBlank(base64)){
String body = null ;
try {
body = new String(Base64.getDecoder().decode(base64),"utf-8");
param.put("body", GenericJsonDeserializer.parse(body));
} catch (UnsupportedEncodingException e) {
log.error("dubbo参数解析失败");
}
}
return param;
}
public HttpHeaders postForHeaders(String path, MultiValueMap<String, String> formData, final HttpHeaders headers) {
RequestCallback requestCallback = new NullRequestCallback();
if (headers != null) {
requestCallback = request -> request.getHeaders().putAll(headers);
}
StringBuilder builder = new StringBuilder(getUrl(path));
if (!path.contains("?")) {
builder.append("?");
} else {
builder.append("&");
}
for (String key : formData.keySet()) {
for (String value : formData.get(key)) {
builder.append(key).append("=").append(value);
builder.append("&");
}
}
builder.deleteCharAt(builder.length() - 1);
return client.execute(builder.toString(), HttpMethod.POST, requestCallback,
HttpMessage::getHeaders);
}
/**
* Whether the given FlashMap matches the current request.
* Uses the expected request path and query parameters saved in the FlashMap.
*/
protected boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request) {
String expectedPath = flashMap.getTargetRequestPath();
if (expectedPath != null) {
String requestUri = getUrlPathHelper().getOriginatingRequestUri(request);
if (!requestUri.equals(expectedPath) && !requestUri.equals(expectedPath + "/")) {
return false;
}
}
UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(request).build();
MultiValueMap<String, String> actualParams = uriComponents.getQueryParams();
MultiValueMap<String, String> expectedParams = flashMap.getTargetRequestParams();
for (String expectedName : expectedParams.keySet()) {
List<String> actualValues = actualParams.get(expectedName);
if (actualValues == null) {
return false;
}
for (String expectedValue : expectedParams.get(expectedName)) {
if (!actualValues.contains(expectedValue)) {
return false;
}
}
}
return true;
}
/**
* Decode the given matrix variables via
* {@link #decodeRequestString(HttpServletRequest, String)} unless
* {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is
* assumed the URL path from which the variables were extracted is already
* decoded through a call to
* {@link #getLookupPathForRequest(HttpServletRequest)}.
* @param request current HTTP request
* @param vars URI variables extracted from the URL path
* @return the same Map or a new Map instance
*/
public MultiValueMap<String, String> decodeMatrixVariables(HttpServletRequest request, MultiValueMap<String, String> vars) {
if (this.urlDecode) {
return vars;
}
else {
MultiValueMap<String, String> decodedVars = new LinkedMultiValueMap <String, String>(vars.size());
for (String key : vars.keySet()) {
for (String value : vars.get(key)) {
decodedVars.add(key, decodeInternal(request, value));
}
}
return decodedVars;
}
}
private boolean isMultipart(MultiValueMap<String, ?> map, @Nullable MediaType contentType) {
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
for (String name : map.keySet()) {
for (Object value : map.get(name)) {
if (value != null && !(value instanceof String)) {
return true;
}
}
}
return false;
}
private boolean isMultipart(MultiValueMap<String, ?> map, @Nullable MediaType contentType) {
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
for (String name : map.keySet()) {
for (Object value : map.get(name)) {
if (value != null && !(value instanceof String)) {
return true;
}
}
}
return false;
}
private boolean isMultipart(MultiValueMap<String, ?> map, MediaType contentType) {
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
for (String name : map.keySet()) {
for (Object value : map.get(name)) {
if (value != null && !(value instanceof String)) {
return true;
}
}
}
return false;
}
/**
* Provide request parameters identifying the request for this FlashMap.
* @param params a Map with the names and values of expected parameters
*/
public FlashMap addTargetRequestParams(MultiValueMap<String, String> params) {
if (params != null) {
for (String key : params.keySet()) {
for (String value : params.get(key)) {
addTargetRequestParam(key, value);
}
}
}
return this;
}
/**
* Decode the given matrix variables via
* {@link #decodeRequestString(HttpServletRequest, String)} unless
* {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is
* assumed the URL path from which the variables were extracted is already
* decoded through a call to
* {@link #getLookupPathForRequest(HttpServletRequest)}.
* @param request current HTTP request
* @param vars URI variables extracted from the URL path
* @return the same Map or a new Map instance
*/
public MultiValueMap<String, String> decodeMatrixVariables(HttpServletRequest request, MultiValueMap<String, String> vars) {
if (this.urlDecode) {
return vars;
}
else {
MultiValueMap<String, String> decodedVars = new LinkedMultiValueMap <String, String>(vars.size());
for (String key : vars.keySet()) {
for (String value : vars.get(key)) {
decodedVars.add(key, decodeInternal(request, value));
}
}
return decodedVars;
}
}
private boolean isMultipart(MultiValueMap<String, ?> map, MediaType contentType) {
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
for (String name : map.keySet()) {
for (Object value : map.get(name)) {
if (value != null && !(value instanceof String)) {
return true;
}
}
}
return false;
}
@Test
@Ignore
public void getRecommendationTest() {
try {
MultiValueMap<String, String> k = migrationService.recommendsSnippet(
"org.sonarsource.sonarqube:sonar-plugin-api:5.6", "org.sonarsource.sonarqube:sonar-plugin-api:6.2",
"/Users/juri/development/git/aethereal/aethereal/dataset/sonar-plugin-api6.2/org/sonarsource/java/java-frontend/4.5.0.8398/java-frontend-4.5.0.8398.jar.m3");
for (String clientLoc : k.keySet())
for (String snippet : k.get(clientLoc))
logger.info("{} -> \n{} ", clientLoc, snippet);
} catch (Exception e) {
logger.error("Error in recommendation calculation: {}", e.getMessage());
}
}
private MultiValueMap<String, String> multi(MultiValueMap<String, Part> body) {
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
for (String key : body.keySet()) {
for (Part part : body.get(key)) {
if (part instanceof FormFieldPart) {
FormFieldPart form = (FormFieldPart) part;
map.add(key, form.value());
}
}
}
return map;
}
public void addNativeHeaders(MultiValueMap<String, String> headers) {
if (headers == null) {
return;
}
for (String header : headers.keySet()) {
for (String value : headers.get(header)) {
addNativeHeader(header, value);
}
}
}
/**
* Provide request parameters identifying the request for this FlashMap.
* @param params a Map with the names and values of expected parameters
*/
public FlashMap addTargetRequestParams(MultiValueMap<String, String> params) {
if (params != null) {
for (String key : params.keySet()) {
for (String value : params.get(key)) {
addTargetRequestParam(key, value);
}
}
}
return this;
}
protected void validateNoInvalidParameterIsLeft(MultiValueMap<String, String> params)
throws InvalidArgumentException {
if (!params.isEmpty()) {
throw new InvalidArgumentException("Invalid parameter specified: " + params.keySet());
}
}