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:net.paslavsky.springrest.SpringRestClientMethodInterceptorTest.java
private RestMethodMetadata createNewMetadata() { RestMethodMetadata metadata = new RestMethodMetadata(); metadata.setCommonPath("somePath"); metadata.setAdditionalPath("/subPath"); metadata.setHttpMethod(HttpMethod.GET); metadata.setResponseClass(String.class); metadata.setMethodReturnType(String.class); metadata.setUriVarParameters(new HashMap<String, Integer>()); metadata.setRequestParameter(0);/*from w ww . j a v a 2 s . com*/ metadata.setRequestHeaderParameters(new HashMap<String, Integer>()); metadata.setQueryParameters(new HashMap<String, Integer>()); return metadata; }
From source file:org.openlmis.fulfillment.service.referencedata.BaseReferenceDataServiceTest.java
@Test public void shouldReturnNullIfEntityCannotBeFoundById() throws Exception { // given//from ww w. j a v a 2 s .co m BaseReferenceDataService<T> service = prepareService(); UUID id = UUID.randomUUID(); // when when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(service.getResultClass()))).thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); T found = service.findOne(id); // then verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), eq(service.getResultClass())); URI uri = uriCaptor.getValue(); String url = service.getServiceUrl() + service.getUrl() + id; assertThat(uri.toString(), is(equalTo(url))); assertThat(found, is(nullValue())); assertAuthHeader(entityCaptor.getValue()); assertThat(entityCaptor.getValue().getBody(), is(nullValue())); }
From source file:com.joseph.california.test.restapi.ClubRestControllerTest.java
@Test public void testreadClubById() { String clubId = "2"; HttpEntity<?> requestEntity = getHttpEntity(); ResponseEntity<Club> responseEntity = restTemplate.exchange(URL + "api/club/id/" + clubId, HttpMethod.GET, requestEntity, Club.class); Club club = responseEntity.getBody(); Assert.assertNotNull(club);//from w w w.ja va 2 s .co m }
From source file:com.auditbucket.client.AbRestClient.java
public String ping() { RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); HttpHeaders httpHeaders = getHeaders(userName, password); HttpEntity requestEntity = new HttpEntity<>(httpHeaders); try {//from w w w . ja va 2 s. c o m ResponseEntity<String> response = restTemplate.exchange(PING, HttpMethod.GET, requestEntity, String.class); return response.getBody(); } catch (HttpClientErrorException e) { // ToDo: Rest error handling pretty useless. need to know why it's failing logger.error("AB Client Audit error {}", getErrorMessage(e)); return "err"; } catch (HttpServerErrorException e) { logger.error("AB Server Audit error {}", getErrorMessage(e)); return "err"; } }
From source file:com.acc.test.UserWebServiceTest.java
@Test() public void testGetUserReviews_Success_JSON_Deep() { final HttpEntity<String> requestEntity = new HttpEntity<String>(getJSONHeaders()); final ResponseEntity<ReviewDataList> response = template.exchange( "http://localhost:9001/rest/v1/users/{userid}/reviews", HttpMethod.GET, requestEntity, ReviewDataList.class, TestConstants.USERNAME); assertEquals("application/json;charset=UTF-8", response.getHeaders().getContentType().toString()); final ReviewDataList reviews = response.getBody(); assertEquals(5, reviews.getReviews().size()); }
From source file:fi.helsinki.opintoni.server.FlammaServer.java
public void expectEnglishStudentOpenUniversityNews() { server.expect(requestTo(flammaBaseUrl + "/infotaulu/atom-tiedotteet-avoin-en.xml")) .andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(toText("flamma/englishstudentopenuniversitynews.xml"), MediaType.TEXT_XML)); }
From source file:com.bodybuilding.argos.discovery.ClusterListDiscovery.java
private Collection<Cluster> getClustersFromURL(String url) { Set<Cluster> clusters = new HashSet<>(); try {/* w w w. ja va 2 s. c o m*/ ResponseEntity<List<ClusterInfo>> response = restTemplate.exchange(url, HttpMethod.GET, null, new ParameterizedTypeReference<List<ClusterInfo>>() { }); if (response.getStatusCode().value() != 200) { throw new RuntimeException("Failed to request clusters from " + url + ", return code: " + response.getStatusCode().value()); } response.getBody().stream().filter( c -> !Strings.isNullOrEmpty(c.getName()) && !Strings.isNullOrEmpty(c.getTurbineStream())) .map(c -> new Cluster(c.getName(), c.getTurbineStream())).forEach(clusters::add); } catch (Exception e) { LOG.warn("Failed getting clusters from {}", url, e); } return clusters; }
From source file:org.energyos.espi.thirdparty.web.custodian.AdministratorController.java
@RequestMapping(value = Routes.ROOT_SERVICE_STATUS, method = RequestMethod.GET) public String showServiceStatus(ModelMap model) { ApplicationInformation applicationInformation = resourceService.findById(1L, ApplicationInformation.class); String statusUri = applicationInformation.getAuthorizationServerAuthorizationEndpoint() + "/ReadServiceStatus"; // not sure this will work w/o the right seed information ///*from w w w.jav a 2s . c om*/ Authorization authorization = resourceService.findByResourceUri(statusUri, Authorization.class); RetailCustomer retailCustomer = authorization.getRetailCustomer(); String accessToken = authorization.getAccessToken(); String serviceStatus = "OK"; try { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Authorization", "Bearer " + accessToken); @SuppressWarnings({ "unchecked", "rawtypes" }) HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); // get the subscription HttpEntity<String> httpResult = restTemplate.exchange(statusUri, HttpMethod.GET, requestEntity, String.class); // import it into the repository ByteArrayInputStream bs = new ByteArrayInputStream(httpResult.getBody().toString().getBytes()); importService.importData(bs, retailCustomer.getId()); List<EntryType> entries = importService.getEntries(); // TODO: Use-Case 1 registration - service status } catch (Exception e) { // nothing there, so log the fact and move on. It will // get imported later. e.printStackTrace(); } model.put("serviceStatus", serviceStatus); return "/custodian/datacustodian/showservicestatus"; }
From source file:io.bosh.client.jobs.SpringJobs.java
private final Observable<File> getGzip(Consumer<UriComponentsBuilder> builderCallback) { // For responses that have a Content-Type of application/x-gzip, we need to // decompress them. The RestTemplate and HttpClient don't handle this for // us//from ww w . ja va2 s. co m return createObservable(() -> { UriComponentsBuilder builder = UriComponentsBuilder.fromUri(this.root); builderCallback.accept(builder); URI uri = builder.build().toUri(); return this.restOperations.execute(uri, HttpMethod.GET, null, new ResponseExtractor<File>() { @Override public File extractData(ClientHttpResponse response) throws IOException { return decompress(response.getBody()); } }); }); }
From source file:eu.cloudwave.wp5.common.rest.BaseRestClientTest.java
@Test public void testWithSingleHeader() throws UnsupportedEncodingException, IOException { mockServer.expect(requestTo(ANY_URL)).andExpect(method(HttpMethod.GET)) .andExpect(header(HEADER_ONE_NAME, HEADER_ONE_VALUE)) .andRespond(withSuccess(getResponseStub(), MediaType.APPLICATION_JSON)); final ResponseEntity<String> responseEntity = restClientMock.get(ANY_URL, String.class, RestRequestHeader.of(HEADER_ONE_NAME, HEADER_ONE_VALUE)); assertThat(responseEntity.getBody()).isEqualTo(getResponseStub()); }