List of usage examples for org.springframework.web.client RestTemplate RestTemplate
public RestTemplate()
From source file:dk.skogemann.airline.project.ApiController.java
@RequestMapping(value = "/reservation/{flightId}", method = RequestMethod.POST) @ResponseBody/* w w w . ja v a 2 s. c om*/ public ReservationResponse bookFlight(@PathVariable("flightId") String flightId, @RequestBody Reservation reservation) { String url = "http://angularairline-plaul.rhcloud.com/api/flightreservation"; System.out.println("kalder remote"); RestTemplate template = new RestTemplate(); ResponseEntity<ReservationResponse> postForEntity = template.postForEntity(url, reservation, ReservationResponse.class); System.out.println(postForEntity); System.out.println("bookFlight apicontroller"); return postForEntity.getBody(); }
From source file:org.n52.tamis.rest.forward.processes.jobs.DeleteRequestForwarder.java
/** * {@inheritDoc} <br/>// w ww .j a va 2 s. co m * <br/> * Delegates an incoming delete request to the WPS proxy. * * @param parameterValueStore * must contain the URL variable * {@link URL_Constants_TAMIS#SERVICE_ID_VARIABLE_NAME} to * identify the WPS instance and * {@link URL_Constants_TAMIS#PROCESS_ID_VARIABLE_NAME} to * identify the process and * {@link URL_Constants_TAMIS#JOB_ID_VARIABLE_NAME} to identify * the job and * @return */ @Override public <T> ResponseEntity forwardRequestToWpsProxy(HttpServletRequest request, T requestBody, ParameterValueStore parameterValueStore) { initializeRequestSpecificParameters(parameterValueStore); String delete_url_wpsProxy = createTargetURL_WpsProxy(request); RestTemplate deleteTemplate = new RestTemplate(); // TODO does that really work this way? // resultTemplate.delete(delete_url_wpsProxy); deleteTemplate.delete(delete_url_wpsProxy); return new ResponseEntity(HttpStatus.OK); }
From source file:com.bailen.radioOnline.recursos.REJA.java
public Cancion[] random(String apiKey) throws IOException { HttpHeaders header = new HttpHeaders(); header.set("Authorization", apiKey); HttpEntity entity = new HttpEntity(header); String lista = new String(); HttpEntity<String> response; response = new RestTemplate().exchange("http://ceatic.ujaen.es:8075/radioapi/v2/random", HttpMethod.GET, entity, String.class, lista); String canc = response.getBody(); StringTokenizer st = new StringTokenizer(canc, "[", true); st.nextToken();// www .j a v a2 s.com st.nextToken(); canc = "[" + st.nextToken(); try { ObjectMapper a = new ObjectMapper(); Item[] listilla = a.readValue(canc, Item[].class); Vector<Integer> ids = new Vector<>(); for (int i = 0; i < listilla.length; ++i) { ids.add(listilla[i].getId()); } return jamendo.canciones(ids); } catch (Exception e) { //return null; throw new IOException("no se han recibido canciones"); } }
From source file:org.client.one.service.OAuthAuthenticationService.java
public String loginApp() throws JSONException { RestOperations rest = new RestTemplate(); String resAuth = rest.postForObject(oauthServerBaseURL + "/oauth/token?client_id=" + appToken + "&client_secret=" + appPassword + "&grant_type=client_credentials", null, String.class); System.out.println(resAuth);// w w w . ja v a 2 s. c om JSONObject resJsA = new JSONObject(resAuth); return resJsA.getString("access_token"); }
From source file:org.trustedanalytics.servicecatalog.security.SecurityConfig.java
@Bean public JwtAccessTokenConverter myjwtTokenEnhancer() { JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter(); DefaultUserAuthenticationConverter userTokenConverter = new JwtUserDetailsTokenConverter(); accessTokenConverter.setUserTokenConverter(userTokenConverter); converter.setAccessTokenConverter(accessTokenConverter); String keyValue = resource.getJwt().getKeyValue(); if (!StringUtils.hasText(keyValue)) { try {/*from w w w .j ava2s . co m*/ keyValue = (String) new RestTemplate().getForObject(resource.getJwt().getKeyUri(), Map.class) .get("value"); } catch (ResourceAccessException e) { throw new TokenFetchException("Failed to fetch token key from " + resource.getJwt().getKeyUri(), e); } } else { if (StringUtils.hasText(keyValue) && !keyValue.startsWith("-----BEGIN")) { converter.setSigningKey(keyValue); } } converter.setVerifierKey(keyValue); return converter; }
From source file:com.auditbucket.client.AbRestClient.java
public String ping() { RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); HttpHeaders httpHeaders = getHeaders(userName, password); HttpEntity requestEntity = new HttpEntity<>(httpHeaders); try {/*w ww .j av a2s.c o m*/ ResponseEntity<String> response = restTemplate.exchange(PING, HttpMethod.GET, requestEntity, String.class); return response.getBody(); } catch (HttpClientErrorException e) { // ToDo: Rest error handling pretty useless. need to know why it's failing logger.error("AB Client Audit error {}", getErrorMessage(e)); return "err"; } catch (HttpServerErrorException e) { logger.error("AB Server Audit error {}", getErrorMessage(e)); return "err"; } }
From source file:com.citibanamex.api.locator.atm.service.impl.AtmServiceImpl.java
/** * This method first takes the address and gets lat lng cordinates of it and * then passes to the google places url along with radius to get list of * banamex atms and branches nearby. We must need API KEY to access google * places APIs.By default Google places limits search to 20 objects, but we * can fetch more than 20 by passing next page token to same url which we * get from first call./*from w w w .j av a2s .c om*/ * * @param radius * @param addressLine1 * @param addressLine2 * @param nextStartIndex * @return list of CitiBanamex ATMs/Branches * @throws InterruptedException */ public List<ATM> getNearByAtmsOrBranches(String radius, String addressLine1, String addressLine2, String nextStartIndex) throws InterruptedException { String address = addressLine1 + " " + addressLine2; RestTemplate restTemplate = new RestTemplate(); Location location = new Location(); List<ATM> atmsList = new ArrayList<ATM>(); GooglePlaces response = null; Results[] resultList = null; StringBuffer imgURL = new StringBuffer(PHOTO_REF_URL); StringBuffer GEO_CODE_URI = new StringBuffer(GEO_CODE_URL); GEO_CODE_URI.append(address); GEO_CODE_URI.append(API_KEY_VALUE); log.info("****************GEO_CODE_URI****************" + GEO_CODE_URI); GeoCodeResponse cordinates = restTemplate.getForObject(GEO_CODE_URI.toString(), GeoCodeResponse.class); com.citibanamex.api.locator.atm.model.geocode.Results[] results = cordinates.getResults(); for (com.citibanamex.api.locator.atm.model.geocode.Results result : results) { location = result.getGeometry().getLocation(); location.setLat(location.getLat()); location.setLng(location.getLng()); } log.info("****Geocode coordinates for a given address : " + address + ", location: " + location.getLat() + "," + location.getLng()); StringBuffer googlePlacesURI = new StringBuffer(GOOGLE_PLACES_URL); googlePlacesURI.append(KEY_WORD); googlePlacesURI.append(API_KEY_VALUE); googlePlacesURI.append(LOCATION); googlePlacesURI.append(location.getLat()); googlePlacesURI.append(COMMA); googlePlacesURI.append(location.getLng()); googlePlacesURI.append(RADIUS); googlePlacesURI.append(radius); if (nextStartIndex != null) { googlePlacesURI.append(NEXT_START_INDEX); googlePlacesURI.append(nextStartIndex); } response = restTemplate.getForObject(googlePlacesURI.toString(), GooglePlaces.class); resultList = response.getResults(); String next_page_token = response.getNext_page_token(); log.info("****************googlePlacesURI****************" + googlePlacesURI); atmsList = getATMsList(atmsList, resultList, imgURL, next_page_token); log.info("*****List of nearby Banamex atms/branches list returning : " + atmsList.size()); return atmsList; }
From source file:eu.falcon.semantic.client.DenaClient.java
public static String getClassSubclasses(String classURI) { final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/class/subclasses"; //final String uri = "http://localhost:8090/api/v1/ontology/class/subclasses"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); RestTemplate restTemplate = new RestTemplate(); HttpEntity<String> entity = new HttpEntity<>(classURI, headers); String result = restTemplate.postForObject(uri, entity, String.class); return result; }
From source file:features.steps.APISteps.java
@Ignore @When("^I POST \\/espi\\/1_1\\/resource\\/RetailCustomer\\/\\{RetailCustomerID\\}\\/UsagePoint$") public void I_POST_espi_1_1_resource_RetailCustomer_RetailCustomerID_UsagePoint() throws Throwable { RestTemplate rest = new RestTemplate(); String response = rest.postForObject( StepUtils.DATA_CUSTODIAN_BASE_URL + "/espi/1_1/resource/RetailCustomer/1/UsagePoint", "<entry xmlns=\"http://www.w3.org/2005/Atom\">>" + " <id>urn:uuid:97EAEBAD-1214-4A58-A3D4-A16A6DE718E1</id>" + " <published>2012-10-24T00:00:00Z</published>" + " <updated>2012-10-24T00:00:00Z</updated>" + " <link rel=\"self\"" + " href=\"/espi/1_1/resource/RetailCustomer/1/UsagePoint/97EAEBAD-1214-4A58-A3D4-A16A6DE718E1\"/>" + " <link rel=\"up\"" + " href=\"/espi/1_1/resource/RetailCustomer/1/UsagePoint\"/>" + " <link rel=\"related\"" + " href=\"/espi/1_1/resource/RetailCustomer/1/UsagePoint/97EAEBAD-1214-4A58-A3D4-A16A6DE718E1/MeterReading\"/>" + " <link rel=\"related\"" + " href=\"/espi/1_1/resource/RetailCustomer/1/UsagePoint/97EAEBAD-1214-4A58-A3D4-A16A6DE718E1/ElectricPowerUsageSummary\"/>" + " <link rel=\"related\"" + " href=\"/espi/1_1/resource/UsagePoint/01/LocalTimeParameters/01\"/>" + " <title>Created</title>" + " <content>" + " <UsagePoint xmlns=\"http://naesb.org/espi\">" + " <ServiceCategory>" + " <kind>0</kind>" + " </ServiceCategory>" + " </UsagePoint>" + " </content>" + "</entry>", String.class); assertThat(response, is(nullValue())); }