List of usage examples for org.springframework.web.client RestTemplate getForObject
@Override @Nullable public <T> T getForObject(URI url, Class<T> responseType) throws RestClientException
From source file:com.mac.halendpoint.endpoints.ProtocolRouter.java
@ProtocolMapping(routeTo = "query", respondTo = "query", numParams = 2) private Message query(String deviceName, String command) throws Exception { Message msg = null;/* ww w .jav a 2s . c o m*/ if (Objects.nonNull(deviceName) && Objects.nonNull(command)) { String uri = formUri(BASE_RESOURCE_PATH, "query", deviceName, command); RestTemplate template = new RestTemplate(); msg = template.getForObject(uri, Message.class); } return msg; }
From source file:com.mac.halendpoint.endpoints.ProtocolRouter.java
@ProtocolMapping(routeTo = "command", respondTo = "status", numParams = 2) private Status command(String deviceName, String command) throws Exception { Status stat = Status.FAILED;/*from w w w . j ava 2s . co m*/ if (Objects.nonNull(deviceName) && Objects.nonNull(command)) { String uri = formUri(BASE_RESOURCE_PATH, deviceName, command); RestTemplate template = new RestTemplate(); stat = template.getForObject(uri, Status.class); } return stat; }
From source file:com.mac.halendpoint.endpoints.ProtocolRouter.java
@ProtocolMapping(routeTo = "listen", respondTo = "socket", numParams = 3) private String listen(String protocol, String host, String port) throws Exception { if (Objects.nonNull(protocol) && Objects.nonNull(host) && Objects.nonNull(port)) { String uri = formUri(BASE_RESOURCE_PATH, "listener", protocol, host, port); System.out.println("URI: " + uri); RestTemplate template = new RestTemplate(); return template.getForObject(uri, String.class); }/*from ww w .ja v a2s . c o m*/ return Status.NOT_MODIFIED.name(); }
From source file:dk.skogemann.airline.project.ApiController.java
private FlightResponse doSearch(String startLoc, String endLoc, String date, int ticket) throws RestClientException { String url;/*from w w w.j av a2 s .c o m*/ if (endLoc == null) { url = baseUrl + "/api/flightinfo/" + startLoc + "/" + date + "/" + ticket; } else { url = baseUrl + "/api/flightinfo/" + startLoc + "/" + endLoc + "/" + date + "/" + ticket; } System.out.println("kalder remote - search"); RestTemplate template = new RestTemplate(); FlightResponse flightResponse = template.getForObject(url, FlightResponse.class); System.out.println(flightResponse); System.out.println(" search remote end"); return flightResponse; }
From source file:eu.impress.impressplatform.IntegrationLayer.ResourcesMgmt.BedAvailabilityServiceBean.java
@Override public String getBedAvailablityHAVEREST(String hospitalname) { //consume DHC rest service RestTemplate restTemplate = new RestTemplate(); String s = restTemplate.getForObject(dhchost + "beds/available?hospital=" + hospitalname, String.class); log.info("URL query: " + dhchost + "beds/available?hospital=" + hospitalname); //return EDXL-HAVE return s;/* w w w . j a va2 s. c om*/ }
From source file:com.xpanxion.restclientexample.Application.java
public User getUser(long userId) { RestTemplate rt = new RestTemplate(); List<HttpMessageConverter<?>> converters = new ArrayList<>(); converters.add(new MappingJacksonHttpMessageConverter()); rt.setMessageConverters(converters); return rt.getForObject("http://localhost:8080/UserProjectHibernate/rest/user/" + userId, User.class); }
From source file:com.navercorp.pinpoint.plugin.spring.web.RestTemplateIT.java
@Test public void test3() throws Exception { RestTemplate restTemplate = new RestTemplate(new Netty4ClientHttpRequestFactory()); String forObject = restTemplate.getForObject(webServer.getCallHttpUrl(), String.class); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache();/*from www.ja va 2s . co m*/ verifier.verifyTrace(event("REST_TEMPLATE", RestTemplate.class.getConstructor())); verifier.verifyTrace(event("REST_TEMPLATE", "org.springframework.http.client.AbstractAsyncClientHttpRequest.executeAsync()")); verifier.verifyTrace(event("REST_TEMPLATE", "RestTemplate execAsync Result Invocation")); verifier.verifyTrace(event("ASYNC", "Asynchronous Invocation")); verifier.verifyTrace(event("REST_TEMPLATE", "org.springframework.util.concurrent.SettableListenableFuture.set(java.lang.Object)", annotation("http.status.code", 200))); }
From source file:org.apache.servicecomb.demo.springmvc.client.SpringmvcClient.java
private static void testSpringMvcDefaultValues(RestTemplate template, String microserviceName) { String cseUrlPrefix = "cse://" + microserviceName + "/SpringMvcDefaultValues/"; //default values HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers); String result = template.postForObject(cseUrlPrefix + "/form", request, String.class); TestMgr.check("Hello 20bobo", result); headers = new HttpHeaders(); HttpEntity<String> entity = new HttpEntity<>(null, headers); result = template.postForObject(cseUrlPrefix + "/header", entity, String.class); TestMgr.check("Hello 20bobo30", result); result = template.getForObject(cseUrlPrefix + "/query?d=10", String.class); TestMgr.check("Hello 20bobo4010", result); boolean failed = false; try {/*from w w w . j a va2s . c o m*/ result = template.getForObject(cseUrlPrefix + "/query2", String.class); } catch (InvocationException e) { failed = true; TestMgr.check(e.getStatusCode(), HttpStatus.SC_BAD_REQUEST); } failed = false; try { result = template.getForObject(cseUrlPrefix + "/query2?d=2&e=2", String.class); } catch (InvocationException e) { failed = true; TestMgr.check(e.getStatusCode(), HttpStatus.SC_BAD_REQUEST); } TestMgr.check(failed, true); failed = false; try { result = template.getForObject(cseUrlPrefix + "/query2?a=&d=2&e=2", String.class); } catch (InvocationException e) { failed = true; TestMgr.check(e.getStatusCode(), HttpStatus.SC_BAD_REQUEST); } TestMgr.check(failed, true); result = template.getForObject(cseUrlPrefix + "/query2?d=30&e=2", String.class); TestMgr.check("Hello 20bobo40302", result); failed = false; try { result = template.getForObject(cseUrlPrefix + "/query3?a=2&b=2", String.class); } catch (InvocationException e) { failed = true; TestMgr.check(e.getStatusCode(), HttpStatus.SC_BAD_REQUEST); } TestMgr.check(failed, true); result = template.getForObject(cseUrlPrefix + "/query3?a=30&b=2", String.class); TestMgr.check("Hello 302", result); result = template.getForObject(cseUrlPrefix + "/query3?a=30", String.class); TestMgr.check("Hello 30null", result); //input values headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<Map<String, String>> requestPara = new HttpEntity<>(null, headers); result = template.postForObject(cseUrlPrefix + "/form?a=30&b=sam", requestPara, String.class); TestMgr.check("Hello 30sam", result); headers = new HttpHeaders(); headers.add("a", "30"); headers.add("b", "sam"); headers.add("c", "40"); entity = new HttpEntity<>(null, headers); result = template.postForObject(cseUrlPrefix + "/header", entity, String.class); TestMgr.check("Hello 30sam40", result); result = template.getForObject(cseUrlPrefix + "/query?a=3&b=sam&c=5&d=30", String.class); TestMgr.check("Hello 3sam530", result); result = template.getForObject(cseUrlPrefix + "/query2?a=3&b=4&c=5&d=30&e=2", String.class); TestMgr.check("Hello 345302", result); }
From source file:com.navercorp.pinpoint.plugin.spring.web.RestTemplateIT.java
@Test public void test2() throws Exception { RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); String forObject = restTemplate.getForObject(webServer.getCallHttpUrl(), String.class); PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache();// w w w .j a v a2 s.co m verifier.verifyTrace(event("REST_TEMPLATE", RestTemplate.class.getConstructor())); verifier.verifyTrace(event("REST_TEMPLATE", AbstractClientHttpRequest.class.getMethod("execute"), annotation("http.status.code", 200))); }