List of usage examples for org.springframework.web.client RestTemplate RestTemplate
public RestTemplate()
From source file:org.zalando.riptide.CaptureTest.java
public CaptureTest() { 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:org.zalando.riptide.CallTest.java
public CallTest() { 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:io.pivotal.strepsirrhini.chaoslemur.reporter.DataDogReporterTest.java
@Before public void setup() { RestTemplate restTemplate = new RestTemplate(); this.mockServer = MockRestServiceServer.createServer(restTemplate); this.dataDog = new DataDogReporter("apiKey", "appKey", restTemplate, new String[] { "key:value" }); }
From source file:me.j360.boot.standard.test.SessionRedisApplicationTests.java
@Test public void sessionExpiry() throws Exception { String port = null;/*from www .jav a 2 s . com*/ try { ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(J360Configuration.class) .properties("server.port:0").initializers(new ServerPortInfoApplicationContextInitializer()) .run(); port = context.getEnvironment().getProperty("local.server.port"); } catch (RuntimeException ex) { if (!redisServerRunning(ex)) { return; } } URI uri = URI.create("http://localhost:" + port + "/"); RestTemplate restTemplate = new RestTemplate(); ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class); String uuid1 = response.getBody(); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Cookie", response.getHeaders().getFirst("Set-Cookie")); RequestEntity<Void> request = new RequestEntity<Void>(requestHeaders, HttpMethod.GET, uri); String uuid2 = restTemplate.exchange(request, String.class).getBody(); assertThat(uuid1, is(equalTo(uuid2))); Thread.sleep(5000); String uuid3 = restTemplate.exchange(request, String.class).getBody(); assertThat(uuid2, is(not(equalTo(uuid3)))); }
From source file:com.xyxy.platform.examples.showcase.functional.rest.UserRestFT.java
@Before public void initRestTemplate() { // JDK Connection jdkTemplate = new RestTemplate(); // (optional)20 ((SimpleClientHttpRequestFactory) jdkTemplate.getRequestFactory()).setConnectTimeout(20000); ((SimpleClientHttpRequestFactory) jdkTemplate.getRequestFactory()).setReadTimeout(20000); // HttpClient4.0 httpClientRestTemplate = new RestTemplate(); httpClientRequestFactory = new HttpComponentsClientHttpRequestFactory(); // (optional)20 httpClientRequestFactory.setConnectTimeout(20000); httpClientRestTemplate.setRequestFactory(httpClientRequestFactory); // ?HttpBasic HeaderInterceptor ClientHttpRequestInterceptor interceptor = new HttpBasicInterceptor("admin", "admin"); httpClientRestTemplate.setInterceptors(Lists.newArrayList(interceptor)); }
From source file:aiai.ai.station.LaunchpadRequester.java
@Autowired public LaunchpadRequester(Globals globals, CommandProcessor commandProcessor, StationTaskService stationTaskService, StationService stationService) { this.globals = globals; this.commandProcessor = commandProcessor; this.stationTaskService = stationTaskService; this.stationService = stationService; this.restTemplate = new RestTemplate(); }
From source file:edu.teilar.jcrop.service.client.controller.KObjectsClientController.java
@RequestMapping(value = "/concepts/{concept}", method = RequestMethod.GET) public String getConcept(@PathVariable String concept, Model model) { RestTemplate restTemplate = new RestTemplate(); String url = ClientUrls.SERVERADDRESS + ApiUrls.CONCEPT_URL; Concept c = restTemplate.getForObject(url, Concept.class, concept); url = ClientUrls.SERVERADDRESS + ApiUrls.KOBJECTS_CONCEPT_URL; List<KObject> kobjects = (List<KObject>) restTemplate.getForObject(url, List.class, concept); model.addAttribute("concept", c); model.addAttribute("kobjects", kobjects); return "concept"; }
From source file:id.co.teleanjar.ppobws.restclient.RestClientService.java
public Map<String, Object> inquiry(String idpel, String idloket, String merchantCode) throws IOException { String uri = "http://localhost:8080/ppobws/api/produk"; RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = createHeaders("superuser", "passwordku"); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri).queryParam("idpel", idpel) .queryParam("idloket", idloket).queryParam("merchantcode", merchantCode); HttpEntity<?> entity = new HttpEntity<>(headers); ResponseEntity<String> httpResp = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, String.class); String json = httpResp.getBody(); LOGGER.info("JSON [{}]", json); LOGGER.info("STATUS [{}]", httpResp.getStatusCode().toString()); Map<String, Object> map = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); map = mapper.readValue(json, new TypeReference<HashMap<String, Object>>() { });/*from w w w.j a va2 s . c om*/ return map; }
From source file:com.aktios.appthree.server.service.OAuthAuthenticationService.java
public String loginApp() throws JSONException { RestOperations rest = new RestTemplate(); String resAuth = rest.getForObject(oauthServerBaseURL + "/oauth/token?client_id=" + appToken + "&client_secret=" + appPassword + "&grant_type=client_credentials", String.class); System.out.println(resAuth);// w ww . j a v a 2 s . c o m JSONObject resJsA = new JSONObject(resAuth); return resJsA.getString("access_token"); }
From source file:org.intermine.app.service.RoboSpiceService.java
@Override public RestTemplate createRestTemplate() { RestTemplate rtp = new RestTemplate(); Charset utf8 = Charset.forName(CHARSET); ByteArrayHttpMessageConverter byteConv = new ByteArrayHttpMessageConverter(); StringHttpMessageConverter stringConv = new StringHttpMessageConverter(utf8); FormHttpMessageConverter formConv = new FormHttpMessageConverter(); formConv.setCharset(utf8);/*from w w w .ja va2s . c o m*/ List<HttpMessageConverter<?>> converters = rtp.getMessageConverters(); converters.add(byteConv); converters.add(stringConv); converters.add(formConv); rtp.setMessageConverters(converters); return rtp; }