List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers)
From source file:com.nobu.dvdrentalweb.test.restapi.AccountRestControllerTest.java
@Test public void tesAcountsUpdate() { Account account = new Account.Builder().accountName("Savings").accountType("Gold Card").build(); HttpEntity<Account> requestEntity = new HttpEntity<>(account, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/account/create", HttpMethod.POST, 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.bailen.radioOnline.recursos.REJA.java
public Incidencia ratings(String apiKey, String rating, String idCancion, String fav) { MultiValueMap<String, String> params1 = new LinkedMultiValueMap<>(); params1.add("rating", (rating)); params1.add("idCancion", (idCancion)); params1.add("fav", (fav)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.add("Authorization", apiKey); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params1, headers); String result = new RestTemplate().postForObject("http://ceatic.ujaen.es:8075/radioapi/v2/ratings", request, String.class); try {// w w w . j a va 2 s. c o m ObjectMapper a = new ObjectMapper(); Incidencia listilla = a.readValue(result, Incidencia.class); return listilla; } catch (Exception e) { return null; } }
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.acesinc.convergentui.content.ContentFetchCommand.java
@Override protected ContentResponse run() throws Exception { log.debug("Getting live content from [ " + location + " ]"); try {/*from w w w.j a v a 2s. c o m*/ HttpServletRequest request = requestContext.getRequest(); MultiValueMap<String, String> headers = this.helper.buildZuulRequestHeaders(request); if (request.getQueryString() != null && !request.getQueryString().isEmpty()) { MultiValueMap<String, String> params = this.helper.buildZuulRequestQueryParams(request); } HttpHeaders requestHeaders = new HttpHeaders(); for (String key : headers.keySet()) { for (String s : headers.get(key)) { requestHeaders.add(key, s); } } HttpEntity requestEntity = new HttpEntity(null, requestHeaders); ResponseEntity<Object> exchange = this.restTemplate.exchange(location, HttpMethod.GET, requestEntity, Object.class); ContentResponse response = new ContentResponse(); response.setContent(exchange.getBody()); response.setContentType(exchange.getHeaders().getContentType()); response.setError(false); return response; } catch (Exception e) { log.debug("Error fetching live content from [ " + location + " ]", e); throw e; } }
From source file:rest.ApplianceRestController.java
public void testApplianceUpdate() { // 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 Appliance app = new Appliance.Builder("samTv003").brand("samsung").descrip("UHDTV").Build(); HttpEntity<Appliance> requestEntity = new HttpEntity<>(app, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/app/create", HttpMethod.POST, 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.trustedanalytics.h2oscoringengine.publisher.steps.RegisteringInApplicationBrokerStep.java
public CreatingPlanVisibilityStep register(BasicAuthServerCredentials appBrokerCredentials, RestTemplate appBrokerRestTemplate, String serviceName, String serviceDescription) { LOGGER.info("Registering service " + serviceName + " in application-broker"); String requestBody = prepareAppBrokerJsonRequest(serviceName, serviceDescription); HttpHeaders headers = HttpCommunication.basicAuthJsonHeaders(appBrokerCredentials.getBasicAuthToken()); HttpEntity<String> request = new HttpEntity<>(requestBody, headers); String appBrokerEndpoint = appBrokerCredentials.getHost() + APP_BROKER_CATALOG_ENDPOINT; appBrokerRestTemplate.exchange(appBrokerEndpoint, HttpMethod.POST, request, String.class); return new CreatingPlanVisibilityStep(cfApiUrl, cfRestTemplate); }
From source file:org.cloudfoundry.identity.uaa.login.test.TestClient.java
public String getOAuthAccessToken(String username, String password, String grantType, String scope) { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", getBasicAuthHeaderValue(username, password)); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); postParameters.add("grant_type", grantType); postParameters.add("client_id", username); postParameters.add("scope", scope); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, headers);//from w ww. j ava 2s . c o m ResponseEntity<Map> exchange = restTemplate.exchange(baseUrl + "/oauth/token", HttpMethod.POST, requestEntity, Map.class); return exchange.getBody().get("access_token").toString(); }
From source file:eu.impress.impressplatform.Application.java
@Override public void run(String... strings) throws Exception { String bedavailability;/* w w w .j av a 2s .c o m*/ String bedavailabilityDEEnvelope; String bedavailabilityDE; String bedavailabilityJSON; /*RESTManager r = new RESTManager(); String s = r.consumePopulation();*/ //get HAVE String bedavailability = b.getBedAvailablityHAVE(""); //get DE String bedavailabilityDEEnvelope = b.createBedAvailabilityDE(); //encapsulate in DE bedavailabilityDE = b.getBedAvailabilityEDXLDE(bedavailabilityDEEnvelope, bedavailability); //produce json message bedavailabilityJSON = b.forwardBedAvailability(bedavailabilityDE); log.info("Json message: " + bedavailabilityJSON); //push message to EMCR RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(bedavailabilityJSON, headers); String answer = restTemplate.postForObject(EMCRUrl, entity, String.class); log.info("EMCR response: " + answer); //log.info("Current message: " + bedavailabilityJSON); }
From source file:org.intermine.app.net.request.post.CreateGenesList.java
@Override public Void loadDataFromNetwork() throws Exception { RestTemplate rtp = getRestTemplate(); HttpHeaders headers = getHeaders();/*from ww w .j a v a 2 s. com*/ String uriString = getUrl(); Map<String, ?> params = getUrlParams(); String post = generateBody(); HttpEntity<?> req; if (null != post) { req = new HttpEntity<Object>(post, headers); } else { req = new HttpEntity<String>(headers); } ResponseEntity<String> res; String uri = Uris.expandQuery(uriString, params); rtp.exchange(uri, POST, req, String.class); return null; }
From source file:org.kurento.repository.test.RangeGetTests.java
@Test public void test() throws Exception { String id = "logo.png"; RepositoryItem item;//from w w w . ja va 2 s . c o m try { item = getRepository().findRepositoryItemById(id); } catch (NoSuchElementException e) { item = getRepository().createRepositoryItem(id); uploadFile(new File("test-files/" + id), item); } RepositoryHttpPlayer player = item.createRepositoryHttpPlayer(); String url = player.getURL(); player.setAutoTerminationTimeout(100000); // Following sample // http://stackoverflow.com/questions/8293687/sample-http-range-request-session RestTemplate httpClient = getRestTemplate(); { HttpHeaders requestHeaders = new HttpHeaders(); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertTrue("The server doesn't accept ranges", response.getHeaders().containsKey("Accept-ranges")); assertTrue("The server doesn't accept ranges with bytes", response.getHeaders().get("Accept-ranges").contains("bytes")); } long fileLength = 0; { // Range: bytes=0- HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Range", "bytes=0-"); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertEquals("The server doesn't respond with http status code 206 to a request with ranges", HttpStatus.PARTIAL_CONTENT, response.getStatusCode()); fileLength = Long.parseLong(response.getHeaders().get("Content-Length").get(0)); } { HttpHeaders requestHeaders = new HttpHeaders(); long firstByte = fileLength - 3000; long lastByte = fileLength - 1; long numBytes = lastByte - firstByte + 1; requestHeaders.set("Range", "bytes=" + firstByte + "-" + lastByte); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertEquals("The server doesn't respond with http status code 206 to a request with ranges", response.getStatusCode(), HttpStatus.PARTIAL_CONTENT); long responseContentLength = Long.parseLong(response.getHeaders().get("Content-Length").get(0)); assertEquals("The server doesn't send the requested bytes", numBytes, responseContentLength); assertEquals("The server doesn't send the requested bytes", responseContentLength, response.getBody().length); } }