List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers)
From source file:org.cloudfoundry.identity.uaa.integration.VmcScimUserEndpointIntegrationTests.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 a v a 2s. co m*/ user.setName(new ScimUser.Name("Joe", "User")); user.addEmail("joe@blah.com"); ResponseEntity<ScimUser> newuser = client.postForEntity(serverRunning.getUrl(usersEndpoint), 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(usersEndpoint) + "/{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:cz.cvut.jirutjak.fastimport.droid.oauth2.DefaultAccessTokenProvider.java
protected HttpEntity<MultiValueMap<String, String>> createAccessTokenRequestEntity( MultiValueMap<String, String> formData) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); return new HttpEntity<MultiValueMap<String, String>>(formData, headers); }
From source file:com.ge.predix.test.utils.PolicyHelper.java
public CreatePolicyStatus createPolicySet(final String policyFile, final RestTemplate restTemplate, final HttpHeaders headers) { PolicySet policySet;//from w w w . j a v a2 s .c o m try { policySet = new ObjectMapper().readValue(new File(policyFile), PolicySet.class); String policyName = policySet.getName(); restTemplate.put(zoneHelper.getAcsBaseURL() + ACS_POLICY_SET_API_PATH + policyName, new HttpEntity<>(policySet, headers)); return CreatePolicyStatus.SUCCESS; } catch (IOException e) { return CreatePolicyStatus.JSON_ERROR; } catch (HttpClientErrorException httpException) { return httpException.getStatusCode() != null && httpException.getStatusCode().equals(HttpStatus.UNPROCESSABLE_ENTITY) ? CreatePolicyStatus.INVALID_POLICY_SET : CreatePolicyStatus.ACS_ERROR; } catch (RestClientException e) { return CreatePolicyStatus.ACS_ERROR; } }
From source file:org.akaademiwolof.ConfigurationTests.java
@SuppressWarnings("static-access") //@Test/*from w w w . j a v a 2 s . c o m*/ public void shouldUpdateWordWhenSendingRequestToController() throws Exception { HttpHeaders headers = new HttpHeaders(); JSONObject requestJson = new JSONObject(); requestJson.wrap(json); System.out.print(requestJson.toString()); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(json, headers); ResponseEntity<String> loginResponse = restTemplate.exchange(localhostUrl, HttpMethod.POST, entity, String.class); if (loginResponse.getStatusCode() == HttpStatus.OK) { JSONObject wordJson = new JSONObject(loginResponse.getBody()); System.out.print(loginResponse.getStatusCode()); assertThat(wordJson != null); } else if (loginResponse.getStatusCode() == HttpStatus.BAD_REQUEST) { System.out.print(loginResponse.getStatusCode()); } }
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);/*from www . j a va 2 s .c om*/ 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:io.getlime.push.service.fcm.FcmClient.java
/** * Send given FCM request to the server. * @param request FCM data request.//from w w w .j a v a 2 s . c o m * @return Listenable future for result callbacks. */ public ListenableFuture<ResponseEntity<FcmSendResponse>> exchange(FcmSendRequest request) { HttpEntity<FcmSendRequest> entity = new HttpEntity<>(request, headers); return restTemplate.exchange(fcm_url, HttpMethod.POST, entity, FcmSendResponse.class); }
From source file:com.logaritex.hadoop.configuration.manager.http.AndroidHttpService.java
public <R> R put(String url, Object request, Class<R> responseType, Object... uriVariables) { R response = restTemplate.exchange(baseUrl + url, HttpMethod.PUT, new HttpEntity<Object>(request, httpHeaders), responseType, uriVariables).getBody(); return response; }
From source file:com.expedia.client.WunderGroundClient.java
@Override public ResponseEntity<ResponseWrapper> getJSONResponse(Object request) { ResponseEntity<ResponseWrapper> responseEntity = null; Weather weather = null;//from w ww . j ava2 s .c om if (request instanceof Weather) { weather = (Weather) request; List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.APPLICATION_JSON); HttpHeaders headers = new HttpHeaders(); headers.setAccept(mediaTypes); HttpEntity<Weather> httpEntity = new HttpEntity<Weather>(null, headers); try { System.out.println("Hitting weather service for JSON response!"); responseEntity = restTemplate.exchange(weatherServiceJsonUrl, HttpMethod.GET, httpEntity, ResponseWrapper.class, weatherApiKey, weather.getZipCode()); } catch (RuntimeException e) { e.printStackTrace(); weather.setErrorDesc("Get failed" + e.getMessage()); } } return responseEntity; }
From source file:com.onedrive.api.resource.support.UploadSession.java
public UploadSession uploadFragment(long startIndex, long endIndex, long totalSize, byte[] data) { Assert.notNull(uploadUrl, "UploadSession instance invalid. The uploadUrl is not defined."); Assert.notNull(data, "The data is required."); MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>(); headers.add("Content-Range", "bytes " + startIndex + "-" + endIndex + "/" + totalSize); ResponseEntity<UploadSession> response = getOneDrive().getRestTemplate().exchange(uploadUri(), HttpMethod.PUT, new HttpEntity<ByteArrayResource>(new ByteArrayResource(data), headers), UploadSession.class); UploadSession session = response.getBody(); session.setUploadUrl(uploadUrl);/*www . j av a 2s .c o m*/ session.complete = response.getStatusCode().equals(HttpStatus.CREATED) || response.getStatusCode().equals(HttpStatus.OK); return session; }
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 w w.j av a 2s . 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); }