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:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java
@Override public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(file != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final String checkSum = createCheckSum(file); final List<NameValuePair> params = Arrays .asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) }); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), UPLOAD_PATH, params);// www . j a v a 2 s. c o m final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("application/zip")); final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getBody().trim(); } else { throw new ResponseStatusException( "HttpStatus " + status.toString() + " response received. File upload failed."); } }
From source file:com.cemeterylistingswebtest.test.rest.RegistrationControllerTest.java
@Test(enabled = false, dependsOnMethods = "testCreate") public void testClubUpdate() { // LEFT AS AN EXERCISE FOR YOU // GET THE CLUB and THEN CHANGE AND MAKE A COPY //THEN SEND TO THE SERVER USING A PUT OR POST // THEN READ BACK TO SEE IF YOUR CHANGE HAS HAPPENED Long me = new Long(17); Subscriber oldsub = cs.find(me);/* ww w .j a v a 2s . co m*/ Subscriber updatesub = new Subscriber.Builder().Subscriber(oldsub).setUsername("newname").build(); repo.save(updatesub); id = updatesub.getSubscriberID(); HttpEntity<Subscriber> requestEntity = new HttpEntity<>(updatesub, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/Registration/update", HttpMethod.PUT, requestEntity, String.class); System.out.println(" THE RESPONSE BODY " + responseEntity.getBody()); System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode()); System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders()); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); }
From source file:org.cloudfoundry.identity.uaa.integration.VmcUserIdTranslationEndpointIntegrationTests.java
@BeforeOAuth2Context @OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class) public void setUpUserAccounts() { // If running against vcap we don't want to run these tests because they create new user accounts // Assume.assumeTrue(!testAccounts.isProfileActive("vcap")); RestOperations client = serverRunning.getRestTemplate(); ScimUser user = new ScimUser(); user.setUserName(JOE);/*from w w w. j av a 2 s . co m*/ user.setName(new ScimUser.Name("Joe", "User")); user.addEmail("joe@blah.com"); user.setGroups(Arrays.asList(new Group(null, "uaa.user"), new Group(null, "orgs.foo"))); ResponseEntity<ScimUser> newuser = client.postForEntity(serverRunning.getUrl(userEndpoint), user, ScimUser.class); joe = newuser.getBody(); assertEquals(JOE, joe.getUserName()); PasswordChangeRequest change = new PasswordChangeRequest(); change.setPassword("password"); 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.OK, result.getStatusCode()); // The implicit grant for vmc requires extra parameters in the authorization request context.setParameters(Collections.singletonMap("credentials", testAccounts.getJsonCredentials(joe.getUserName(), "password"))); }
From source file:org.zalando.boot.etcd.EtcdClientTest.java
@Test public void put() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .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"); Assert.assertNotNull("response", response); server.verify();/*from w ww.j a v a2 s. co m*/ }
From source file:com.cemeterylistingswebtest.test.rest.DisplayDeceasedControllerTest.java
@Test(enabled = false, dependsOnMethods = "testCreate") public void testClubUpdate() { // LEFT AS AN EXERCISE FOR YOU // GET THE CLUB and THEN CHANGE AND MAKE A COPY //THEN SEND TO THE SERVER USING A PUT OR POST // THEN READ BACK TO SEE IF YOUR CHANGE HAS HAPPENED Long me = new Long(17); PublishedDeceasedListing oldpdl = cs.find(me); PublishedDeceasedListing updatepdl = new PublishedDeceasedListing.Builder().PublishedDeceasedListing(oldpdl) .setGender("male").build(); repoList.save(updatepdl);//ww w . j av a 2 s. co m id = updatepdl.getPublishedListingID(); HttpEntity<PublishedDeceasedListing> requestEntity = new HttpEntity<>(updatepdl, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/DeceasedListing/update", HttpMethod.PUT, requestEntity, String.class); System.out.println(" THE RESPONSE BODY " + responseEntity.getBody()); System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode()); System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders()); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); }
From source file:org.avidj.zuul.client.ZuulRestClient.java
@Override public boolean lock(String sessionId, List<String> path, LockType type, LockScope scope) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); Map<String, String> parameters = new HashMap<>(); parameters.put("id", sessionId); // set the session id UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(serviceUrl + lockPath(path)) .queryParam("t", type(type)).queryParam("s", scope(scope)); ResponseEntity<String> result = restTemplate.exchange(uriBuilder.build().encode().toUri(), HttpMethod.PUT, entity, String.class); LOG.info(result.toString());/*from w w w. ja va 2s . co m*/ HttpStatus code = result.getStatusCode(); return code.equals(HttpStatus.CREATED); }
From source file:com.expedia.seiso.SeisoWebSecurityConfig.java
@Override protected void configure(HttpSecurity http) throws Exception { // @formatter:off http/* www . ja v a2 s . co m*/ // TODO Would prefer to do this without sessions if possible. But see // https://spring.io/guides/tutorials/spring-security-and-angular-js/ // http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-sticky-sessions.html // .sessionManagement() // .sessionCreationPolicy(SessionCreationPolicy.STATELESS) // .and() .authorizeRequests().antMatchers(HttpMethod.GET, "/internal/**").permitAll() .antMatchers(HttpMethod.GET, "/api/**").permitAll().antMatchers(HttpMethod.POST, "/api/**") .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.PUT, "/api/**") .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.DELETE, "/api/**") .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.PATCH, "/api/**") .hasAnyRole(Roles.USER, Roles.ADMIN) // Admin console .antMatchers(HttpMethod.GET, "/admin").hasRole(Roles.ADMIN).antMatchers(HttpMethod.GET, "/admin/**") .hasRole(Roles.ADMIN) // Blacklist .anyRequest().denyAll() // .anyRequest().hasRole(Roles.USER) .and().httpBasic().authenticationEntryPoint(entryPoint()).and().exceptionHandling() .authenticationEntryPoint(entryPoint()).and() // FIXME Enable. See https://spring.io/guides/tutorials/spring-security-and-angular-js/ .csrf().disable(); // @formatter:on }
From source file:com.cemeterylistingswebtest.test.rest.SearchSurnameControllerTest.java
@Test(enabled = false, dependsOnMethods = "testCreate") public void testClubUpdate() { // LEFT AS AN EXERCISE FOR YOU // GET THE CLUB and THEN CHANGE AND MAKE A COPY //THEN SEND TO THE SERVER USING A PUT OR POST // THEN READ BACK TO SEE IF YOUR CHANGE HAS HAPPENED Long me = new Long(17); PublishedDeceasedListing oldpdl = cs.find(me); PublishedDeceasedListing updatepdl = new PublishedDeceasedListing.Builder().PublishedDeceasedListing(oldpdl) .setGender("male").build(); repoList.save(updatepdl);/*from w ww . j a v a2 s.c o m*/ id = updatepdl.getPublishedListingID(); HttpEntity<PublishedDeceasedListing> requestEntity = new HttpEntity<>(updatepdl, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/SearchSurname/update", HttpMethod.PUT, requestEntity, String.class); System.out.println(" THE RESPONSE BODY " + responseEntity.getBody()); System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode()); System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders()); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); }
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategyTest.java
@Test public void testTriggerDataLoad() throws IOException, URISyntaxException, ResponseStatusException { final URI location = new URI( "https://my.eu1.fredhopperservices.com:443/fas:test1/trigger/load-data/2001-01-01_21-12-21"); mockServer.expect(requestTo("https://my.eu1.fredhopperservices.com:443/fas:test1/trigger/load-data")) .andExpect(method(HttpMethod.PUT)).andRespond(withCreatedEntity(location)); final URI response = strategy.triggerDataLoad(config, "data-id=00987123"); Assert.assertEquals(location, response); }
From source file:io.bosh.client.internal.AbstractSpringOperations.java
protected final <T, R> Observable<ResponseEntity<R>> exchangeForEntity(T request, Class<R> responseType, HttpHeaders headers, HttpMethod method, Consumer<UriComponentsBuilder> builderCallback) { return createObservable(() -> { UriComponentsBuilder builder = UriComponentsBuilder.fromUri(this.root); builderCallback.accept(builder); URI uri = builder.build().toUri(); RequestEntity<T> requestEntity = new RequestEntity<T>(request, headers, HttpMethod.PUT, uri); this.logger.debug("{} {}", method, uri); return this.restOperations.exchange(requestEntity, responseType); });//from www. j a v a 2s . c om }