List of usage examples for org.springframework.http HttpMethod PUT
HttpMethod PUT
To view the source code for org.springframework.http HttpMethod PUT.
Click Source Link
From source file:org.dawnsci.marketplace.config.SecurityConfiguration.java
@Override protected void configure(HttpSecurity http) throws Exception { http.formLogin().loginPage("/signin").loginProcessingUrl("/signin/authenticate") .failureUrl("/signin?param.error=bad_credentials").and().logout().logoutUrl("/signout") .deleteCookies("JSESSIONID").and().authorizeRequests().antMatchers("/**").permitAll() .antMatchers(HttpMethod.POST, "/**").authenticated().antMatchers(HttpMethod.PUT, "/**") .authenticated().antMatchers(HttpMethod.DELETE, "/**").authenticated().and().httpBasic().and() .rememberMe();/*w w w .jav a 2s.com*/ }
From source file:access.test.PiazzaEnvironmentTests.java
@Test public void testResourcesDoNotExist() { Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces"), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{\"result\": \"all good\"}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.xml"), Mockito.eq(HttpMethod.PUT), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{\"result\": \"all good\"}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{invalid JSON}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores"), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{\"result\": \"all good\"}", HttpStatus.OK)); piazzaEnvironment.initializeEnvironment(); assertTrue(true); // no error occurred }
From source file:com.appglu.impl.CrudTemplateTest.java
@Test public void update() { mockServer.expect(requestTo("http://localhost/appglu/v1/tables/user/1")).andExpect(method(HttpMethod.PUT)) .andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/crud_row_relationships"))) .andRespond(withSuccess().headers(responseHeaders)); Row row = row();/*from w w w .ja va2 s. c o m*/ boolean success = crudOperations.update("user", 1, row); Assert.assertTrue(success); mockServer.verify(); }
From source file:org.androidannotations.test15.rest.HttpMethodServiceTest.java
@Test public void usePutHttpMethod() { HttpMethodsService_ service = new HttpMethodsService_(null); RestTemplate restTemplate = mock(RestTemplate.class); service.setRestTemplate(restTemplate); service.put();/* w ww . j a v a 2 s.co m*/ verify(restTemplate).exchange(Matchers.anyString(), Matchers.<HttpMethod>eq(HttpMethod.PUT), Matchers.<HttpEntity<?>>any(), Matchers.<Class<Object>>any()); }
From source file:org.zalando.boot.etcd.EtcdClientTest.java
@Test public void putWithSetTtl() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=60")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_set.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.put("sample", "Hello world", 60); Assert.assertNotNull("response", response); server.verify();/*www .ja va 2s. c o m*/ }
From source file:org.drugis.addis.config.SecurityConfig.java
@Override protected void configure(HttpSecurity http) throws Exception { String[] whitelist = { "/", "/trialverse", "/trialverse/**", "/patavi", // allow POST mcda models anonymously "/favicon.ico", "/favicon.png", "/app/**", "/auth/**", "/signin", "/signup", "/**/modal/*.html", "/manual.html" }; // Disable CSFR protection on the following urls: List<AntPathRequestMatcher> requestMatchers = Arrays.asList(whitelist).stream() .map(AntPathRequestMatcher::new).collect(Collectors.toList()); CookieCsrfTokenRepository csrfTokenRepository = new CookieCsrfTokenRepository(); csrfTokenRepository.setCookieHttpOnly(false); http.formLogin().loginPage("/signin").loginProcessingUrl("/signin/authenticate") .failureUrl("/signin?param.error=bad_credentials").and().authorizeRequests().antMatchers(whitelist) .permitAll().antMatchers(HttpMethod.GET, "/**").permitAll().antMatchers(HttpMethod.POST, "/**") .authenticated().antMatchers(HttpMethod.PUT, "/**").authenticated() .antMatchers(HttpMethod.DELETE, "/**").authenticated().and().rememberMe().and().exceptionHandling() .authenticationEntryPoint(new Http403ForbiddenEntryPoint()).and() .apply(new SpringSocialConfigurer().alwaysUsePostLoginUrl(false)).and().csrf() .csrfTokenRepository(csrfTokenRepository) .requireCsrfProtectionMatcher( request -> !(requestMatchers.stream().anyMatch(matcher -> matcher.matches(request)) || Optional.fromNullable(request.getHeader("X-Auth-Application-Key")).isPresent() || HttpMethod.GET.toString().equals(request.getMethod()))) .and().setSharedObject(ApplicationContext.class, context); http.addFilterBefore(new AuthenticationFilter(authenticationManager()), BasicAuthenticationFilter.class); }
From source file:org.cloudfoundry.identity.uaa.integration.VmcScimUserEndpointIntegrationTests.java
@Test public void changePasswordSucceeds() throws Exception { PasswordChangeRequest change = new PasswordChangeRequest(); change.setOldPassword("password"); change.setPassword("newpassword"); HttpHeaders headers = new HttpHeaders(); RestOperations client = serverRunning.getRestTemplate(); ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(usersEndpoint) + "/{id}/password", HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, joe.getId()); assertEquals(HttpStatus.OK, result.getStatusCode()); }
From source file:com.tikinou.schedulesdirect.ClientUtils.java
public <R_IMPL extends R, P extends BaseCommandParameter, R extends CommandResult, C extends ParameterizedCommand<P, R>, R_OVER> R_OVER executeRequest( SchedulesDirectClient client, C command, Class<R_IMPL> resultType, Class<R_OVER> resulTypetOverride) { StringBuilder url = new StringBuilder(client.getUrl()); url.append("/").append(command.getEndPoint()); String token = null;/*w w w.ja va2 s.c om*/ if (command.getParameters() instanceof AuthenticatedBaseCommandParameter) token = ((AuthenticatedBaseCommandParameter) command.getParameters()).getToken(); org.springframework.http.HttpMethod httpMethod = null; switch (command.getMethod()) { case GET: Map<String, String> reqParams = command.getParameters().toRequestParameters(); if (reqParams != null) { url.append("?"); int i = 0; for (Map.Entry<String, String> entry : reqParams.entrySet()) { if (i > 0) url.append("&"); url.append(entry.getKey()).append("=").append(entry.getValue()); i++; } } httpMethod = org.springframework.http.HttpMethod.GET; break; case POST: { httpMethod = org.springframework.http.HttpMethod.POST; break; } case PUT: { httpMethod = org.springframework.http.HttpMethod.PUT; break; } case DELETE: { httpMethod = org.springframework.http.HttpMethod.DELETE; break; } } if (resulTypetOverride == null) { ResponseEntity<R_IMPL> res = restTemplate.exchange(url.toString(), httpMethod, getRequestEntity(client.getUserAgent(), command.getParameters(), token), resultType); if (res.getStatusCode() == HttpStatus.OK) { R result = res.getBody(); command.setResults(result); command.setStatus(CommandStatus.SUCCESS); } else { command.setStatus(CommandStatus.FAILURE); } } else { ResponseEntity<R_OVER> res = restTemplate.exchange(url.toString(), httpMethod, getRequestEntity(client.getUserAgent(), command.getParameters(), token), resulTypetOverride); if (res.getStatusCode() == HttpStatus.OK) { command.setStatus(CommandStatus.SUCCESS); } else { command.setStatus(CommandStatus.FAILURE); } return res.getBody(); } return null; }
From source file:fragment.web.AccessDecisionTest.java
@Test public void testAuthenticatedUrls() { Object[][] authenticatedAccessValid = { { HttpMethod.GET, "/portal/portal/" }, { HttpMethod.GET, "/portal/portal/home" }, { HttpMethod.GET, "/portal/portal/profile" }, { HttpMethod.GET, "/portal/portal/profile/edit" }, { HttpMethod.POST, "/portal/portal/profile" }, { HttpMethod.POST, "/portal/portal/acceptCookies" }, { HttpMethod.GET, "/portal/portal/users" }, { HttpMethod.GET, "/portal/portal/users/new" }, { HttpMethod.POST, "/portal/portal/users" }, { HttpMethod.GET, "/portal/portal/users/1" }, { HttpMethod.PUT, "/portal/portal/users/1" }, { HttpMethod.GET, "/portal/portal/tenants" }, { HttpMethod.POST, "/portal/portal/tenants" }, { HttpMethod.GET, "/portal/portal/tenants/new" }, { HttpMethod.GET, "/portal/portal/tenants/1" }, { HttpMethod.GET, "/portal/portal/tenants/1/edit" }, { HttpMethod.PUT, "/portal/portal/tenants/1" }, { HttpMethod.GET, "/portal/portal/tasks/" }, { HttpMethod.GET, "/portal/portal/tasks/1/" }, { HttpMethod.GET, "/portal/portal/tasks/approval-task/1" }, { HttpMethod.POST, "/portal/portal/tasks/approval-task" } }; User user = getRootUser();/*from w ww . j a v a2 s . c o m*/ Authentication auth = createAuthenticationToken(user); verify(auth, authenticatedAccessValid, null); }
From source file:com.appglu.impl.CrudTemplateTest.java
@Test public void updateNotFound() { mockServer.expect(requestTo("http://localhost/appglu/v1/tables/user/2")).andExpect(method(HttpMethod.PUT)) .andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/crud_row_relationships"))) .andRespond(withStatus(HttpStatus.NOT_FOUND).body(compactedJson("data/error_not_found")) .headers(responseHeaders)); Row row = row();/* w ww . ja v a 2s. c om*/ boolean success = crudOperations.update("user", 2, row); Assert.assertFalse(success); mockServer.verify(); }