List of usage examples for org.springframework.util MultiValueMap getFirst
@Nullable V getFirst(K key);
From source file:com.gvmax.web.api.WebAppAPI.java
private boolean getBoolean(String key, MultiValueMap<String, String> form) { return Boolean.parseBoolean(form.getFirst(key)); }
From source file:org.cloudfoundry.identity.uaa.login.feature.OpenIdTokenGrantsIT.java
@Test public void testImplicitGrant() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>(); postBody.add("client_id", "cf"); postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf"); postBody.add("response_type", "token id_token"); postBody.add("source", "credentials"); postBody.add("username", user.getUserName()); postBody.add("password", "secret"); ResponseEntity<Void> responseEntity = restOperations.exchange(loginUrl + "/oauth/authorize", HttpMethod.POST, new HttpEntity<>(postBody, headers), Void.class); Assert.assertEquals(HttpStatus.FOUND, responseEntity.getStatusCode()); UriComponents locationComponents = UriComponentsBuilder.fromUri(responseEntity.getHeaders().getLocation()) .build();/*w w w . ja v a2 s. co m*/ Assert.assertEquals("uaa.cloudfoundry.com", locationComponents.getHost()); Assert.assertEquals("/redirect/cf", locationComponents.getPath()); MultiValueMap<String, String> params = parseFragmentParams(locationComponents); Assert.assertThat(params.get("jti"), not(empty())); Assert.assertEquals("bearer", params.getFirst("token_type")); Assert.assertThat(Integer.parseInt(params.getFirst("expires_in")), Matchers.greaterThan(40000)); String[] scopes = UriUtils.decode(params.getFirst("scope"), "UTF-8").split(" "); Assert.assertThat(Arrays.asList(scopes), containsInAnyOrder("scim.userids", "password.write", "cloud_controller.write", "openid", "cloud_controller.read")); validateToken("access_token", params.toSingleValueMap(), scopes); validateToken("id_token", params.toSingleValueMap(), scopes); }
From source file:com.gvmax.web.api.WebAppAPI.java
private int getInt(String key, MultiValueMap<String, String> form) { try {/*from www.j a v a 2 s . com*/ return Integer.parseInt(form.getFirst(key)); } catch (NumberFormatException e) { return 0; } }
From source file:com.kolich.pusachat.spring.controllers.api.Chat.java
@RequestMapping(method = { RequestMethod.DELETE }, value = "/message/{token}") public ModelAndView deleteMessage(@PathVariable final String token, @RequestBody final MultiValueMap<String, String> params) { return new PusaChatControllerClosure<ModelAndView>("DELETE:/api/chat/message/" + token, logger__) { @Override/* w ww . j a v a 2 s . co m*/ public ModelAndView doit() throws Exception { final PusaChatSession session = getSession(token); return getModelAndView(VIEW_NAME, postDeleteMessage(session.getRoomId(), session.getClientId(), params.getFirst(MESSAGE_ID_DELETE_QUERY_PARAM))); } }.execute(); }
From source file:de.codecentric.batch.web.JobOperationsController.java
@RequestMapping(value = "/jobs/{jobName}", method = RequestMethod.POST) public String launch(@PathVariable String jobName, @RequestParam MultiValueMap<String, String> payload) throws NoSuchJobException, JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersNotFoundException { String parameters = payload.getFirst(JOB_PARAMETERS); if (LOG.isDebugEnabled()) { LOG.debug("Attempt to start job with name " + jobName + " and parameters " + parameters + "."); }/*from ww w. j a v a2 s.c om*/ try { Job job = jobRegistry.getJob(jobName); JobParameters jobParameters = createJobParametersWithIncrementerIfAvailable(parameters, job); Long id = jobLauncher.run(job, jobParameters).getId(); return String.valueOf(id); } catch (NoSuchJobException e) { // Job hasn't been found in normal context, so let's check if there's a JSR-352 job. String jobConfigurationLocation = "/META-INF/batch-jobs/" + jobName + ".xml"; Resource jobXml = new ClassPathResource(jobConfigurationLocation); if (!jobXml.exists()) { throw e; } else { Long id = jsrJobOperator.start(jobName, PropertiesConverter.stringToProperties(parameters)); return String.valueOf(id); } } }
From source file:com.gvmax.web.api.WebAppAPI.java
@RequestMapping(value = "/monitors", method = RequestMethod.POST) @Timed/*from w w w. j a va 2 s. c o m*/ @ExceptionMetered public ModelMap monitors(@RequestBody MultiValueMap<String, String> params, HttpSession session, HttpServletResponse resp) { try { String pin = params.getFirst("pin"); User user = getUser(service, session, pin); if (user == null) { invalidCredentials(resp); return null; } boolean monitorSMS = Boolean.parseBoolean(params.getFirst("monitorSMS")); boolean monitorVM = Boolean.parseBoolean(params.getFirst("monitorVM")); boolean monitorMC = Boolean.parseBoolean(params.getFirst("monitorMC")); service.setMonitors(user.getEmail(), monitorSMS, monitorVM, monitorMC); return new ModelMap("result", "ok"); } catch (DataAccessException e) { internalError(e, resp); return null; } }
From source file:com.expedia.seiso.web.hateoas.link.RepoSearchLinks.java
private String toQueryString(MultiValueMap<String, String> params) { val paramNames = new ArrayList<String>(params.keySet()); Collections.sort(paramNames); val builder = new StringBuilder(); boolean first = true; for (val paramName : paramNames) { if (!first) { builder.append("&"); }/*from w w w. j av a 2 s .c o m*/ builder.append(paramName); builder.append("="); // FIXME The responsibility for formatting template variables belongs here, not with the clients. [WLW] builder.append(params.getFirst(paramName)); first = false; } return builder.toString(); }
From source file:com.gvmax.web.api.WebAppAPI.java
@RequestMapping(value = "/notifiers", method = RequestMethod.POST) @Timed//from www . jav a 2 s .c o m @ExceptionMetered public ModelMap notifiers(@RequestBody MultiValueMap<String, String> params, HttpSession session, HttpServletResponse resp) { try { User user = getUser(service, session, params.getFirst("pin")); if (user == null) { invalidCredentials(resp); return null; } extractUserFromForm(user, params); try { service.setNotifiers(user); return new ModelMap("result", "ok"); } catch (IOException e) { sendError(400, e.getMessage(), resp); return null; } } catch (DataAccessException e) { internalError(e, resp); return null; } }
From source file:org.jutge.joc.porra.controller.desktop.DesktopSignupController.java
@EntityStashManaged @RequestMapping(value = "/apuntar-se/activar/{activationToken}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.TEXT_HTML_VALUE) public String activatePost(@PathVariable final String activationToken, @RequestBody final MultiValueMap<String, String> dataMap, final HttpServletRequest request, final Locale locale) { this.logger.info("DesktopSignupController.activatePost"); final Account account = this.validateAccountToken(activationToken, locale); request.setAttribute("userName", account.getName()); request.setAttribute("activationToken", activationToken); // validate params final String password = dataMap.getFirst("pwd"); final String passwordConfirm = dataMap.getFirst("pwd-con"); account.setHashedPass(password);/*from ww w.java 2s . com*/ this.validatePassword(account, passwordConfirm, locale); this.accountService.approveAccount(account); return "/desktop/signup/activate-done"; }
From source file:com.gvmax.web.api.WebAppAPI.java
@RequestMapping(value = "/register", method = RequestMethod.POST) @Timed// w w w .j a v a 2 s .c o m @ExceptionMetered public ModelMap register(@RequestBody MultiValueMap<String, String> params, HttpSession session, HttpServletResponse resp) { // Check thirdParty Pin String thirdParty = params.getFirst("tpPin"); if (thirdParty == null) { invalidCredentials(resp); return null; } thirdParty = thirdParties.getProperty(thirdParty); if (thirdParty == null) { invalidCredentials(resp); return null; } // Check email String email = params.getFirst("email"); if (email == null) { invalidCredentials(resp); return null; } email = EmailUtils.normalizeEmail(email); // Check googlePassword String googlePassword = params.getFirst("googlePassword"); if (googlePassword == null) { googlePassword = params.getFirst("password"); } if (googlePassword == null) { invalidCredentials(resp); return null; } User user = service.getUser(email); if (user == null) { user = new User(email); user.setPassword(params.getFirst("password")); user.setGvPassword(Boolean.parseBoolean(params.getFirst("gvPassword"))); } if (user.getPassword() == null) { invalidCredentials(resp); return null; } // Monitors if (params.getFirst("monitorSMS") != null) { user.setMonitorSMS(Boolean.parseBoolean(params.getFirst("monitorSMS"))); } if (params.getFirst("monitorVM") != null) { user.setMonitorVM(Boolean.parseBoolean(params.getFirst("monitorVM"))); } if (params.getFirst("monitorMC") != null) { user.setMonitorMC(Boolean.parseBoolean(params.getFirst("monitorMC"))); } // Notifiers extractUserFromForm(user, params); try { RegistrationInfo info = service.register(user, googlePassword); if (info.isRegistered()) { String message = "You are receiving this email because " + thirdParty + " has registered your account with GVMax\n" + "GVMax is a service used to monitor GoogleVoice and provide notifications for incoming SMS and Voicemail\n" + "GVMax also provides other services such as sending Group SMS's and integration with GoogleTalk, Twitter etc...\n" + "You can view your account at https://www.gvmax.com\n" + "username: " + user.getEmail() + "\n"; if (info.isAlreadyRegistered()) { message = "You are receiving this email because " + thirdParty + " has modified your account at GVMax\n" + "You can view your account at https://www.gvmax.com\n" + "username: " + user.getEmail() + "\n"; } if (user.isGvPassword()) { message += "password: your google voice password\n"; } else { message += "password: " + user.getPassword() + "\n"; } try { relay.sendEmail(relay.getEmailSender(), relay.getEmailSender(), user.getEmail(), "Welcome to GVMax", message); } catch (Exception e) { logger.warn("Unable to send email: " + e.getMessage()); } } return new ModelMap("info", info); } catch (DataAccessException e) { internalError(e, resp); return null; } }