List of usage examples for org.springframework.web.client RestTemplate RestTemplate
public RestTemplate()
From source file:com.salmon.security.xacml.demo.springmvc.rest.HTTPPopulatorsTest.java
@Test public void badUserPrevented() { HttpHeaders headers = this.getHeaders("wrongusername" + ":" + "wrongpwd"); RestTemplate template = new RestTemplate(); HttpEntity<String> requestEntity = new HttpEntity<String>(DriverFixtures.standardDriverJSON(), headers); try {/*from w ww . j a v a 2 s .co m*/ ResponseEntity<Driver> entity = template.postForEntity( "http://localhost:8085/xacml/populators/dvla/driveradd", requestEntity, Driver.class); fail("Request Passed incorrectly with status " + entity.getStatusCode()); } catch (HttpClientErrorException ex) { assertEquals(HttpStatus.UNAUTHORIZED, ex.getStatusCode()); } }
From source file:org.cloudfoundry.identity.uaa.oauth.RemoteTokenServices.java
public RemoteTokenServices() { restTemplate = new RestTemplate(); ((RestTemplate) restTemplate).setErrorHandler(new DefaultResponseErrorHandler() { @Override/*www . ja va 2s .c om*/ // Ignore 400 public void handleError(ClientHttpResponse response) throws IOException { if (response.getRawStatusCode() != 400) { super.handleError(response); } } }); }
From source file:edu.teilar.jcrop.service.client.controller.KObjectsClientController.java
@RequestMapping(value = "/kobjects/{kobject}", method = RequestMethod.GET) public String getKObject(@PathVariable String kobject, Model model) { RestTemplate restTemplate = new RestTemplate(); String url = ClientUrls.SERVERADDRESS + ApiUrls.KOBJECT_XMODELS_XGRAPH_SVG_URL; Map<String, Object> svgDocument = restTemplate.getForObject(url, Map.class, kobject, "default"); model.addAllAttributes(svgDocument); url = ClientUrls.SERVERADDRESS + ApiUrls.KOBJECT_URL; KObject kobj = restTemplate.getForObject(url, KObject.class, kobject); model.addAttribute("kobject", kobj); return "kobject"; }
From source file:cz.muni.fi.mushroomhunter.restclient.MushroomCreateSwingWorker.java
@Override protected Void doInBackground() throws Exception { MushroomDto mushroomDto = new MushroomDto(); mushroomDto.setName(restClient.getTfMushroomName().getText()); mushroomDto.setType(cz.fi.muni.pa165.mushroomhunter.api.Type .valueOf(restClient.getComboBoxMushroomType().getSelectedItem().toString())); //to create date object only month is used, day and year are fixed values String dateInString = restClient.getComboBoxMushroomStartOfOccurence().getSelectedItem().toString() + " 1, 2000"; SimpleDateFormat formatter = new SimpleDateFormat("MMMM d, yyyy", new Locale("en_US")); mushroomDto.setStartOfOccurence(formatter.parse(dateInString)); //to create date object only month is used, day and year are fixed values dateInString = restClient.getComboBoxMushroomEndOfOccurence().getSelectedItem().toString() + " 1, 2000"; mushroomDto.setEndOfOccurence(formatter.parse(dateInString)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);//ww w .j a va 2s . co m headers.setAccept(mediaTypeList); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(mushroomDto); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity(json, headers); RestTemplate restTemplate = new RestTemplate(); Long[] result = restTemplate.postForObject(RestClient.SERVER_URL + "pa165/rest/mushroom", request, Long[].class); System.out.println("Id of the created mushroom: " + result[0]); RestClient.getMushroomIDs().add(result[0]); return null; }
From source file:com.uimirror.auth.LoginStepDef.java
@Then("^I call the login service$") public void i_call_the_login_service() throws Throwable { when(someBean.test()).thenReturn("Helooooooooo done"); String res = new RestTemplate().postForObject("http://localhost:8080/uim/auth/api/auth/login", new Object(), String.class); System.out.println(res);/*from w w w .j a va 2 s. c o m*/ throw new PendingException(); }
From source file:org.venice.piazza.servicecontroller.Application.java
@Bean public RestTemplate restTemplate() { RestTemplate restTemplate = new RestTemplate(); HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(httpMaxTotal) .setMaxConnPerRoute(httpMaxRoute).build(); HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); factory.setReadTimeout(httpRequestTimeout * 1000); factory.setConnectTimeout(httpRequestTimeout * 1000); restTemplate.setRequestFactory(factory); return restTemplate; }
From source file:com.netflix.genie.web.services.impl.HttpFileTransferImplTest.java
/** * Setup for the tests./* w w w. j a v a 2s . c om*/ */ @Before public void setup() { final RestTemplate restTemplate = new RestTemplate(); this.server = MockRestServiceServer.createServer(restTemplate); this.downloadTimer = Mockito.mock(Timer.class); this.uploadTimer = Mockito.mock(Timer.class); this.metadataTimer = Mockito.mock(Timer.class); this.downloadTimerId = Mockito.mock(Id.class); this.uploadTimerId = Mockito.mock(Id.class); this.metadataTimerId = Mockito.mock(Id.class); final Registry registry = Mockito.mock(Registry.class); Mockito.when(registry.createId("genie.files.http.download.timer")).thenReturn(this.downloadTimerId); Mockito.when(registry.createId("genie.files.http.upload.timer")).thenReturn(this.uploadTimerId); Mockito.when(registry.createId("genie.files.http.getLastModified.timer")).thenReturn(this.metadataTimerId); Mockito.when(this.downloadTimerId.withTags(Mockito.anyMapOf(String.class, String.class))) .thenReturn(this.downloadTimerId); Mockito.when(this.uploadTimerId.withTags(Mockito.anyMapOf(String.class, String.class))) .thenReturn(this.uploadTimerId); Mockito.when(this.metadataTimerId.withTags(Mockito.anyMapOf(String.class, String.class))) .thenReturn(this.metadataTimerId); Mockito.when(registry.timer(this.downloadTimerId)).thenReturn(this.downloadTimer); Mockito.when(registry.timer(this.uploadTimerId)).thenReturn(this.uploadTimer); Mockito.when(registry.timer(this.metadataTimerId)).thenReturn(this.metadataTimer); this.httpFileTransfer = new HttpFileTransferImpl(restTemplate, registry); }
From source file:com.netflix.spinnaker.front50.config.AzureStorageConfig.java
@Bean @ConditionalOnMissingBean(RestTemplate.class) public RestTemplate restTemplate() { return new RestTemplate(); }
From source file:com.kurento.kmf.repository.test.OneRecordingServerTest.java
protected void downloadFromURL(String urlToDownload, File downloadedFile) throws Exception { if (!downloadedFile.exists()) { downloadedFile.createNewFile();// w ww . ja va 2s. c o m } log.info(urlToDownload); RestTemplate client = new RestTemplate(); ResponseEntity<byte[]> response = client.getForEntity(urlToDownload, byte[].class); assertEquals(HttpStatus.OK, response.getStatusCode()); FileOutputStream os = new FileOutputStream(downloadedFile); os.write(response.getBody()); os.close(); }
From source file:com.github.ljtfreitas.restify.spring.netflix.autoconfigure.ribbon.RestifyRibbonAutoConfiguration.java
@ConditionalOnMissingBean @Bean @LoadBalanced public RestTemplate restifyRestTemplate() { return new RestTemplate(); }