List of usage examples for org.springframework.web.client RestTemplate RestTemplate
public RestTemplate()
From source file:sample.tomcat.SslApplicationTests.java
@Test(expected = ResourceAccessException.class) public void testUnauthenticatedHello() throws Exception { RestTemplate template = new RestTemplate(); ResponseEntity<String> httpsEntity = template.getForEntity("https://localhost:" + this.port + "/hello", String.class); assertEquals(HttpStatus.OK, httpsEntity.getStatusCode()); assertEquals("hello", httpsEntity.getBody()); }
From source file:com.nestedbird.modules.facebookreader.FacebookReader.java
/** * This is the method that actually makes the http request * * @param url request url/*ww w. j ava 2s . co m*/ * @param deconstructClass class of request object * @param <T> type of request object this is * @return request object */ private <T> T request(final String url, final Class<T> deconstructClass) { final RestTemplate restTemplate = new RestTemplate(); T deconstructedResponse = null; try { deconstructedResponse = restTemplate.getForObject(url, deconstructClass); } catch (HttpClientErrorException err) { logger.info("[FacebookReader] [request] Failure To Retrieve Facebook Resource (" + url + ")", err); } return deconstructedResponse; }
From source file:co.mafiagame.telegraminterface.inputhandler.UpdateController.java
@SuppressWarnings("InfiniteLoopStatement") @PostConstruct/*w w w.j a v a 2 s . c o m*/ public void init() { Thread thread = new Thread(() -> { try { long offset = 1; Thread.sleep(TimeUnit.MINUTES.toMillis(2)); while (true) { try { RestTemplate restTemplate = new RestTemplate(); setErrorHandler(restTemplate); TResult tResult = restTemplate.getForObject( telegramUrl + telegramToken + "/getUpdates?offset=" + String.valueOf(offset + 1), TResult.class); for (TUpdate update : tResult.getResult()) { if (offset < update.getId()) { offset = update.getId(); if (Objects.nonNull(update.getMessage())) { logger.info("receive: {}", update); commandDispatcher.handle(update); } logger.info("offset set to {}", offset); } } Thread.sleep(TimeUnit.MILLISECONDS.toMillis(500)); } catch (Exception e) { logger.error(e.getMessage(), e); } } } catch (InterruptedException e) { e.printStackTrace(); } }); thread.start(); }
From source file:org.aksw.gerbil.datasets.datahub.DatahubNIFLoader.java
public DatahubNIFLoader() { rt = new RestTemplate(); init(); }
From source file:com.ggk.hrms.authentication.CustomTokenServices.java
public CustomTokenServices() { restTemplate = new RestTemplate(); ((RestTemplate) restTemplate).setErrorHandler(new DefaultResponseErrorHandler() { @Override//from w w w . j a va 2 s . c om // Ignore 400 public void handleError(ClientHttpResponse response) throws IOException { if (response.getRawStatusCode() != 400) { super.handleError(response); } } }); }
From source file:org.openwms.common.comm.app.DriverConfig.java
public @LoadBalanced @Bean RestTemplate aLoadBalanced() { return new RestTemplate(); }
From source file:com.golonzovsky.oauth2.google.security.GoogleTokenServices.java
public GoogleTokenServices() { restTemplate = new RestTemplate(); ((RestTemplate) restTemplate).setErrorHandler(new DefaultResponseErrorHandler() { @Override/* w ww. j a v a 2s .c o m*/ // Ignore 400 public void handleError(ClientHttpResponse response) throws IOException { if (response.getRawStatusCode() != 400) { super.handleError(response); } } }); }
From source file:org.client.one.service.OAuthAuthenticationService.java
public String login(String username, String password) throws JSONException { RestOperations rest = new RestTemplate(); String resAuth = rest.postForObject(oauthServerBaseURL + "/oauth/token?username=" + username + "&password=" + password + "&client_id=" + appToken + "&client_secret=" + appPassword + "&grant_type=password", null, String.class); System.out.println(resAuth);/*from w w w . j av a2 s . com*/ JSONObject resJsA = new JSONObject(resAuth); return resJsA.getString("access_token"); }
From source file:io.lavagna.service.ApiHooksService.java
private static void executeScript(String name, CompiledScript script, Map<String, Object> scope) { try {/*from w ww . j a v a2 s . c om*/ ScriptContext newContext = new SimpleScriptContext(); Bindings engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE); engineScope.putAll(scope); engineScope.put("log", LOG); engineScope.put("GSON", Json.GSON); engineScope.put("restTemplate", new RestTemplate()); script.eval(newContext); } catch (ScriptException ex) { LOG.warn("Error while executing script " + name, ex); } }
From source file:com.iata.ndc.trial.controllers.DefaultController.java
@RequestMapping(value = "/ba", method = RequestMethod.GET) public String getCal() { RestTemplate restTemplate = new RestTemplate(); List<HttpMessageConverter<?>> converters = new ArrayList<>(); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); converter.getObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); converters.add(converter);/* w ww. j av a 2 s. c o m*/ restTemplate.setMessageConverters(converters); HttpHeaders headers = new HttpHeaders(); headers.add("client-key", "zmd9apqgg2jwekf8zgqg5ybf"); headers.setContentType(MediaType.APPLICATION_JSON); ResponseEntity<BALocationsResponseWrapper> baLocationsResponse = restTemplate.exchange( "https://api.ba.com/rest-v1/v1/balocations", HttpMethod.GET, new HttpEntity<Object>(headers), BALocationsResponseWrapper.class); System.out.println(baLocationsResponse.getBody().getGetBALocationsResponse().getCountry().size()); return "index"; }