List of usage examples for org.springframework.web.client RestTemplate RestTemplate
public RestTemplate()
From source file:devbury.dewey.hipchat.api.Api.java
@PostConstruct public void init() { authorization = "Bearer " + hipChatSettings.getApiToken(); restTemplate = new RestTemplate(); restTemplate.setInterceptors(Collections.singletonList(this)); }
From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityStoreConnector.java
public synchronized String createNewTraceabilityRecord(String serviceId, String traceabilityRecord) { String restURI = "http://" + server_add + ":" + port_no + "/" + service + "/" + resource + "/" + serviceId + "/" + this.TRACEABILITY_TYPE; logger.info("Invoking URI: " + restURI); RestTemplate restTemplate = new RestTemplate(); // String traceabilityRecordIdResponse = // restTemplate.getForObject(restURI, String.class); String traceabilityRecordIdResponse = restTemplate.postForObject(restURI, traceabilityRecord, String.class); return traceabilityRecordIdResponse; }
From source file:org.mimacom.sample.integration.patterns.user.service.integration.HystrixSearchServiceIntegration.java
public HystrixSearchServiceIntegration(String searchServiceUrl) { this.searchServiceUrl = searchServiceUrl; this.restTemplate = new RestTemplate(); exposeMetricsOnJmx();/* w w w . j ava 2s . com*/ }
From source file:org.starfishrespect.myconsumption.android.tasks.UserUpdater.java
@Override protected Void doInBackground(Void... params) { RestTemplate template = new RestTemplate(); HttpHeaders httpHeaders = CryptoUtils.createHeaders(username, password); template.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); try {/* www . j a va2s . c o m*/ ResponseEntity<UserDTO> response = template.exchange( SingleInstance.getServerUrl() + "users/" + username, HttpMethod.GET, new HttpEntity<>(httpHeaders), UserDTO.class); UserDTO user = response.getBody(); UserData userData = new UserData(user); for (String sensor : user.getSensors()) { try { ResponseEntity<SensorDTO> responseSensor = template.exchange( SingleInstance.getServerUrl() + "sensors/" + sensor, HttpMethod.GET, new HttpEntity<>(httpHeaders), SensorDTO.class); SensorDTO SensorDTO = responseSensor.getBody(); userData.addSensor(new SensorData(SensorDTO)); } catch (RestClientException e) { e.printStackTrace(); } } publishProgress(userData); } catch (RestClientException e) { e.printStackTrace(); publishProgress(null); } return null; }
From source file:org.zalando.riptide.RedirectTest.java
public RedirectTest() { final RestTemplate template = new RestTemplate(); template.setErrorHandler(new PassThroughResponseErrorHandler()); this.server = MockRestServiceServer.createServer(template); this.unit = Rest.create(template); }
From source file:com.unknownpkg.StupsSwaggerCodegenIT.java
@Test public void getResources() { RestTemplate rest = new RestTemplate(); ResponseEntity<List<SwaggerResource>> responseEntity = rest.exchange( "http://localhost:" + port + "/swagger-resources", HttpMethod.GET, null, swaggerResourceParameterizedType); List<SwaggerResource> swaggerResourceList = responseEntity.getBody(); Assertions.assertThat(swaggerResourceList).isNotEmpty(); SwaggerResource resource = swaggerResourceList.get(0); Assertions.assertThat(resource).isNotNull(); Assertions.assertThat(resource.getSwaggerVersion()).isEqualTo("2.0"); Assertions.assertThat(resource.getName()).isEqualTo("default"); Assertions.assertThat(resource.getLocation()).isEqualTo("/v2/api-docs"); }
From source file:cz.muni.fi.mushroomhunter.restclient.LocationDeleteSwingWorker.java
@Override protected Integer doInBackground() throws Exception { int selectedRow = restClient.getTblLocation().getSelectedRow(); RestTemplate restTemplate = new RestTemplate(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); HttpEntity<String> request = new HttpEntity<>(headers); restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() { @Override//from w w w . ja v a 2 s . c o m protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) { if (HttpMethod.DELETE == httpMethod) { return new HttpEntityEnclosingDeleteRequest(uri); } return super.createHttpUriRequest(httpMethod, uri); } }); restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/location/" + RestClient.getLocationIDs().get(selectedRow), HttpMethod.DELETE, request, LocationDto.class); RestClient.getLocationIDs().remove(selectedRow); return selectedRow; }
From source file:com.nbempire.dentalnavarra.dao.impl.RememberDaoImplSpring.java
@Override public RemembersDTO findRemembers(String patientId) { RestTemplate restTemplate = new RestTemplate(); // Add a JSON converter (use GSON instead of Jackson because is a smaller library) restTemplate.getMessageConverters().add(new GsonHttpMessageConverter()); String urlString = MainKeys.API_HOST + "/patients/" + patientId + "/notifications"; Log.d(TAG, "Getting resource: " + urlString); RemembersDTO response = null;//from www.ja va 2s .com URI url = null; try { url = new URI(urlString); response = restTemplate.getForObject(url, RemembersDTO.class); } catch (URISyntaxException e) { Log.e(TAG, "There was an error creating the URI: " + urlString); } catch (RestClientException restClientException) { Log.e(TAG, "There was an error getting remembers from URL: " + url); Log.e(TAG, restClientException.getMessage()); } return response != null ? response : new RemembersDTO(); }
From source file:com.aktios.appthree.server.service.OAuthAuthenticationService.java
public String login(String username, String password) throws JSONException { RestOperations rest = new RestTemplate(); String resAuth = rest.getForObject(oauthServerBaseURL + "/oauth/token?username=" + username + "&password=" + password + "&client_id=" + appToken + "&client_secret=" + appPassword + "&grant_type=password", String.class); System.out.println(resAuth);/*www . j a v a 2s .co m*/ JSONObject resJsA = new JSONObject(resAuth); return resJsA.getString("access_token"); }
From source file:spring.microservice.blog.BlogApplication.java
@LoadBalanced @Bean public RestTemplate restTemplate() { return new RestTemplate(); }