Example usage for org.springframework.util MultiValueMap containsKey

List of usage examples for org.springframework.util MultiValueMap containsKey

Introduction

In this page you can find the example usage for org.springframework.util MultiValueMap containsKey.

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:org.mule.modules.wechat.WechatConnector.java

/**
 * Verify validity of the URL//from  w  ww.java2s  .  co m
 * <br><a href="http://admin.wechat.com/wiki/index.php?title=Getting_Started#Step_2._Verify_validity_of_the_URL">http://admin.wechat.com/wiki/index.php?title=Getting_Started#Step_2._Verify_validity_of_the_URL</a>
 * 
 * @param uri URI sent by WeChat Official Account Admin System
 * @return The developer's backend system should return the echostr parameter value indicating that the request has been successfully received
 * @throws Exception If anything fails
 */
@Processor
public Object verifyUrl(@Default("#[message.inboundProperties.'http.request.uri']") String uri)
        throws Exception {
    String result = "";
    MultiValueMap<String, String> parameters = UriComponentsBuilder.fromUri(new URI(uri)).build()
            .getQueryParams();

    if (parameters.containsKey("timestamp") && parameters.containsKey("nonce")
            && parameters.containsKey("signature")) {
        String[] arr = { config.getToken(), parameters.get("timestamp").get(0),
                parameters.get("nonce").get(0) };
        Arrays.sort(arr);
        String tmpStr = String.join("", arr);
        tmpStr = DigestUtils.sha1Hex(tmpStr);
        if (tmpStr.equals(parameters.get("signature").get(0))) {
            if (parameters.containsKey("echostr")) {
                result = parameters.get("echostr").get(0);
            }
        }
    }

    return result;
}

From source file:org.sparkcommerce.openadmin.web.controller.entity.AdminBasicEntityController.java

/**
 * Renders the main entity listing for the specified class, which is based on the current sectionKey with some optional
 * criteria.//w  w w.ja  v  a2  s.  c  om
 * 
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param criteria a Map of property name -> list critiera values
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "", method = RequestMethod.GET)
public String viewEntityList(HttpServletRequest request, HttpServletResponse response, Model model,
        @PathVariable Map<String, String> pathVars, @RequestParam MultiValueMap<String, String> requestParams)
        throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> crumbs = getSectionCrumbs(request, null, null);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, crumbs,
            pathVars);

    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();

    ListGrid listGrid = formService.buildMainListGrid(drs, cmd, sectionKey, crumbs);
    List<EntityFormAction> mainActions = new ArrayList<EntityFormAction>();
    addAddActionIfAllowed(sectionClassName, cmd, mainActions);

    Field firstField = listGrid.getHeaderFields().iterator().next();
    if (requestParams.containsKey(firstField.getName())) {
        model.addAttribute("mainSearchTerm", requestParams.get(firstField.getName()).get(0));
    }

    extensionManager.getProxy().addAdditionalMainActions(sectionClassName, mainActions);

    model.addAttribute("entityFriendlyName", cmd.getPolymorphicEntities().getFriendlyName());
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("listGrid", listGrid);
    model.addAttribute("mainActions", mainActions);
    model.addAttribute("viewType", "entityList");

    setModelAttributes(model, sectionKey);
    return "modules/defaultContainer";
}

From source file:org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper.java

public void setResponse(int status, InputStream entity, MultiValueMap<String, String> headers)
        throws IOException {
    RequestContext context = RequestContext.getCurrentContext();

    RequestContext.getCurrentContext().setResponseStatusCode(status);
    if (entity != null) {
        RequestContext.getCurrentContext().setResponseDataStream(entity);
    }//from ww  w .jav  a2  s . c om

    boolean isOriginResponseGzipped = false;

    if (headers.containsKey(CONTENT_ENCODING)) {
        Collection<String> collection = headers.get(CONTENT_ENCODING);
        for (String header : collection) {
            if (HTTPRequestUtils.getInstance().isGzipped(header)) {
                isOriginResponseGzipped = true;
                break;
            }
        }
    }
    context.setResponseGZipped(isOriginResponseGzipped);

    for (Entry<String, List<String>> header : headers.entrySet()) {
        RequestContext ctx = RequestContext.getCurrentContext();
        String name = header.getKey();
        for (String value : header.getValue()) {
            ctx.addOriginResponseHeader(name, value);

            if (name.equalsIgnoreCase("content-length"))
                ctx.setOriginContentLength(value);

            if (isIncludedHeader(name)) {
                ctx.addZuulResponseHeader(name, value);
            }
        }
    }

}

From source file:org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.java

private MultiValueMap<String, String> revertHeaders(Header[] headers) {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    for (Header header : headers) {
        String name = header.getName();
        if (!map.containsKey(name)) {
            map.put(name, new ArrayList<String>());
        }//  w  w w .j  a  v a 2  s.c  o m
        map.get(name).add(header.getValue());
    }
    return map;
}

From source file:org.springframework.data.rest.webmvc.config.RepositoryRestMvConfigurationIntegrationTests.java

/**
 * @see DATAREST-271/*from ww w  . ja v  a  2  s .  c o m*/
 */
