List of usage examples for org.springframework.util MultiValueMap add
void add(K key, @Nullable V value);
From source file:at.create.android.ffc.http.FormBasedAuthentication.java
/** * Authentication via username and password. * @return True if the authentication succeeded, otherwise false is returned. *//*from w ww .j av a 2 s .c o m*/ public boolean authenticate() { MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("authentication[username]", username); formData.add("authentication[password]", password); formData.add("authentication[remember_me]", "1"); restTemplate.getMessageConverters().add(new FormHttpMessageConverter()); restTemplate.postForLocation(getUrl(), formData); if (CookiePreserveHttpRequestInterceptor.getInstance().hasCookieWithName("user_credentials")) { return true; // Try with another method } else { restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders); ResponseEntity<String> responseEntity = restTemplate.exchange(baseUri, HttpMethod.GET, requestEntity, String.class); return !responseEntity.getBody().toString().contains("authentication[username]"); } }
From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.PasswordValidationRuleTest.java
@Test public void validate_emptyPasswordKeyInData_exceptionThrown() { //given//from w ww .ja v a 2s.co m MultiValueMap<String, String> requestWithEmptyPasswordKey = new LinkedMultiValueMap<>(); requestWithEmptyPasswordKey.add(PasswordValidationRule.PASSWORD_KEY, ""); PasswordValidationRule rule = new PasswordValidationRule(new FormDataValidator()); //then thrown.expect(ValidationException.class); //when rule.validate(requestWithEmptyPasswordKey); }
From source file:org.ow2.proactive.scheduling.api.graphql.client.SchedulingApiClient.java
public SchedulingApiResponse execute(Query query) throws SchedulingApiException { if (Strings.isNullOrEmpty(url)) { throw new SchedulingApiException("API server URL is not initialized"); }//www. j a v a2s . c o m try { MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>(); headers.add("sessionid", sessionId); headers.add("Content-Type", "application/json"); log.debug("request query : ", query.getQuery()); HttpEntity<Map<String, String>> request = new HttpEntity<>(query.getQueryMap(), headers); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); return restTemplate.postForObject(url, request, SchedulingApiResponse.class); } catch (Exception e) { throw new SchedulingApiException("Exception", e); } }
From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.HostValidationRuleTest.java
@Test public void validate_allDataValid_doesntThrowException() { //given//from w w w .j a v a2 s .c o m MultiValueMap<String, String> requestWithHost = new LinkedMultiValueMap<>(); requestWithHost.add(HostValidationRule.HOST_KEY, "http://example.com"); HostValidationRule rule = new HostValidationRule(new FormDataValidator()); //when rule.validate(requestWithHost); //then // no exception is thrown }
From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.UsernameValidationRuleTest.java
@Test public void validate_multipleUsernameKeysInData_exceptionThrown() { // given/*from w w w .ja v a2s . com*/ MultiValueMap<String, String> requestWithMultipleUsernameKeys = new LinkedMultiValueMap<>(); requestWithMultipleUsernameKeys.add(UsernameValidationRule.USERNAME_KEY, "some-username"); requestWithMultipleUsernameKeys.add(UsernameValidationRule.USERNAME_KEY, "other-username"); UsernameValidationRule rule = new UsernameValidationRule(new FormDataValidator()); // then thrown.expect(ValidationException.class); // when rule.validate(requestWithMultipleUsernameKeys); }
From source file:org.wallride.web.controller.admin.comment.CommentSearchForm.java
public MultiValueMap<String, String> toQueryParams() { MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); if (StringUtils.hasText(keyword)) { params.add("keyword", keyword); }//from ww w. ja v a 2s. c o m return params; }
From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.PasswordValidationRuleTest.java
@Test public void validate_multiplePasswordKeysInData_exceptionThrown() { //given//from w ww . j av a 2 s .co m MultiValueMap<String, String> requestWithMultiplePasswordKeys = new LinkedMultiValueMap<>(); requestWithMultiplePasswordKeys.add(PasswordValidationRule.PASSWORD_KEY, "some-password"); requestWithMultiplePasswordKeys.add(PasswordValidationRule.PASSWORD_KEY, "other-password"); PasswordValidationRule rule = new PasswordValidationRule(new FormDataValidator()); //then thrown.expect(ValidationException.class); //when rule.validate(requestWithMultiplePasswordKeys); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.HostValidationRuleTest.java
@Test public void validate_invalidUrlInHostKeyInData_exceptionThrown() { //given/*from ww w .ja v a 2 s. co m*/ MultiValueMap<String, String> requestWithInvalidUrl = new LinkedMultiValueMap<>(); requestWithInvalidUrl.add(HostValidationRule.HOST_KEY, "lsakjfajkadf"); HostValidationRule rule = new HostValidationRule(new FormDataValidator()); //then thrown.expect(ValidationException.class); //when rule.validate(requestWithInvalidUrl); }
From source file:de.codecentric.batch.test.metrics.BatchMetricsExporterIntegrationTest.java
@Test public void testRunJob() throws InterruptedException { MultiValueMap<String, Object> requestMap = new LinkedMultiValueMap<>(); requestMap.add("jobParameters", "run=2"); Long executionId = restTemplate.postForObject( "http://localhost:" + port + "/batch/operations/jobs/simpleBatchMetricsJob", requestMap, Long.class); while (!restTemplate .getForObject("http://localhost:" + port + "/batch/operations/jobs/executions/{executionId}", String.class, executionId) .equals("COMPLETED")) { Thread.sleep(1000);/* w w w . ja v a 2s . c om*/ } String log = restTemplate.getForObject( "http://localhost:" + port + "/batch/operations/jobs/executions/{executionId}/log", String.class, executionId); assertThat(log.length() > 20, is(true)); JobExecution jobExecution = jobExplorer.getJobExecution(executionId); assertThat(jobExecution.getStatus(), is(BatchStatus.COMPLETED)); String jobExecutionString = restTemplate.getForObject( "http://localhost:" + port + "/batch/monitoring/jobs/executions/{executionId}", String.class, executionId); assertThat(jobExecutionString.contains("COMPLETED"), is(true)); Metric<?> metric = metricReader .findOne("gauge.batch.simpleBatchMetricsJob.simpleBatchMetricsStep.processor"); assertThat(metric, is(notNullValue())); assertThat((Double) metric.getValue(), is(notNullValue())); assertThat((Double) metric.getValue(), is(7.0)); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.restapi.validation.HostValidationRuleTest.java
@Test public void validate_emptyHostKeyInData_exceptionThrown() { //given// www.j av a 2s .co m MultiValueMap<String, String> requestWithEmptyHostKey = new LinkedMultiValueMap<>(); requestWithEmptyHostKey.add(HostValidationRule.HOST_KEY, ""); HostValidationRule rule = new HostValidationRule(new FormDataValidator()); //then thrown.expect(ValidationException.class); //when rule.validate(requestWithEmptyHostKey); }