List of usage examples for org.springframework.http HttpMethod POST
HttpMethod POST
To view the source code for org.springframework.http HttpMethod POST.
Click Source Link
From source file:org.openlmis.notification.web.BaseWebIntegrationTest.java
private String fetchToken() { RestTemplate restTemplate = new RestTemplate(); String plainCreds = clientId + ":" + clientSecret; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); HttpEntity<String> request = new HttpEntity<>(headers); Map<String, Object> params = new HashMap<>(); params.put("grant_type", "password"); ResponseEntity<?> response = restTemplate.exchange(buildUri(authorizationUrl, params), HttpMethod.POST, request, Object.class); return ((Map<String, String>) response.getBody()).get("access_token"); }
From source file:org.openlmis.fulfillment.service.stockmanagement.StockEventStockManagementServiceTest.java
@Test public void shouldSubmitStockEvent() { ResponseEntity response = mock(ResponseEntity.class); when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(UUID.class))) .thenReturn(response);/*from w w w . ja v a 2 s . c om*/ service.submit(new StockEventDto()); verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.POST), entityCaptor.capture(), eq(UUID.class)); URI uri = uriCaptor.getValue(); String url = service.getServiceUrl() + service.getUrl(); assertThat(uri.toString(), is(equalTo(url))); assertThat(entityCaptor.getValue().getBody(), is(new StockEventDto())); }
From source file:com.mec.Security.WebSecurityConfig.java
@Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable().cors().and().sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests() .antMatchers(HttpMethod.POST, "/login/**").permitAll().antMatchers(HttpMethod.OPTIONS, "/**") .permitAll().and() // **permit OPTIONS call to all** .authorizeRequests().antMatchers("/API/editor/**").hasAnyRole("mapa.Editor").and() .addFilterBefore(jwtLoginFilter(), UsernamePasswordAuthenticationFilter.class)//filter the api/login requests .addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);// And filter other requests to check the presence of JWT in header }
From source file:eu.cloudwave.wp5.monitoring.rest.FeedbackHandlerMonitoringClient.java
/** * Sends monitoring data (i.e. the call trace) and its attached metrics to the Feedback Handler. * /*w ww .j av a2s . c o m*/ * @param executions * the {@link RunningProcedureExecution}'s (i.e. the call trace) * @return <code>true</code> if the data has been successfully sent to the Feedback Handler, <code>false</code> * otherwise */ public boolean postData(final RunningProcedureExecution rootProcedureExecution) { final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); headers.add(Headers.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); headers.add(Headers.ACCESS_TOKEN, accessToken()); headers.add(Headers.APPLICATION_ID, applicationId()); final HttpEntity<MetricContainingProcedureExecutionDto> httpEntity = new HttpEntity<MetricContainingProcedureExecutionDto>( rootProcedureExecution, headers); final ResponseEntity<Boolean> result = new RestTemplate().exchange(url(), HttpMethod.POST, httpEntity, Boolean.class); return result.getBody(); }
From source file:org.schedoscope.metascope.controller.MetascopeDataDistributionControllerTest.java
@Test public void sometest() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.set("Referer", "/test"); HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); ResponseEntity<String> response = this.restTemplate.exchange("/datadistribution/start?fqdn=test", HttpMethod.POST, entity, String.class); assertEquals(302, response.getStatusCodeValue()); assertTrue(response.getHeaders().get("Location").get(0).endsWith("/test#datadistributionContent")); }
From source file:com.logaritex.hadoop.configuration.manager.http.AndroidHttpService.java
public <R> R post(String url, Object request, Class<R> responseType, Object... uriVariables) { R response = restTemplate.exchange(baseUrl + url, HttpMethod.POST, new HttpEntity<Object>(request, httpHeaders), responseType, uriVariables).getBody(); return response; }
From source file:example.company.SecurityConfiguration.java
/** * This section defines the security policy for the app. * <p>/*from w w w .j a v a2 s . c om*/ * <ul> * <li>BASIC authentication is supported (enough for this REST-based demo).</li> * <li>/employees is secured using URL security shown below.</li> * <li>CSRF headers are disabled since we are only testing the REST interface, not a web one.</li> * </ul> * NOTE: GET is not shown which defaults to permitted. * * @param http * @throws Exception * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity) */ @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic().and().authorizeRequests().// antMatchers(HttpMethod.POST, "/employees").hasRole("ADMIN").// antMatchers(HttpMethod.PUT, "/employees/**").hasRole("ADMIN").// antMatchers(HttpMethod.PATCH, "/employees/**").hasRole("ADMIN").and().// csrf().disable(); }
From source file:org.openlmis.fulfillment.service.AuthServiceTest.java
@Test public void shouldObtainAccessToken() throws Exception { ResponseEntity<Object> response = mock(ResponseEntity.class); Map<String, String> body = ImmutableMap.of("access_token", TOKEN); when(restTemplate.exchange(eq(AUTHORIZATION_URI), eq(HttpMethod.POST), any(HttpEntity.class), eq(Object.class))).thenReturn(response); when(response.getBody()).thenReturn(body); String token = authService.obtainAccessToken(); assertThat(token, is(equalTo(TOKEN))); verify(restTemplate).exchange(eq(AUTHORIZATION_URI), eq(HttpMethod.POST), entityStringCaptor.capture(), eq(Object.class)); HttpEntity<String> entity = entityStringCaptor.getValue(); assertThat(entity.getHeaders().get("Authorization"), contains("Basic dHJ1c3RlZC1jbGllbnQ6c2VjcmV0")); }
From source file:com.consol.citrus.admin.connector.WebSocketPushMessageListenerTest.java
@Test public void testOnOutboundMessage() throws Exception { Message outbound = new DefaultMessage("Hello Citrus!"); reset(restTemplate, context);/*from www .ja v a 2 s . c o m*/ when(restTemplate.exchange(eq("http://localhost:8080/connector/message/outbound?processId=MySampleTest"), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> { HttpEntity request = (HttpEntity) invocation.getArguments()[2]; Assert.assertEquals(request.getBody().toString(), outbound.toString()); return ResponseEntity.ok().build(); }); when(context.getVariables()) .thenReturn(Collections.singletonMap(Citrus.TEST_NAME_VARIABLE, "MySampleTest")); when(context.getVariable(Citrus.TEST_NAME_VARIABLE)).thenReturn("MySampleTest"); pushMessageListener.onOutboundMessage(outbound, context); verify(restTemplate).exchange(eq("http://localhost:8080/connector/message/outbound?processId=MySampleTest"), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); }
From source file:business.security.HttpSecurityConfiguration.java
@Override protected void configure(HttpSecurity http) throws Exception { http.exceptionHandling().authenticationEntryPoint(new Http403ForbiddenEntryPoint()).and() .userDetailsService(userDetailsService()).formLogin().permitAll() .failureHandler(authenticationFailureHandler).and().logout().permitAll() .logoutSuccessUrl("/#/login").and().authorizeRequests().antMatchers("/admin/**") .access("hasRole('palga')").and().authorizeRequests() .antMatchers("/", "/robots.txt", "/public/labs/**", "/password/request-new", "/password/reset", "/index.html", "/bower_components/**", "/app/**", "/js/**", "/messages/**", "/css/**", "/*.ico", "/images/**") .permitAll().antMatchers(HttpMethod.POST, "/register/users").permitAll() .antMatchers(HttpMethod.POST, "/register/users/**").permitAll() .antMatchers(HttpMethod.GET, "/register/users/activate/**").permitAll() .antMatchers(HttpMethod.GET, "/status").permitAll().antMatchers(HttpMethod.GET, "/ping").permitAll() .anyRequest().authenticated().and().addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class).csrf() .csrfTokenRepository(csrfTokenRepository()).and().headers() .addHeaderWriter(new StaticHeadersWriter("Content-Security-Policy-Report-Only", "default-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:")); }