List of usage examples for org.springframework.http HttpMethod GET
HttpMethod GET
To view the source code for org.springframework.http HttpMethod GET.
Click Source Link
From source file:uk.ac.ebi.ep.ebeye.EbeyeRestServiceTest.java
/** * Test of queryEbeyeForAccessions method, of class EbeyeRestService. *///from w ww . ja v a2 s. c o m @Test public void testQueryEbeyeForAccessions_String() { try { LOGGER.info("queryEbeyeForAccessions"); String url = ebeyeIndexUrl.getDefaultSearchIndexUrl() + "?format=json&size=100&query="; String json = getJsonFile(ebeyeJsonFile); mockRestServer.expect(requestTo(url)).andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(json, MediaType.APPLICATION_JSON)); EbeyeSearchResult searchResult = restTemplate.getForObject(url.trim(), EbeyeSearchResult.class); Set<String> accessions = new LinkedHashSet<>(); for (Entry entry : searchResult.getEntries()) { accessions.add(entry.getUniprotAccession()); } List<String> expResult = accessions.stream().distinct().collect(Collectors.toList()); String accession = expResult.stream().findAny().get(); List<String> result = ebeyeRestService.queryEbeyeForAccessions(query); mockRestServer.verify(); assertThat(result.stream().findAny().get(), containsString(accession)); assertEquals(expResult, result); } catch (IOException ex) { LOGGER.error(ex.getMessage(), ex); } }
From source file:svc.data.citations.datasources.tyler.TylerCitationDataSource.java
private List<Citation> performRestTemplateCall(URI uri) { HttpHeaders headers = new HttpHeaders(); headers.add("apikey", tylerConfiguration.apiKey); HttpEntity<?> query = new HttpEntity<>(headers); ResponseEntity<List<TylerCitation>> tylerCitationsResponse = null; ParameterizedTypeReference<List<TylerCitation>> type = new ParameterizedTypeReference<List<TylerCitation>>() { };/*from w ww . j a va2 s . c o m*/ List<TylerCitation> tylerCitations = null; try { tylerCitationsResponse = restTemplate.exchange(uri, HttpMethod.GET, query, type); tylerCitations = tylerCitationsResponse.getBody(); return citationFilter .RemoveCitationsWithExpiredDates(citationTransformer.fromTylerCitations(tylerCitations)); } catch (RestClientException ex) { System.out.println("Tyler datasource is down."); return Lists.newArrayList(); } }
From source file:info.losd.galen.scheduler.repository.TestTaskRepo.java
@Test public void test_it_can_get_a_list_of_tasks_to_be_run() { List<Header> headers = Arrays.asList(new Header("h1", "v1"), new Header("h2", "v2")); String url = "http://localhost:8080/test"; String method = HttpMethod.GET.toString(); repo.save(new Task("test_task", 10, Instant.now().minusSeconds(10), url, method, Collections.emptyList())); repo.save(new Task("test_task", 10, Instant.now().minusSeconds(10), url, method, Collections.emptyList())); repo.save(new Task("test_task", 10, Instant.now().minusSeconds(10), url, method, headers)); repo.save(new Task("test_task", 10, Instant.now().plusSeconds(11), url, method, Collections.emptyList())); repo.save(new Task("test_task", 10, Instant.now().plusSeconds(12), url, method, Collections.emptyList())); List<Task> result = repo.findTasksToBeRun(); assertThat(result, IsCollectionWithSize.hasSize(3)); result.forEach(res -> {// www . j a va 2 s. c o m LOG.info("{} has {} headers", res.toString(), res.getHeaders().size()); }); }
From source file:io.spring.initializr.web.test.MockMvcClientHttpRequestFactory.java
@Override public ClientHttpRequest createRequest(final URI uri, final HttpMethod httpMethod) throws IOException { return new MockClientHttpRequest(httpMethod, uri) { @Override/* ww w . ja v a 2 s. c om*/ public ClientHttpResponse executeInternal() throws IOException { try { MockHttpServletRequestBuilder requestBuilder = request(httpMethod, uri.toString()); requestBuilder.content(getBodyAsBytes()); requestBuilder.headers(getHeaders()); MockHttpServletResponse servletResponse = actions(requestBuilder).andReturn().getResponse(); HttpStatus status = HttpStatus.valueOf(servletResponse.getStatus()); if (status.value() >= 400) { requestBuilder = request(HttpMethod.GET, "/error") .requestAttr(RequestDispatcher.ERROR_STATUS_CODE, status.value()) .requestAttr(RequestDispatcher.ERROR_REQUEST_URI, uri.toString()); if (servletResponse.getErrorMessage() != null) { requestBuilder.requestAttr(RequestDispatcher.ERROR_MESSAGE, servletResponse.getErrorMessage()); } // Overwrites the snippets from the first request servletResponse = actions(requestBuilder).andReturn().getResponse(); } byte[] body = servletResponse.getContentAsByteArray(); HttpHeaders headers = getResponseHeaders(servletResponse); MockClientHttpResponse clientResponse = new MockClientHttpResponse(body, status); clientResponse.getHeaders().putAll(headers); return clientResponse; } catch (Exception ex) { throw new IllegalStateException(ex); } } }; }
From source file:soap.client.Application.java
@Bean public HttpRequestHandlingMessagingGateway httpGate() { HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true); RequestMapping mapping = new RequestMapping(); mapping.setMethods(HttpMethod.GET); mapping.setPathPatterns("/foo"); gateway.setRequestMapping(mapping);// w w w . j a v a 2s . co m gateway.setRequestChannel(requestChannel()); gateway.setRequestPayloadType(String.class); return gateway; }
From source file:io.pivotal.receptor.events.EventDispatcher.java
@Override public void run() { RequestCallback requestCallback = new NoOpRequestCallback(); ResponseExtractor<?> responseExtractor = new EventResponseExtractor(); while (true) { try {//from ww w . j a v a2 s. co m restTemplate.execute(url, HttpMethod.GET, requestCallback, responseExtractor); } catch (Exception e) { throw new IllegalStateException("Exception while reading event stream.", e); } } }
From source file:org.zalando.boot.etcd.EtcdClientTest.java
@Test public void getRecursive() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?recursive=true")) .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators .withSuccess(new ClassPathResource("EtcdClientTest_get.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.get("sample", true); Assert.assertNotNull("response", response); server.verify();/*from w w w . j a v a2s .co m*/ }
From source file:org.zalando.github.spring.StatusesTemplate.java
/** * 'ref' can be SHA, branch or tag./* www . j a v a 2s. c o m*/ */ @Override public CombinedStatus getCombinedStatus(String owner, String repository, String ref) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("owner", owner); uriVariables.put("repository", repository); uriVariables.put("ref", ref); return getRestOperations() .exchange(buildUri("/repos/{owner}/{repository}/commits/{ref}/status", uriVariables), HttpMethod.GET, null, CombinedStatus.class) .getBody(); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.CreatingPlanVisibilityStep.java
private String getServiceGuidByName(String serviceName) throws IOException { String cfServiceGuidUrl = cfApiUrl + GET_SERVICE_GUID_BY_NAME_ENDPOINT_TEMPLATE; ResponseEntity<String> response = cfRestTemplate.exchange(cfServiceGuidUrl, HttpMethod.GET, HttpCommunication.simpleJsonRequest(), String.class, serviceName); return JsonDataFetcher.getStringValue(response.getBody(), SERVICE_GUID_JSON_PATH); }