List of usage examples for org.springframework.web.client RestTemplate RestTemplate
public RestTemplate()
From source file:org.zalando.riptide.NestedDispatchTest.java
public NestedDispatchTest() { final RestTemplate template = new RestTemplate(); final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); converter.setObjectMapper(new ObjectMapper().findAndRegisterModules()); template.setMessageConverters(singletonList(converter)); template.setErrorHandler(new PassThroughResponseErrorHandler()); this.server = MockRestServiceServer.createServer(template); this.unit = Rest.create(template); }
From source file:com.brightcove.zencoder.client.ZencoderClient.java
public ZencoderClient(String api_key) { this.api_key = api_key; this.api_url = API_URL; this.rt = new RestTemplate(); this.mapper = createObjectMapper(); }
From source file:nl.surfnet.coin.api.service.JanusClientDetailsServiceTest.java
@Before public void init() throws URISyntaxException { service = new JanusClientDetailsService(); restClient = new JanusRestClient(); RestTemplate restTemplate = new RestTemplate(); List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(); converters.add(new MappingJacksonHttpMessageConverter()); restTemplate.setMessageConverters(converters); restClient.setJanusUri(new URI("http://localhost:8088/janus/services/rest/")); restClient.setSecret("secret"); restClient.setUser("user"); restClient.setRestTemplate(restTemplate); service.setJanus(restClient);//from ww w . j a v a2 s.co m }
From source file:currency.converter.openexchangerate.OpenExchangeCurrencyConverter.java
/** * Retrieves latest exchange rates from <a href="https://openexchangerates.org">OpenExchangeRates</a> by using * REST template. Retrieved rates are stored as search history for the specific user. * /* w ww . j a v a 2 s .c o m*/ * @param baseCurrency Base currency for exchange rates * @param amount Amount * * @return {@link CurrencyRateModel} * * @throws InvalidParameterException for invalid arguments */ public CurrencyRateModel getLatestCurrencyRates(String baseCurrency, double amount) throws InvalidParameterException { if (StringUtils.isNullOrEmpty(baseCurrency)) { baseCurrency = SupportedCurrencies.USD.name(); } if (amount <= ZERO) { amount = MINIMUM_AMOUNT; } StringBuilder builder = new StringBuilder(); String apiKey = configuration.getOpenExchangeApiKey(); builder.append("https://openexchangerates.org/api/latest.json?app_id=").append(apiKey).append("&base=") .append(baseCurrency); boolean isCommercialApi = configuration.isOpenExchangeCommercialLicense(); if (isCommercialApi) { builder.append(getTargetCurrencies(baseCurrency)); } logger.info("Latest rate API URL : " + builder.toString()); RestTemplate restTemplate = new RestTemplate(); CurrencyRateModel rates = restTemplate.getForObject(builder.toString(), CurrencyRateModel.class); multiplyAmount(rates, amount, baseCurrency); logger.info(rates.toString()); // save currency history String userName = userService.getLoggedInUserName(); saveExchangeRate(rates, baseCurrency, amount, LocalDate.now(), userName); return rates; }
From source file:com.bytebybyte.mapquest.geocoding.service.standard.MapQuestTest.java
@Test public void testGetBasicSearch() { RestTemplate restTemplate = new RestTemplate(); String ADDRESS = "http://open.mapquestapi.com/nominatim/v1/search.php?format=json&"; String callback = "q=windsor+[castle]&addressdetails=1&limit=3&"; String viewbox = "viewbox=-1.99%2C52.02%2C0.78%2C50.94&exclude_place_ids=41697"; String url = ADDRESS + callback + viewbox; String result = restTemplate.getForObject(url, String.class); System.out.println("Result : " + result); JsonElement jelement = new JsonParser().parse(result); JsonArray jsonArray = jelement.getAsJsonArray(); JsonObject jo = jsonArray.get(0).getAsJsonObject(); System.out.println("Place Id : " + jo.get("place_id")); System.out.println("License : " + jo.get("licence")); System.out.println("OSM Type : " + jo.get("osm_type")); System.out.println("OSM ID : " + jo.get("osm_id")); System.out.println("BoundingBox : " + jo.get("boundingbox")); System.out.println("Lat : " + jo.get("lat")); System.out.println("lon : " + jo.get("lon")); System.out.println("type : " + jo.get("type")); System.out.println("Importance : " + jo.get("importance")); System.out.println("Icon : " + jo.get("icon")); System.out.println("Address : " + jo.get("address")); jo = jo.getAsJsonObject("address"); System.out.println("--------------------------------"); System.out.println("Castle : " + jo.get("castle")); System.out.println("Path : " + jo.get("path")); System.out.println("Neighbourhood : " + jo.get("neighbourhood")); System.out.println("Suburb : " + jo.get("suburb")); System.out.println("Town : " + jo.get("town")); System.out.println("State_District : " + jo.get("state_district")); System.out.println("State : " + jo.get("state")); System.out.println("Postcode : " + jo.get("postcode")); System.out.println("Country : " + jo.get("country")); System.out.println("Country_code : " + jo.get("country_code")); }
From source file:io.syndesis.inspector.DataMapperClassInspectorTest.java
@Test public void shouldExtractClassName() throws Exception { DataMapperClassInspector dataMapperClassInspector = new DataMapperClassInspector(infinispan.getCaches(), new RestTemplate(), config); Assert.assertEquals("Status", dataMapperClassInspector.getClassName("Status")); Assert.assertEquals("Status", dataMapperClassInspector.getClassName("twitter4j.Status")); Assert.assertEquals("Status", dataMapperClassInspector.getClassName("more.twitter4j.Status")); }
From source file:comsat.sample.tomcat.SampleTomcatTwoConnectorsApplicationTests.java
@Test public void testHello() throws Exception { RestTemplate template = new RestTemplate(); final MySimpleClientHttpRequestFactory factory = new MySimpleClientHttpRequestFactory( new HostnameVerifier() { @Override//w ww .j a va 2s . c o m public boolean verify(final String hostname, final SSLSession session) { return true; // these guys are alright by me... } }); template.setRequestFactory(factory); ResponseEntity<String> entity = template.getForEntity("http://localhost:" + this.port + "/hello", String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals("hello", entity.getBody()); ResponseEntity<String> httpsEntity = template .getForEntity("https://localhost:" + this.context.getBean("port") + "/hello", String.class); assertEquals(HttpStatus.OK, httpsEntity.getStatusCode()); assertEquals("hello", httpsEntity.getBody()); }
From source file:minium.cucumber.rest.RemoteBackend.java
public RemoteBackend(String baseUrl) { this(baseUrl, new RestTemplate()); }
From source file:org.apigw.authserver.web.controller.MonitoringController.java
@RequestMapping(method = RequestMethod.GET, params = { "clientId", "state" }) public ModelAndView list(@RequestParam("clientId") String clientId, @RequestParam("state") String state, Authentication authentication) { Application application = appManagement.getApplicationByClientId(clientId); UserDetails user = (UserDetails) authentication.getPrincipal(); if (application == null) { throw new IllegalArgumentException("No application found with client id " + clientId); }/* w ww.j ava 2 s . co m*/ if (!user.getUsername().equals(application.getDeveloper().getResidentIdentificationNumber())) { throw new IllegalArgumentException("Application developer is not the same as the logged in user"); } if (!state.toUpperCase().equals("SERVER_FAILURE") && !state.toUpperCase().equals("CLIENT_FAILURE") && !state.toUpperCase().equals("SUCCESS")) { throw new IllegalArgumentException("Provided state not recogonized: " + state); } TreeMap<String, Object> model = new TreeMap<String, Object>(); RestTemplate template = new RestTemplate(); long from = System.currentTimeMillis() - 24 * 3600 * 1000; Map<String, Object> params = new HashMap<String, Object>(); params.put("from", from); params.put("client", clientId); params.put("state", state); // Load list of last 100 failed requests List<Map<String, Object>> requests = template.getForObject( location + "/api/timeline/resourceRequest?from={from}&state={state}&client={client}", List.class, params); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (Map<String, Object> request : requests) { long timestamp = (Long) request.get("timestamp"); Date date = new Date(timestamp); request.put("datetime", format.format(date)); } model.put("requests", requests); model.put("client", clientId); model.put("state", state); return new ModelAndView("monitoring", model); }
From source file:edu.teilar.jcrop.service.client.controller.KObjectsClientController.java
@RequestMapping(value = "/kobjects", method = RequestMethod.GET) public String getKObjects(Model model) { RestTemplate restTemplate = new RestTemplate(); String url = ClientUrls.SERVERADDRESS + ApiUrls.KOBJECTS_URL; List<KObject> kobjects = (List<KObject>) restTemplate.getForObject(url, List.class); model.addAttribute("kobjects", kobjects); return "kobjects"; }