@Test
public void assetConsidersPaginationCustomization() {

    HateoasPageableHandlerMethodArgumentResolver resolver = context
            .getBean(HateoasPageableHandlerMethodArgumentResolver.class);

    UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
    resolver.enhance(builder, null, new PageRequest(0, 9000, Direction.ASC, "firstname"));

    MultiValueMap<String, String> params = builder.build().getQueryParams();

    assertThat(params.containsKey("myPage"), is(true));
    assertThat(params.containsKey("mySort"), is(true));

    assertThat(params.get("mySize"), hasSize(1));
    assertThat(params.get("mySize").get(0), is("7000"));
}

From source file:org.springframework.web.multipart.commons.CommonsMultipartResolverTests.java

private void doTestFiles(MultipartHttpServletRequest request) throws IOException {
    Set<String> fileNames = new HashSet<>();
    Iterator<String> fileIter = request.getFileNames();
    while (fileIter.hasNext()) {
        fileNames.add(fileIter.next());/*from w w w .  ja va  2 s . co  m*/
    }
    assertEquals(3, fileNames.size());
    assertTrue(fileNames.contains("field1"));
    assertTrue(fileNames.contains("field2"));
    assertTrue(fileNames.contains("field2x"));
    CommonsMultipartFile file1 = (CommonsMultipartFile) request.getFile("field1");
    CommonsMultipartFile file2 = (CommonsMultipartFile) request.getFile("field2");
    CommonsMultipartFile file2x = (CommonsMultipartFile) request.getFile("field2x");

    Map<String, MultipartFile> fileMap = request.getFileMap();
    assertEquals(3, fileMap.size());
    assertTrue(fileMap.containsKey("field1"));
    assertTrue(fileMap.containsKey("field2"));
    assertTrue(fileMap.containsKey("field2x"));
    assertEquals(file1, fileMap.get("field1"));
    assertEquals(file2, fileMap.get("field2"));
    assertEquals(file2x, fileMap.get("field2x"));

    MultiValueMap<String, MultipartFile> multiFileMap = request.getMultiFileMap();
    assertEquals(3, multiFileMap.size());
    assertTrue(multiFileMap.containsKey("field1"));
    assertTrue(multiFileMap.containsKey("field2"));
    assertTrue(multiFileMap.containsKey("field2x"));
    List<MultipartFile> field1Files = multiFileMap.get("field1");
    assertEquals(2, field1Files.size());
    assertTrue(field1Files.contains(file1));
    assertEquals(file1, multiFileMap.getFirst("field1"));
    assertEquals(file2, multiFileMap.getFirst("field2"));
    assertEquals(file2x, multiFileMap.getFirst("field2x"));

    assertEquals("type1", file1.getContentType());
    assertEquals("type2", file2.getContentType());
    assertEquals("type2", file2x.getContentType());
    assertEquals("field1.txt", file1.getOriginalFilename());
    assertEquals("field2.txt", file2.getOriginalFilename());
    assertEquals("field2x.txt", file2x.getOriginalFilename());
    assertEquals("text1", new String(file1.getBytes()));
    assertEquals("text2", new String(file2.getBytes()));
    assertEquals(5, file1.getSize());
    assertEquals(5, file2.getSize());
    assertTrue(file1.getInputStream() instanceof ByteArrayInputStream);
    assertTrue(file2.getInputStream() instanceof ByteArrayInputStream);
    File transfer1 = new File("C:/transfer1");
    file1.transferTo(transfer1);
    File transfer2 = new File("C:/transfer2");
    file2.transferTo(transfer2);
    assertEquals(transfer1, ((MockFileItem) file1.getFileItem()).writtenFile);
    assertEquals(transfer2, ((MockFileItem) file2.getFileItem()).writtenFile);

}