List of usage examples for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap
public LinkedMultiValueMap()
From source file:org.cloudfoundry.identity.uaa.integration.PasswordChangeEndpointIntegrationTests.java
@Test @OAuth2ContextConfiguration(resource = OAuth2ContextConfiguration.Implicit.class, initialize = false) public void testUserMustSupplyOldPassword() throws Exception { MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>(); parameters.set("source", "credentials"); parameters.set("username", joe.getUserName()); parameters.set("password", "password"); context.getAccessTokenRequest().putAll(parameters); PasswordChangeRequest change = new PasswordChangeRequest(); change.setPassword("newpassword"); HttpHeaders headers = new HttpHeaders(); ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}/password", HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, joe.getId()); assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode()); }
From source file:com.marklogic.mgmt.admin.AdminManager.java
/** * Set whether SSL FIPS is enabled on the cluster or not by running against /v1/eval on the given appServicesPort. */// w ww . j a va 2 s . co m public void setSslFipsEnabled(final boolean enabled, final int appServicesPort) { final String xquery = "import module namespace admin = 'http://marklogic.com/xdmp/admin' at '/MarkLogic/admin.xqy'; " + "admin:save-configuration(admin:cluster-set-ssl-fips-enabled(admin:get-configuration(), " + enabled + "()))"; invokeActionRequiringRestart(new ActionRequiringRestart() { @Override public boolean execute() { RestTemplate rt = RestTemplateUtil.newRestTemplate(adminConfig.getHost(), appServicesPort, adminConfig.getUsername(), adminConfig.getPassword()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.add("xquery", xquery); HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<MultiValueMap<String, String>>( map, headers); String url = format("http://%s:%d/v1/eval", adminConfig.getHost(), appServicesPort); if (logger.isInfoEnabled()) { logger.info("Setting SSL FIPS enabled: " + enabled); } rt.exchange(url, HttpMethod.POST, entity, String.class); if (logger.isInfoEnabled()) { logger.info("Finished setting SSL FIPS enabled: " + enabled); } return true; } }); }
From source file:com.artivisi.belajar.restful.ui.controller.ApplicationConfigControllerTestIT.java
@SuppressWarnings("unchecked") @Test//from w ww. j a v a2 s. c o m public void testUploadPakaiRestTemplate() { RestTemplate rest = new RestTemplate(); String jsessionid = rest.execute(login, HttpMethod.POST, new RequestCallback() { @Override public void doWithRequest(ClientHttpRequest request) throws IOException { request.getBody().write(("j_username=" + username + "&j_password=" + password).getBytes()); } }, new ResponseExtractor<String>() { @Override public String extractData(ClientHttpResponse response) throws IOException { List<String> cookies = response.getHeaders().get("Cookie"); // assuming only one cookie with jsessionid as the only value if (cookies == null) { cookies = response.getHeaders().get("Set-Cookie"); } String cookie = cookies.get(cookies.size() - 1); int start = cookie.indexOf('='); int end = cookie.indexOf(';'); return cookie.substring(start + 1, end); } }); MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>(); form.add("foto", new FileSystemResource("src/test/resources/foto-endy.jpg")); form.add("Filename", "cv-endy.pdf"); form.add("cv", new FileSystemResource("src/test/resources/resume-endy-en.pdf")); form.add("keterangan", "File Endy"); Map<String, String> result = rest.postForObject(target + "/abc123/files;jsessionid=" + jsessionid, form, Map.class); assertEquals("success", result.get("cv")); assertEquals("success", result.get("foto")); assertEquals("success", result.get("keterangan")); }
From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.CrowdJob.java
public MultiValueMap<String, String> getIncludedCountriesMap() { MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); for (String country : getIncludedCountries()) { map.add(jobKey + "[" + includedCountriesKey + "][]", country); }//w ww . j ava2 s . c o m return map; }
From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java
@Test public void testFormEncodedAutologinRequest() throws Exception { HttpHeaders headers = getAppBasicAuthHttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>(); requestBody.add("username", testAccounts.getUserName()); requestBody.add("password", testAccounts.getPassword()); ResponseEntity<Map> autologinResponseEntity = restOperations.exchange(baseUrl + "/autologin", HttpMethod.POST, new HttpEntity<>(requestBody, headers), Map.class); String autologinCode = (String) autologinResponseEntity.getBody().get("code"); assertEquals(6, autologinCode.length()); }
From source file:org.appverse.web.framework.backend.frontfacade.websocket.IntegrationWebsocketTest.java
private static void loginAndSaveJsessionIdCookie(final String user, final String password, final HttpHeaders headersToUpdate) { String url = "http://localhost:" + port + "/"; new RestTemplate().execute(url, HttpMethod.POST, new RequestCallback() { @Override//from w w w.jav a 2 s . c o m public void doWithRequest(ClientHttpRequest request) throws IOException { MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.add("username", user); map.add("password", password); new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request); } }, new ResponseExtractor<Object>() { @Override public Object extractData(ClientHttpResponse response) throws IOException { headersToUpdate.add("Cookie", response.getHeaders().getFirst("Set-Cookie")); return null; } }); }
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);//from w ww .j ava 2s . com form.add(REQUEST_PARAM_ID, id); 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:de.tudarmstadt.ukp.clarin.webanno.crowdflower.CrowdJob.java
public MultiValueMap<String, String> getExcludedCountriesMap() { MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); for (String country : getExcludedCountries()) { map.add(jobKey + "[" + excludedCountriesKey + "][]", country); }//ww w . j a va2 s.c o m return map; }
From source file:com.esri.geoportal.harvester.rest.TaskController.java
/** * Gets task by id./*w w w . ja v a2 s .c o m*/ * * @param taskId task id * @return task info or <code>null</code> if no task found */ @RequestMapping(value = "/rest/harvester/tasks/{taskId}/export", method = RequestMethod.GET) public ResponseEntity<String> export(@PathVariable UUID taskId) { try { LOG.debug(formatForLog("GET /rest/harvester/tasks/%s", taskId)); TaskDefinition taskDefinition = engine.getTasksService().readTaskDefinition(taskId); if (taskDefinition == null) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); headers.add("Content-disposition", String.format("attachment; filename=\"%s.json\"", taskId)); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); ResponseEntity<String> responseEntity = new ResponseEntity<>(mapper.writeValueAsString(taskDefinition), headers, HttpStatus.OK); return responseEntity; } catch (DataProcessorException | JsonProcessingException ex) { LOG.error(formatForLog("Error getting task: %s", taskId), ex); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.CrowdClient.java
/** * Sets a single key in Crowdflowers job with a given value * @param job//from w w w .j a v a2s . c om * @param key * @param value */ void updateVariable(CrowdJob job, String Url, String key, String value) { MultiValueMap<String, String> argumentMap = new LinkedMultiValueMap<String, String>(); argumentMap.add(key, value); RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new FormHttpMessageConverter()); restTemplate.put(Url, argumentMap, job.getId(), apiKey); }