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:org.slc.sli.dashboard.client.RESTClient.java
/** * Make a request to a REST service and convert the result to JSON * /*w w w . j a v a2s .c o m*/ * @param path * the unique portion of the requested REST service URL * @param token * not used yet * * @param fullEntities * flag for returning expanded entities from the API * * @return a {@link JsonElement} if the request is successful and returns valid JSON, otherwise * null. * @throws NoSessionException */ public String makeJsonRequestWHeaders(String path, String token) { if (token != null) { URLBuilder url = null; if (!path.startsWith("http")) { url = new URLBuilder(getSecurityUrl()); url.addPath(path); } else { url = new URLBuilder(path); } HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); HttpEntity entity = new HttpEntity(headers); logger.debug("Accessing API at: {}", url); HttpEntity<String> response = null; try { response = exchange(template, url.toString(), HttpMethod.GET, entity, String.class); } catch (HttpClientErrorException e) { logger.debug("Catch HttpClientException: {}", e.getStatusCode()); } if (response == null) { return null; } return response.getBody(); } logger.debug("Token is null in call to RESTClient for path {}", path); return null; }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRouteCreatingStepTest.java
@Before public void setUp() { this.restTemplateMock = mock(RestTemplate.class); this.domainsResponseMock = mock(ResponseEntity.class); when(restTemplateMock.exchange(testCfDomainsEndpoint, HttpMethod.GET, HttpCommunication.simpleJsonRequest(), String.class)).thenReturn(domainsResponseMock); this.routesResponseMock = mock(ResponseEntity.class); when(restTemplateMock.exchange(testCfGetRoutesEndpoint, HttpMethod.GET, HttpCommunication.simpleJsonRequest(), String.class, testSubdomain, testDomainGuid)) .thenReturn(routesResponseMock); this.routeCreatedResponseMock = mock(ResponseEntity.class); when(restTemplateMock.exchange(testCfCreateRouteEndpoint, HttpMethod.POST, HttpCommunication.postRequest(createRouteRequestBody), String.class)) .thenReturn(routeCreatedResponseMock); }
From source file:example.users.UserControllerClientTests.java
private UserPayload issueGet(String path, MediaType mediaType) { HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.ACCEPT, mediaType.toString()); return template.exchange(path, HttpMethod.GET, new HttpEntity<Void>(headers), UserPayload.class).getBody(); }
From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImplTest.java
@Test public void testCreatePageWithPaginationModeSingleWithOrphanFailSafe() { final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig(); swaggerConfluenceConfig.setAncestorId(null); final String xhtml = IOUtils.readFull( AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream("/swagger-petstore-xhtml-example.html")); when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(String.class))) .thenReturn(responseEntity, responseEntity); when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))) .thenReturn(responseEntity); when(responseEntity.getBody()).thenReturn(GET_RESPONSE_NOT_FOUND, GET_RESPONSE_FOUND, POST_RESPONSE); final ArgumentCaptor<HttpEntity> httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class); xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); verify(restTemplate, times(2)).exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(String.class)); verify(restTemplate).exchange(any(URI.class), eq(HttpMethod.POST), httpEntityCaptor.capture(), eq(String.class)); final HttpEntity<String> capturedHttpEntity = httpEntityCaptor.getValue(); final String expectedPostBody = IOUtils.readFull(AsciiDocToXHtmlServiceImplTest.class .getResourceAsStream("/swagger-confluence-create-json-body-example.json")); assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity); assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody()); }
From source file:org.hypernovae.entapps.actuator.ui.SampleActuatorUiApplicationTests.java
@Test public void testError() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/error", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("<html>")); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("<body>")); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("Please contact the operator with the above information")); }
From source file:org.openlmis.fulfillment.service.referencedata.RightReferenceDataServiceTest.java
@Test public void shouldReturnNullIfRightCannotBeFound() throws Exception { // given//from w w w . j a v a2s. c om String name = "testRight"; RightDto[] rights = new RightDto[0]; RightReferenceDataService service = (RightReferenceDataService) prepareService(); ResponseEntity<RightDto[]> response = mock(ResponseEntity.class); // when when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(service.getArrayResultClass()))).thenReturn(response); when(response.getBody()).thenReturn(rights); RightDto right = service.findRight(name); // then verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), eq(service.getArrayResultClass())); URI uri = uriCaptor.getValue(); String url = service.getServiceUrl() + service.getUrl() + "search?name=" + name; assertThat(uri.toString(), is(equalTo(url))); assertThat(right, is(nullValue())); assertAuthHeader(entityCaptor.getValue()); assertThat(entityCaptor.getValue().getBody(), is(nullValue())); }
From source file:comsat.sample.actuator.ui.SampleActuatorUiApplicationTests.java
@Test public void testError() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/error", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getBody()).contains("<html>").contains("<body>") .contains("Please contact the operator with the above information"); }
From source file:de.zib.gndms.gndmc.utils.HTTPGetter.java
public int get(String url) throws NoSuchAlgorithmException, KeyManagementException { return get(HttpMethod.GET, url, (HttpHeaders) null); }
From source file:edu.wisc.cypress.dao.benstmt.RestBenefitStatementDao.java
@Override public void getBenefitStatement(String emplid, int year, String docId, String mode, ProxyResponse proxyResponse) {/*from w w w . j a v a 2 s . co m*/ final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("HRID", emplid); final String yearStr = Integer.toString(year); final String yearCode; if (yearStr.length() > 2) { yearCode = yearStr.substring(2); } else if (yearStr.length() < 2) { yearCode = StringUtils.leftPad(yearStr, 2, '0'); } else { yearCode = yearStr; } this.restOperations.proxyRequest(proxyResponse, this.statementUrl, HttpMethod.GET, httpHeaders, yearCode, docId, mode); }
From source file:com.greglturnquist.spring.social.ecobee.api.impl.ThermostatTemplateTest.java
@Test public void testGetAllThermostats() throws Exception { final Selection selection = Selection.allThermostats(); selection.getSelection().setIncludeRuntime(true); selection.getSelection().setIncludeSettings(true); selection.getSelection().setIncludeSensors(true); final String selectionStr = UriUtils.encodeQueryParam(this.getObjectMapper().writeValueAsString(selection), "UTF-8"); mockServer.expect(requestTo("https://api.ecobee.com/1/thermostat?json=" + selectionStr)) .andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(jsonResource("thermostats"), MediaType.APPLICATION_JSON)); final List<Thermostat> thermostats = ecobee.thermostatOperations().getAllThermostats(); assertThat(thermostats.size(), equalTo(1)); final Thermostat thermostat = thermostats.get(0); assertThat(thermostat.getIdentifier(), equalTo("161775386723")); assertThat(thermostat.getName(), equalTo("My Test Thermostat")); assertThat(thermostat.getLastModified(), equalTo("2011-01-28 23:40:25")); assertThat(thermostat.getSettings().getHvacMode(), equalTo("heat")); assertThat(thermostat.getSettings().getVent(), is(nullValue())); }