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.opensearchserver.hadse.index.IndexTest.java
@Test public void t02_createDefaultIndex() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); RestTemplate template = new RestTemplate(); ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.PUT, null, String.class); assertEquals(HttpStatus.CREATED, entity.getStatusCode()); }
From source file:org.openbaton.nfvo.vnfm_reg.impl.sender.RestVnfmSender.java
private void put(String path, String json, String url) { HttpEntity<String> requestEntity = new HttpEntity<>(json, headers); ResponseEntity<String> responseEntity = rest.exchange(url + path, HttpMethod.PUT, requestEntity, String.class); this.setStatus(responseEntity.getStatusCode()); }
From source file:net.eusashead.hateoas.response.impl.OptionsResponseBuilderImplTest.java
@Test public void testAllHeaders() throws Exception { Entity entity = new Entity("foo"); ResponseEntity<Entity> response = builder.entity(entity).allow(HttpMethod.GET, HttpMethod.PUT).build(); Assert.assertNotNull(response);//from www . ja va 2 s.co m Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); Assert.assertEquals(entity, response.getBody()); Assert.assertNotNull(response.getHeaders().getAllow()); Set<HttpMethod> allow = new HashSet<HttpMethod>(); allow.addAll(Arrays.asList(HttpMethod.GET, HttpMethod.PUT)); Assert.assertEquals(allow, response.getHeaders().getAllow()); }
From source file:com.appglu.impl.PushTemplateTest.java
@Test public void registerDevice() { mockServer.expect(requestTo("http://localhost/appglu/v1/push/device")).andExpect(method(HttpMethod.PUT)) .andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/push_device"))) .andRespond(withSuccess().headers(responseHeaders)); pushOperations.registerDevice(device()); mockServer.verify();//from w w w .j ava2 s .c om }
From source file:net.paslavsky.springrest.HttpHeadersHelperTest.java
@DataProvider public Object[][] data() { DateFormat dateFormat = createDateFormat(); final long currentTime = System.currentTimeMillis(); final String currentTimeStr = dateFormat.format(new Date(currentTime)); return new Object[][] { new Object[] { "Other", new Object[] { 123 }, "123" }, new Object[] { "Other", new Object[] { "123" }, "123" }, new Object[] { "Other", new String[] { "123" }, "123" }, new Object[] { "Other", Arrays.asList("123"), "123" }, new Object[] { "Other", "123", "123" }, new Object[] { "Accept", MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON_VALUE }, new Object[] { "Accept", Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML), MediaType.APPLICATION_JSON_VALUE + ", " + MediaType.APPLICATION_XML_VALUE }, new Object[] { "Accept-Charset", java.nio.charset.Charset.forName("UTF-8"), "utf-8" }, new Object[] { "Allow", HttpMethod.GET, "GET" }, new Object[] { "Allow", new TreeSet<HttpMethod>(Arrays.asList(HttpMethod.PUT, HttpMethod.POST)), "POST,PUT" }, new Object[] { "Connection", "close", "close" }, new Object[] { "Content-Disposition", "form-data; name=\"AttachedFile1\"; filename=\"photo-1.jpg\"", "form-data; name=\"AttachedFile1\"; filename=\"photo-1.jpg\"" }, new Object[] { "Content-Disposition", new String[] { "AttachedFile1", "photo-1.jpg" }, "form-data; name=\"AttachedFile1\"; filename=\"photo-1.jpg\"" }, new Object[] { "Content-Disposition", "AttachedFile1", "form-data; name=\"AttachedFile1\"" }, new Object[] { "Content-Length", 123l, "123" }, new Object[] { "Content-Type", MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON_VALUE }, new Object[] { "Content-Type", MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, new Object[] { "Date", currentTime, currentTimeStr }, new Object[] { "ETag", "W/\"123456789\"", "W/\"123456789\"" }, new Object[] { "Expires", currentTime, currentTimeStr }, new Object[] { "If-Modified-Since", currentTime, currentTimeStr }, new Object[] { "If-None-Match", "737060cd8c284d8af7ad3082f209582d", "737060cd8c284d8af7ad3082f209582d" }, new Object[] { "Last-Modified", currentTime, currentTimeStr }, new Object[] { "Location", "http://example.com/", "http://example.com/" }, new Object[] { "Location", URI.create("http://example.com/"), "http://example.com/" }, new Object[] { "Origin", "www.a.com", "www.a.com" }, new Object[] { "Pragma", "no-cache", "no-cache" }, new Object[] { "Upgrade", "HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11", "HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11" }, }; }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStepTest.java
@Test public void uploadBits_performsProperCloudFoundryRestCall() throws Exception { // given/*w w w. j ava 2 s . c o m*/ AppBitsUploadingStep step = new AppBitsUploadingStep(testCfApi, restTemplateMock, testAppGuid); // when step.uploadBits(testAppBitsPath); // then HttpEntity<MultiValueMap<String, Object>> testRequest = createTestAppBitsRequest(); verify(restTemplateMock).exchange(eq(cfUploadEndpoint), same(HttpMethod.PUT), eq(testRequest), same(String.class), same(testAppGuid)); }
From source file:io.syndesis.runtime.SetupITCase.java
@Test public void updateOauthApp() { // Validate initial state assumptions. getOauthApps();// w w w. j ava2s.c o m OAuthAppHandler.OAuthApp twitter = new OAuthAppHandler.OAuthApp(); twitter.clientId = "test-id"; twitter.clientSecret = "test-secret"; http(HttpMethod.PUT, "/api/v1/setup/oauth-apps/twitter", twitter, null, tokenRule.validToken(), HttpStatus.NO_CONTENT); ResponseEntity<OAuthAppHandler.OAuthApp[]> result = get("/api/v1/setup/oauth-apps", OAuthAppHandler.OAuthApp[].class); List<OAuthAppHandler.OAuthApp> apps = Arrays.asList(result.getBody()); assertThat(apps.size()).isEqualTo(2); twitter = apps.stream().filter(x -> "twitter".equals(x.id)).findFirst().get(); assertThat(twitter.id).isEqualTo("twitter"); assertThat(twitter.name).isEqualTo("Twitter"); assertThat(twitter.icon).isEqualTo("fa-twitter"); assertThat(twitter.clientId).isEqualTo("test-id"); assertThat(twitter.clientSecret).isEqualTo("test-secret"); // Now that we have configured the app, we should be able to create the connection factory. // The connection factory is setup async so we might need to wait a little bit for it to register. given().ignoreExceptions().await().atMost(10, SECONDS).pollInterval(1, SECONDS).until(() -> { final CredentialProvider twitterCredentialProvider = locator.providerWithId("twitter"); // preparing is something we could not do with a `null` ConnectionFactory assertThat(twitterCredentialProvider).isNotNull().isInstanceOfSatisfying(OAuth1CredentialProvider.class, p -> { final Connection connection = new Connection.Builder().build(); final CredentialFlowState flowState = new OAuth1CredentialFlowState.Builder() .accessToken(new OAuthToken("value", "secret")).build(); final Connection appliedTo = p.applyTo(connection, flowState); // test that the updated values are used assertThat(appliedTo.getConfiguredProperties()).contains(entry("consumerKey", "test-id"), entry("consumerSecret", "test-secret")); }); return true; }); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStep.java
public RegisteringInApplicationBrokerStep uploadBits(Path appBits) throws EnginePublicationException { prepareRestTemplateForMultipartRequest(); LOGGER.info("Uploading bits for app " + appGuid + " from " + appBits); try {/*from w w w .j av a 2 s.c o m*/ HttpEntity<MultiValueMap<String, Object>> request = prepareMutlipartRequest(appBits); String cfUploadAppUrl = cfApiUrl + APP_BITS_ENDPOINT_TEMPLATE; cfRestTemplate.exchange(cfUploadAppUrl, HttpMethod.PUT, request, String.class, appGuid); return new RegisteringInApplicationBrokerStep(appGuid, cfApiUrl, cfRestTemplate); } catch (IOException e) { throw new EnginePublicationException("Unable to read application bits from " + appBits.toString(), e); } }
From source file:cz.muni.fi.mushroomhunter.restclient.LocationUpdateSwingWorker.java
@Override protected Integer doInBackground() throws Exception { DefaultTableModel model = (DefaultTableModel) restClient.getTblLocation().getModel(); int selectedRow = restClient.getTblLocation().getSelectedRow(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);/*from ww w.j a v a 2s . c om*/ headers.setAccept(mediaTypeList); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity<>(headers); ResponseEntity<LocationDto> responseEntity = restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/location/" + RestClient.getLocationIDs().get(selectedRow), HttpMethod.GET, request, LocationDto.class); LocationDto locationDto = responseEntity.getBody(); locationDto.setName(restClient.getTfLocationName().getText()); locationDto.setDescription(restClient.getTfLocationDescription().getText()); locationDto.setNearCity(restClient.getTfLocationNearCity().getText()); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(locationDto); request = new HttpEntity(json, headers); restTemplate.exchange(RestClient.SERVER_URL + "pa165/rest/location", HttpMethod.PUT, request, LocationDto.class); return selectedRow; }
From source file:org.cloudfoundry.identity.api.web.CloudfoundryApiIntegrationTests.java
@Test public void testClientAccessesProtectedResource() throws Exception { OAuth2AccessToken accessToken = context.getAccessToken(); // add an approval for the scope requested HttpHeaders approvalHeaders = new HttpHeaders(); approvalHeaders.set("Authorization", "bearer " + accessToken.getValue()); Date oneMinuteAgo = new Date(System.currentTimeMillis() - 60000); Date expiresAt = new Date(System.currentTimeMillis() + 60000); ResponseEntity<Approval[]> approvals = serverRunning.getRestTemplate().exchange( serverRunning.getUrl("/uaa/approvals"), HttpMethod.PUT, new HttpEntity<Approval[]>((new Approval[] { new Approval(testAccounts.getUserName(), "app", "cloud_controller.read", expiresAt, ApprovalStatus.APPROVED, oneMinuteAgo), new Approval(testAccounts.getUserName(), "app", "openid", expiresAt, ApprovalStatus.APPROVED, oneMinuteAgo), new Approval(testAccounts.getUserName(), "app", "password.write", expiresAt, ApprovalStatus.APPROVED, oneMinuteAgo) }), approvalHeaders),/* w ww. j a va 2 s. co m*/ Approval[].class); assertEquals(HttpStatus.OK, approvals.getStatusCode()); // System.err.println(accessToken); // The client doesn't know how to use an OAuth bearer token CloudFoundryClient client = new CloudFoundryClient("Bearer " + accessToken.getValue(), testAccounts.getCloudControllerUrl()); CloudInfo info = client.getCloudInfo(); assertNotNull("Wrong cloud info: " + info.getDescription(), info.getUser()); }