List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers)
From source file:com.cemeterylistingswebtest.test.rest.PublishedListingController.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); Cemetery oldCemetery = cs.find(me);//from w w w . j ava 2 s . c om Cemetery updateCemetery = new Cemetery.Builder().Cemetery(oldCemetery).setContactNumber("0215554412") .build(); repo.save(updateCemetery); id = updateCemetery.getId(); HttpEntity<Cemetery> requestEntity = new HttpEntity<>(updateCemetery, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/cemetery/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.cemeterylistingswebtest.test.rest.LoginControllerTest.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);//from ww w . j a v a 2 s.c om 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/cemetery/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:am.ik.categolj2.app.authentication.AuthenticationHelper.java
public HttpEntity<MultiValueMap<String, Object>> createRopRequest(String username, String password) { MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); params.add("username", username); params.add("password", password); params.add("grant_type", "password"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); byte[] clientInfo = (adminClientProperties.getClientId() + ":" + adminClientProperties.getClientSecret()) .getBytes(StandardCharsets.UTF_8); String basic = new String(Base64.getEncoder().encode(clientInfo), StandardCharsets.UTF_8); headers.set(com.google.common.net.HttpHeaders.AUTHORIZATION, "Basic " + basic); return new HttpEntity<>(params, headers); }
From source file:com.logaritex.hadoop.configuration.manager.SimpleHttpService.java
@Override 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.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);//from w w w .j av a 2 s. c o 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.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsServiceEnabledPredefinedTests.java
@Test public void basicAuthenticationServiceTestInvalidCredentials() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + new String(Base64.encode("user:badpassword".getBytes("UTF-8")))); HttpEntity<String> entity = new HttpEntity<String>("headers", headers); ResponseEntity<AuthorizationData> responseEntity = restTemplate.exchange( "http://localhost:" + port + baseApiPath + basicAuthenticationEndpointPath, HttpMethod.POST, entity, AuthorizationData.class); assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode()); }
From source file:com.companyname.plat.commons.client.HttpRestfulClient.java
public HttpEntity<Object> getHttpRequest(Map<String, String> params) { // construct headers with login and password HttpHeaders headers = getHeaders();//from ww w. j a va 2 s. c o m // request body to send String requestBodyJSON = buildRequestJasonObject(params); // HTTP request HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBodyJSON, headers); return requestEntity; }
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);/*from w ww. j a v a2 s .c om*/ 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:com.example.ProxyAuthorizationServerTokenServices.java
@Override public OAuth2AccessToken refreshAccessToken(String refreshToken, TokenRequest tokenRequest) throws AuthenticationException { MultiValueMap<String, String> form = createForm(refreshToken, tokenRequest); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(form, createHeaders());// w ww . ja v a 2 s . com String url = properties.getAccessTokenUrl(); @SuppressWarnings("unchecked") Map<String, Object> map = restTemplate.postForEntity(url, request, Map.class).getBody(); OAuth2AccessToken token = ectractAccessToken(map); return token; }
From source file:org.messic.android.util.RestJSONClient.java
/** * Rest GET petition to the server at the url param, sending all the post parameters defiend at formData. This post * return an object (json marshalling) of class defined at clazz parameter. You should register a * {@link RestListener} in order to obtain the returned object, this is because the petition is done in an async * process./*from w w w . j a v a 2 s . c o m*/ * * @param url {@link string} URL to attack * @param clazz Class<T/> class that you will marshall to a json object * @param rl {@link RestListener} listener to push the object returned */ public static <T> void get(final String url, final Class<T> clazz, final RestListener<T> rl) { final RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); // Populate the MultiValueMap being serialized and headers in an HttpEntity object to use for the request final HttpEntity<MultiValueMap<?, ?>> requestEntity = new HttpEntity<MultiValueMap<?, ?>>( new LinkedMultiValueMap<String, Object>(), requestHeaders); AsyncTask<Void, Void, Void> at = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, clazz); rl.response(response.getBody()); } catch (Exception e) { rl.fail(e); } return null; } }; at.execute(); }