List of usage examples for org.springframework.util MultiValueMap add
void add(K key, @Nullable V value);
From source file:org.craftercms.search.service.impl.RestClientSearchService.java
@Override public String updateDocument(String site, String id, File document, Map<String, String> additionalFields) throws SearchException { FileSystemResource fsrDoc = new FileSystemResource(document); MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>(); form.add(REQUEST_PARAM_SITE, site); form.add(REQUEST_PARAM_ID, id);// w w w .ja v a 2 s. c o m form.add(REQUEST_PARAM_DOCUMENT, fsrDoc); if (MapUtils.isNotEmpty(additionalFields)) { for (Map.Entry<String, String> additionalField : additionalFields.entrySet()) { String fieldName = additionalField.getKey(); if (fieldName.equals(REQUEST_PARAM_SITE) || fieldName.equals(REQUEST_PARAM_ID) || fieldName.equals(REQUEST_PARAM_DOCUMENT)) { throw new SearchException( String.format("An additional field shouldn't have the following names: %s, %s, %s", REQUEST_PARAM_SITE, REQUEST_PARAM_ID, REQUEST_PARAM_DOCUMENT)); } form.add(fieldName, additionalField.getValue()); } } String updateDocumentUrl = serverUrl + URL_ROOT + URL_UPDATE_DOCUMENT; try { return restTemplate.postForObject(new URI(updateDocumentUrl), form, String.class); } catch (URISyntaxException e) { throw new SearchException("Invalid URI: " + updateDocumentUrl, e); } catch (HttpStatusCodeException e) { throw new SearchException("Update for document '" + id + "' failed: [" + e.getStatusText() + "] " + e.getResponseBodyAsString()); } catch (Exception e) { throw new SearchException("Update for document '" + id + "' failed: " + e.getMessage(), e); } }
From source file:com.aestheticsw.jobkeywords.service.termextractor.impl.fivefilters.FiveFiltersClient.java
public String[][] executeFiveFiltersPost(String content) { String query = "http://termextract.fivefilters.org/extract.php"; MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.add("text", content); params.add("output", "json"); params.add("max", "300"); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( params, requestHeaders);/*www .j a v a 2s . co m*/ ResponseEntity<String[][]> stringArrayEntty = restTemplate.exchange(query, HttpMethod.POST, requestEntity, String[][].class); String[][] stringArray = stringArrayEntty.getBody(); return stringArray; }
From source file:org.hdiv.web.multipart.HDIVMultipartResolver.java
/** * Return the multipart files as Map of field name to MultipartFile instance. *//* ww w . j av a 2s. c om*/ public MultiValueMap<String, MultipartFile> getMultipartFileElements(Hashtable fileElements) { MultiValueMap<String, MultipartFile> multipartFiles = new LinkedMultiValueMap<String, MultipartFile>(); for (Object key : fileElements.keySet()) { multipartFiles.add((String) key, (MultipartFile) fileElements.get(key)); } return multipartFiles; }
From source file:com.bailen.radioOnline.recursos.REJA.java
public Usuario login(String email) { MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("email", email); String result = new RestTemplate().postForObject("http://ceatic.ujaen.es:8075/radioapi/v2/login", params, String.class); //return result; try {/*from w ww. j av a2s .c o m*/ ObjectMapper a = new ObjectMapper(); Usuario listilla = a.readValue(result, Usuario.class); return listilla; } catch (Exception e) { return null; } }
From source file:com.music.web.AuthenticationController.java
@RequestMapping("/persona/auth") @ResponseBody//from w w w .ja v a 2 s. c om public String authenticateWithPersona(@RequestParam String assertion, @RequestParam boolean userRequestedAuthentication, HttpServletRequest request, HttpServletResponse httpResponse, Model model) throws IOException { if (context.getUser() != null) { return ""; } MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("assertion", assertion); params.add("audience", request.getScheme() + "://" + request.getServerName() + ":" + (request.getServerPort() == 80 ? "" : request.getServerPort())); PersonaVerificationResponse response = restTemplate.postForObject( "https://verifier.login.persona.org/verify", params, PersonaVerificationResponse.class); if (response.getStatus().equals("okay")) { User user = userService.getUserByEmail(response.getEmail()); if (user == null && userRequestedAuthentication) { return "/socialSignUp?email=" + response.getEmail(); } else if (user != null) { if (userRequestedAuthentication || user.isLoginAutomatically()) { signInAdapter.signIn(user, httpResponse, true); return "/"; } else { return ""; } } else { return ""; //in case this is not a user-requested operation, do nothing } } else { logger.warn("Persona authentication failed due to reason: " + response.getReason()); throw new IllegalStateException("Authentication failed"); } }
From source file:com.bailen.radioOnline.recursos.REJA.java
public Incidencia ratings(String apiKey, String rating, String idCancion, String fav) { MultiValueMap<String, String> params1 = new LinkedMultiValueMap<>(); params1.add("rating", (rating)); params1.add("idCancion", (idCancion)); params1.add("fav", (fav)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.add("Authorization", apiKey); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params1, headers); String result = new RestTemplate().postForObject("http://ceatic.ujaen.es:8075/radioapi/v2/ratings", request, String.class); try {/* w w w . ja va 2s . c om*/ ObjectMapper a = new ObjectMapper(); Incidencia listilla = a.readValue(result, Incidencia.class); return listilla; } catch (Exception e) { return null; } }
From source file:de.loercher.localpress.core.api.LocalPressController.java
@RequestMapping(value = "/articles", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<String> addArticleEntry(@RequestBody LocalPressArticleEntity entity, @RequestHeader HttpHeaders headers) throws UnauthorizedException, GeneralLocalPressException, JsonProcessingException { AddArticleEntityDTO geoDTO = new AddArticleEntityDTO(entity.getRelease()); List<String> userHeader = headers.get("UserID"); if (userHeader == null || userHeader.isEmpty()) { throw new UnauthorizedException("There needs to be set a UserID-Header!", "", ""); }//from w w w .j a va 2 s .co m MultiValueMap<String, String> geoHeaders = new LinkedMultiValueMap<>(); geoHeaders.add("UserID", userHeader.get(0)); HttpEntity<AddArticleEntityDTO> request = new HttpEntity<>(geoDTO, geoHeaders); RestTemplate template = new RestTemplate(); String ratingURL = RATING_URL + "feedback"; ResponseEntity<Map> result; try { result = template.postForEntity(ratingURL, request, Map.class); } catch (RestClientException e) { GeneralLocalPressException ex = new GeneralLocalPressException( "There happened an error by trying to invoke the geo API!", e); log.error(ex.getLoggingString()); throw ex; } if (!result.getStatusCode().equals(HttpStatus.CREATED)) { GeneralLocalPressException e = new GeneralLocalPressException(result.getStatusCode().getReasonPhrase()); log.error(e.getLoggingString()); throw e; } String articleID = (String) result.getBody().get("articleID"); if (articleID == null) { GeneralLocalPressException e = new GeneralLocalPressException( "No articleID found in response from rating module by trying to add new article!"); log.error(e.getLoggingString()); throw e; } HttpEntity<LocalPressArticleEntity> second = new HttpEntity<>(entity, geoHeaders); template.put(GEO_URL + articleID, second); String url = (String) result.getBody().get("feedbackURL"); Map<String, Object> returnMap = new LinkedHashMap<>(); returnMap.put("articleID", articleID); returnMap.put("userID", userHeader.get(0)); Timestamp now = new Timestamp(new Date().getTime()); returnMap.put("timestamp", now); returnMap.put("status", 201); returnMap.put("message", "Created."); returnMap.put("feedbackURL", url); return new ResponseEntity<>(objectMapper.writeValueAsString(returnMap), HttpStatus.CREATED); }
From source file:org.unidle.social.ConnectionRepositoryImplTest.java
@Test public void testFindConnectionsToUsers() throws Exception { final MultiValueMap<String, String> providerUserIds = new LinkedMultiValueMap<>(); providerUserIds.add("twitter", "provider user id 1"); providerUserIds.add("twitter", "provider user id 2"); providerUserIds.add("twitter", "provider user id 3"); providerUserIds.add("facebook", "provider user id 4"); final MultiValueMap<String, Connection<?>> result = subject.findConnectionsToUsers(providerUserIds); assertThat(result).hasSize(2).satisfies(containsKey("twitter")).satisfies(containsKey("facebook")); assertThat(result.get("twitter")).hasSize(3); assertThat(result.get("twitter").get(0)).isNotNull(); assertThat(result.get("twitter").get(1)).isNotNull(); assertThat(result.get("twitter").get(2)).isNull(); assertThat(result.get("facebook")).hasSize(1); assertThat(result.get("facebook").get(0)).isNull(); }
From source file:org.cloudfoundry.identity.uaa.login.SamlRemoteUaaController.java
@RequestMapping(value = "/oauth/token", method = RequestMethod.POST, params = "grant_type=password") @ResponseBody// www. ja v a 2s. c o m public ResponseEntity<byte[]> tokenEndpoint(HttpServletRequest request, HttpEntity<byte[]> entity, @RequestParam Map<String, String> parameters, Map<String, Object> model, Principal principal) throws Exception { // Request has a password. Owner password grant with a UAA password if (null != request.getParameter("password")) { return passthru(request, entity, model); } else { // MultiValueMap<String, String> requestHeadersForClientInfo = new LinkedMultiValueMap<String, String>(); requestHeadersForClientInfo.add(AUTHORIZATION, request.getHeader(AUTHORIZATION)); ResponseEntity<byte[]> clientInfoResponse = getDefaultTemplate().exchange( getUaaBaseUrl() + "/clientinfo", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(null, requestHeadersForClientInfo), byte[].class); if (clientInfoResponse.getStatusCode() == HttpStatus.OK) { String path = extractPath(request); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.setAll(parameters); if (principal != null) { map.set("source", "login"); map.set("client_id", getClientId(clientInfoResponse.getBody())); map.setAll(getLoginCredentials(principal)); map.remove("credentials"); // legacy vmc might break otherwise } else { throw new BadCredentialsException("No principal found in authorize endpoint"); } HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.putAll(getRequestHeaders(requestHeaders)); requestHeaders.remove(AUTHORIZATION.toLowerCase()); requestHeaders.remove(ACCEPT.toLowerCase()); requestHeaders.remove(CONTENT_TYPE.toLowerCase()); requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); requestHeaders.remove(COOKIE); requestHeaders.remove(COOKIE.toLowerCase()); ResponseEntity<byte[]> response = getAuthorizationTemplate().exchange(getUaaBaseUrl() + "/" + path, HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders), byte[].class); saveCookie(response.getHeaders(), model); byte[] body = response.getBody(); if (body != null) { HttpHeaders outgoingHeaders = getResponseHeaders(response.getHeaders()); return new ResponseEntity<byte[]>(response.getBody(), outgoingHeaders, response.getStatusCode()); } throw new IllegalStateException("Neither a redirect nor a user approval"); } else { throw new BadCredentialsException(new String(clientInfoResponse.getBody())); } } }
From source file:com.evozon.evoportal.myaccount.worker.PMReportsIntegration.java
private MultiValueMap<String, Object> getPMReportsParameters(User forUser) { MultiValueMap<String, Object> mapModifications = new LinkedMultiValueMap<String, Object>(); DetailsModel detailsModel = newAccountModelHolder.getDetailsModel(); mapModifications.add(PMReportsConstants.USER_CNP, detailsModel.getCNP()); mapModifications.add(PMReportsConstants.USER_EMAIL, detailsModel.getEmailAddress()); mapModifications.add(PMReportsConstants.USER_LAST_NAME, detailsModel.getLastName()); mapModifications.add(PMReportsConstants.USER_FIRST_NAME, detailsModel.getFirstName()); String startDate = MyAccountUtil.convertDateToString( newAccountModelHolder.getFreeDaysModel().getStartDate(), DATE_FORMAT_MONTH_DAY_YEAR); mapModifications.add(PMReportsConstants.USER_DATE_HIRED, startDate); String pmDep = findPMReportsAssociatedDepartment(forUser); if (!pmDep.isEmpty()) { mapModifications.add(PMReportsConstants.DEPARTMENT_NAME, pmDep); }/* ww w .j a va 2 s . c om*/ String countryCode = null; EvoAddressModel primaryAddress = newAccountModelHolder.getPrimaryAddress(); if (primaryAddress != null) { mapModifications.add(PMReportsConstants.USER_ZIP_CODE, primaryAddress.getPostalCode()); mapModifications.add(PMReportsConstants.USER_CITY_NAME, primaryAddress.getCity()); countryCode = primaryAddress.getCountryCode(); if (countryCode.isEmpty()) { countryCode = PMReportsConstants.USER_DEFAULT_COUNTRY_CODE; } mapModifications.add(PMReportsConstants.USER_STREET_NAME, primaryAddress.getStreetName()); mapModifications.add(PMReportsConstants.USER_STREET_NUMBER, primaryAddress.getStreetNumber()); } // The 'country code' is mandatory mapModifications.add(PMReportsConstants.USER_COUNTRY_CODE, (countryCode == null) ? PMReportsConstants.USER_DEFAULT_COUNTRY_CODE : countryCode); mapModifications.add(PMReportsConstants.USER_MOBILE_NUMBER, detailsModel.getPhoneNumber()); mapModifications.add(PMReportsConstants.USER_PLATE_NUMBER, detailsModel.getLicensePlate()); return mapModifications; }