List of usage examples for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap
public LinkedMultiValueMap()
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStep.java
/** * Prepares request to CF//from w w w . j a v a 2 s. c om * <a href="https://apidocs.cloudfoundry.org/225/apps/uploads_the_bits_for_an_app.html">endpoint * </a> * * @param dataPath * @return prepared request * @throws IOException */ private HttpEntity<MultiValueMap<String, Object>> prepareMutlipartRequest(Path dataPath) throws IOException { HttpEntity<String> resourcesPart = prepareResourcesRequestPart(); HttpEntity<ByteArrayResource> dataPart = prepareDataRequestPart(dataPath); MultiValueMap<String, Object> multiPartRequest = new LinkedMultiValueMap<>(); multiPartRequest.add("resources", resourcesPart); multiPartRequest.add("application", dataPart); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); return new HttpEntity<>(multiPartRequest, headers); }
From source file:com.ezsource_mobile.fileservice.FileService.java
public FileUploadResponse[] uploadFile(final MultipartFile[] files, final String relativePath, final HttpServletRequest httpServletRequest) { LOGGER.debug("start of uploadFile method"); final RestTemplate restTemplate = new RestTemplate(); FileUploadResponse[] result;/*from w w w. j a va 2 s . c o m*/ try { final String url = getFileUploadUrl(httpServletRequest); final String fileName = files[0].getOriginalFilename(); final LinkedMultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>(); final ByteArrayResource contentsAsResource = new ByteArrayResource(files[0].getBytes()) { @Override public String getFilename() { return fileName; } }; body.add("files", contentsAsResource); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.add("Authorization", "Basic " + Base64.encodeBase64String(new StringBuilder(securityService.getUserName()) .append(":").append(getHash()).toString().getBytes())); final HttpEntity<LinkedMultiValueMap<String, Object>> request = new HttpEntity<LinkedMultiValueMap<String, Object>>( body, headers); result = restTemplate.postForObject(url, request, FileUploadResponse[].class); } catch (Exception e) { throw new RuntimeException(e); } LOGGER.debug("end of uploadFile method" + result); return result; }
From source file:com.ctrip.infosec.rule.rest.RuleEngineRESTfulControllerTest.java
@Test @Ignore//from w ww .ja v a 2 s . c o m public void testVerify() throws Exception { System.out.println("verify"); MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.add("fact", JSON.toJSONString(fact)); String response = rt.postForObject("http://10.2.10.77:8080/ruleenginews/rule/verify", params, String.class); System.out.println("response: " + response); }
From source file:org.cloudfoundry.identity.uaa.login.feature.LoginIT.java
@Test public void testRedirectAfterFailedLogin() throws Exception { RestTemplate template = new RestTemplate(); LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>(); body.add("username", testAccounts.getUserName()); body.add("password", "invalidpassword"); ResponseEntity<Void> loginResponse = template.exchange(baseUrl + "/login.do", HttpMethod.POST, new HttpEntity<>(body, null), Void.class); assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode()); }
From source file:org.unidle.social.ConnectionRepositoryImpl.java
@Override @Transactional(readOnly = true)/* w ww. j a v a2 s . com*/ public MultiValueMap<String, Connection<?>> findConnectionsToUsers( final MultiValueMap<String, String> providerUserIds) { final MultiValueMap<String, Connection<?>> connections = new LinkedMultiValueMap<>(); for (final String providerId : providerUserIds.keySet()) { final List<String> singleProviderUserIds = providerUserIds.get(providerId); final List<UserConnection> userConnections = userConnectionRepository.findAll(user, providerId, singleProviderUserIds); for (final String providerUserId : singleProviderUserIds) { UserConnection userConnection = null; for (UserConnection candidateUserConnection : userConnections) { if (providerUserId.equals(candidateUserConnection.getProviderUserId())) { userConnection = candidateUserConnection; break; } } connections.add(providerId, Functions.toConnection(connectionFactoryLocator, textEncryptor).apply(userConnection)); } } return connections; }
From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java
@Test public void testSimpleAutologinFlow() throws Exception { HttpHeaders headers = getAppBasicAuthHttpHeaders(); LinkedMultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>(); requestBody.add("username", testAccounts.getUserName()); requestBody.add("password", testAccounts.getPassword()); //generate an autologin code with our credentials ResponseEntity<Map> autologinResponseEntity = restOperations.exchange(baseUrl + "/autologin", HttpMethod.POST, new HttpEntity<>(requestBody, headers), Map.class); String autologinCode = (String) autologinResponseEntity.getBody().get("code"); //start the authorization flow - this will issue a login event //by using the autologin code String authorizeUrl = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/oauth/authorize") .queryParam("redirect_uri", appUrl).queryParam("response_type", "code") .queryParam("client_id", "app").queryParam("code", autologinCode).build().toUriString(); //rest template that does NOT follow redirects RestTemplate template = new RestTemplate(new DefaultIntegrationTestConfig.HttpClientFactory()); headers.remove("Authorization"); ResponseEntity<Map> authorizeResponse = template.exchange(authorizeUrl, HttpMethod.GET, new HttpEntity<>(new HashMap<String, String>(), headers), Map.class); //we are now logged in. retrieve the JSESSIONID List<String> cookies = authorizeResponse.getHeaders().get("Set-Cookie"); assertEquals(1, cookies.size());// ww w . j av a 2 s . co m headers = getAppBasicAuthHttpHeaders(); headers.add("Cookie", cookies.get(0)); //if we receive a 200, then we must approve our scopes if (HttpStatus.OK == authorizeResponse.getStatusCode()) { authorizeUrl = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/oauth/authorize") .queryParam("user_oauth_approval", "true").build().toUriString(); authorizeResponse = template.exchange(authorizeUrl, HttpMethod.POST, new HttpEntity<>(new HashMap<String, String>(), headers), Map.class); } //approval is complete, we receive a token code back assertEquals(HttpStatus.FOUND, authorizeResponse.getStatusCode()); List<String> location = authorizeResponse.getHeaders().get("Location"); assertEquals(1, location.size()); String newCode = location.get(0).substring(location.get(0).indexOf("code=") + 5); //request a token using our code String tokenUrl = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/oauth/token") .queryParam("response_type", "token").queryParam("grant_type", "authorization_code") .queryParam("code", newCode).queryParam("redirect_uri", appUrl).build().toUriString(); ResponseEntity<Map> tokenResponse = template.exchange(tokenUrl, HttpMethod.POST, new HttpEntity<>(new HashMap<String, String>(), headers), Map.class); assertEquals(HttpStatus.OK, tokenResponse.getStatusCode()); //here we must reset our state. we do that by following the logout flow. headers.clear(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); ResponseEntity<Void> loginResponse = restOperations.exchange(baseUrl + "/login.do", HttpMethod.POST, new HttpEntity<>(requestBody, headers), Void.class); cookies = loginResponse.getHeaders().get("Set-Cookie"); assertEquals(1, cookies.size()); headers.clear(); headers.add("Cookie", cookies.get(0)); restOperations.exchange(baseUrl + "/profile", HttpMethod.GET, new HttpEntity<>(null, headers), Void.class); String revokeApprovalsUrl = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/profile").build() .toUriString(); requestBody.clear(); requestBody.add("clientId", "app"); requestBody.add("delete", ""); ResponseEntity<Void> revokeResponse = template.exchange(revokeApprovalsUrl, HttpMethod.POST, new HttpEntity<>(requestBody, headers), Void.class); assertEquals(HttpStatus.FOUND, revokeResponse.getStatusCode()); }
From source file:com.miserablemind.api.consumer.tradeking.api.impl.MarketTemplate.java
@Override public OptionQuote[] searchOptions(String ticker, Double minStrikePrice, Double maxStrikePrice, OptionQuote.OptionType type, LocalDate startDate, LocalDate endDate) { MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(); String queryString = "put_call-eq:" + type; //Strike Prices if (null != minStrikePrice) queryString += " AND strikeprice-gte:" + minStrikePrice; if (null != maxStrikePrice) queryString += " AND strikeprice-lte:" + maxStrikePrice; //Dates//from w ww.j ava2 s . c o m if (null != startDate) queryString += " AND xdate-gte:" + startDate.toString("yyyyMMdd"); if (null != endDate) queryString += " AND xdate-lte:" + endDate.toString("yyyyMMdd"); parameters.set("symbol", ticker); parameters.set("query", queryString); URI url = this.buildUri(URL_SEARCH_OPTIONS, parameters); ResponseEntity<TKOptionQuoteResponse> response = this.getRestTemplate().getForEntity(url, TKOptionQuoteResponse.class); if (null != response.getBody().getError()) throw new ApiException(TradeKingServiceProvider.PROVIDER_ID, response.getBody().getError()); return response.getBody().getQuotes(); }
From source file:com.rst.oauth2.google.security.GoogleTokenServices.java
private Map<String, Object> checkToken(String accessToken) { MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("token", accessToken); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", getAuthorizationHeader(clientId, clientSecret)); String accessTokenUrl = new StringBuilder(checkTokenEndpointUrl).append("?access_token=") .append(accessToken).toString(); return postForMap(accessTokenUrl, formData, headers); }
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); }/*w w w . j a v a 2s.co m*/ 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; }