List of usage examples for org.springframework.web.client RestTemplate RestTemplate
public RestTemplate()
From source file:fm.last.lastfmlive.service.LastfmFacade.java
public List<Track> getTopTracks(String userName) { log.info("Getting top tracks for user {}", userName); RestTemplate restTemplate = new RestTemplate(); String methodString = "user.gettoptracks&user={user}&api_key={apiKey}"; Source topArtistsXml = restTemplate.getForObject(wsPrefix + methodString, Source.class, userName, apiKey); List<Track> output = xpathTemplate.evaluate("//track", topArtistsXml, new NodeMapper<Track>() { public Track mapNode(Node node, int nodeIndex) throws DOMException { Source src = new DOMSource(node); try { String title = xpathTemplate.evaluateAsNodeList("name", src).get(0).getTextContent(); String artist = xpathTemplate.evaluateAsNodeList("artist/name", src).get(0).getTextContent(); return new Track(artist, title); } catch (Exception e) { return null; }/*from ww w. jav a 2 s . c o m*/ } }); log.info("Found {} top tracks", output.size()); return output; }
From source file:org.zalando.stups.oauth2.spring.server.TokenInfoResourceServerTokenServices.java
public TokenInfoResourceServerTokenServices(final String tokenInfoEndpointUrl, final String clientId) { this(tokenInfoEndpointUrl, clientId, new LaxAuthenticationExtractor(), new RestTemplate()); }
From source file:au.id.hazelwood.xmltvguidebuilder.grabber.Grabber.java
public Grabber() { StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from www .ja v a 2s. c om*/ this.restTemplate = new RestTemplate(); stopWatch.stop(); LOGGER.debug("Grabber created in {}", formatDurationWords(stopWatch.getTime())); }
From source file:com.gopivotal.cloudfoundry.test.support.TestConfiguration.java
@Bean RestOperations restOperations() { RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(new NoErrorResponseErrorHandler()); return restTemplate; }
From source file:org.cbioportal.genome_nexus.annotation.service.internal.VEPVariantAnnotationService.java
public String getRawAnnotation(String variant) { //http://grch37.rest.ensembl.org/vep/human/hgvs/VARIANT?content-type=application/json&xref_refseq=1&ccds=1&canonical=1&domains=1&hgvs=1&numbers=1&protein=1 String uri = vepURL.replace("VARIANT", variant); RestTemplate restTemplate = new RestTemplate(); return restTemplate.getForObject(uri, String.class); }
From source file:demo.ServerRunning.java
@Override public Statement apply(final Statement base, FrameworkMethod method, Object target) { // Check at the beginning, so this can be used as a static field Assume.assumeTrue(serverOnline.get(port)); RestTemplate client = new RestTemplate(); boolean followRedirects = HttpURLConnection.getFollowRedirects(); HttpURLConnection.setFollowRedirects(false); boolean online = false; try {/*from w ww. j ava 2 s. com*/ client.getForEntity(new UriTemplate(getUrl("/info")).toString(), String.class); online = true; logger.info("Basic connectivity test passed"); } catch (RestClientException e) { logger.warn(String.format( "Not executing tests because basic connectivity test failed for hostName=%s, port=%d", hostName, port), e); Assume.assumeNoException(e); } finally { HttpURLConnection.setFollowRedirects(followRedirects); if (!online) { serverOnline.put(port, false); } } return new Statement() { @Override public void evaluate() throws Throwable { base.evaluate(); } }; }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManager.java
public RemoteUaaAuthenticationManager() { RestTemplate restTemplate = new RestTemplate(); // The default java.net client doesn't allow you to handle 4xx responses restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory()); restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { protected boolean hasError(HttpStatus statusCode) { return statusCode.series() == HttpStatus.Series.SERVER_ERROR; }/*from w w w . j av a2 s . c om*/ }); this.restTemplate = restTemplate; }
From source file:uk.ac.kcl.itemProcessors.BioLarkDocumentItemProcessor.java
@PostConstruct private void init() { fieldsToBioLark = Arrays.asList(env.getProperty("fieldsToBioLark").toLowerCase().split(",")); endPoint = env.getProperty("biolarkEndPoint"); setFieldName(env.getProperty("biolarkFieldName")); this.mapper = new ObjectMapper(); this.connectTimeout = Integer.valueOf(env.getProperty("biolarkConnectTimeout")); this.readTimeout = Integer.valueOf(env.getProperty("biolarkReadTimeout")); this.retryTemplate = getRetryTemplate(); this.restTemplate = new RestTemplate(); ((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setReadTimeout(readTimeout); ((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setConnectTimeout(connectTimeout); }
From source file:sample.tomcat.SslApplicationTests.java
@Test public void testAuthenticatedHello() throws Exception { RestTemplate template = new RestTemplate(); final LocalhostClientHttpRequestFactory factory = new LocalhostClientHttpRequestFactory( secureSocketFactory());// www . java 2s . co m template.setRequestFactory(factory); ResponseEntity<String> httpsEntity = template.getForEntity("https://localhost:" + this.port + "/hello", String.class); assertEquals(HttpStatus.OK, httpsEntity.getStatusCode()); assertEquals("hello", httpsEntity.getBody()); }
From source file:uk.ac.kcl.itemProcessors.WebserviceDocumentItemProcessor.java
@PostConstruct private void init() { fieldsToSendToWebservice = Arrays .asList(env.getProperty("webservice.fieldsToSendToWebservice").toLowerCase().split(",")); setFieldName(fieldName);/* w w w .j ava 2s. c o m*/ this.retryTemplate = getRetryTemplate(); this.restTemplate = new RestTemplate(); ((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setReadTimeout(readTimeout); ((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setConnectTimeout(connectTimeout); }