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.awesomeagile.integrations.hackpad.HackpadClientTest.java
@Test public void testGetHackpad() { mockServer.expect(requestTo("http://test/api/1.0/pad/12345/content/latest.html")) .andExpect(method(HttpMethod.GET)) .andRespond(withSuccess("<html>works!</html>", MediaType.TEXT_HTML)); String res = client.getHackpad(new PadIdentity("12345")); assertEquals("<html>works!</html>", res); }
From source file:fi.helsinki.opintoni.integration.unisport.UnisportRestClient.java
@Override public UnisportUserReservations getUserReservations(Long unisportUserId, Locale locale) { return restTemplate.exchange("{baseUrl}/api/v1/{locale}/ext/opintoni/reservations", HttpMethod.GET, getAuthorizationHeader(unisportUserId), new ParameterizedTypeReference<UnisportUserReservations>() { }, baseUrl, locale.getLanguage()).getBody(); }
From source file:me.j360.boot.standard.test.SessionRedisApplicationTests.java
@Test public void sessionExpiry() throws Exception { String port = null;/*from w w w . jav a 2s . c om*/ try { ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(J360Configuration.class) .properties("server.port:0").initializers(new ServerPortInfoApplicationContextInitializer()) .run(); port = context.getEnvironment().getProperty("local.server.port"); } catch (RuntimeException ex) { if (!redisServerRunning(ex)) { return; } } URI uri = URI.create("http://localhost:" + port + "/"); RestTemplate restTemplate = new RestTemplate(); ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class); String uuid1 = response.getBody(); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Cookie", response.getHeaders().getFirst("Set-Cookie")); RequestEntity<Void> request = new RequestEntity<Void>(requestHeaders, HttpMethod.GET, uri); String uuid2 = restTemplate.exchange(request, String.class).getBody(); assertThat(uuid1, is(equalTo(uuid2))); Thread.sleep(5000); String uuid3 = restTemplate.exchange(request, String.class).getBody(); assertThat(uuid2, is(not(equalTo(uuid3)))); }
From source file:org.kurento.repository.test.RangeGetTests.java
@Test public void test() throws Exception { String id = "logo.png"; RepositoryItem item;/*from w w w . jav a 2 s .co m*/ try { item = getRepository().findRepositoryItemById(id); } catch (NoSuchElementException e) { item = getRepository().createRepositoryItem(id); uploadFile(new File("test-files/" + id), item); } RepositoryHttpPlayer player = item.createRepositoryHttpPlayer(); String url = player.getURL(); player.setAutoTerminationTimeout(100000); // Following sample // http://stackoverflow.com/questions/8293687/sample-http-range-request-session RestTemplate httpClient = getRestTemplate(); { HttpHeaders requestHeaders = new HttpHeaders(); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertTrue("The server doesn't accept ranges", response.getHeaders().containsKey("Accept-ranges")); assertTrue("The server doesn't accept ranges with bytes", response.getHeaders().get("Accept-ranges").contains("bytes")); } long fileLength = 0; { // Range: bytes=0- HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Range", "bytes=0-"); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertEquals("The server doesn't respond with http status code 206 to a request with ranges", HttpStatus.PARTIAL_CONTENT, response.getStatusCode()); fileLength = Long.parseLong(response.getHeaders().get("Content-Length").get(0)); } { HttpHeaders requestHeaders = new HttpHeaders(); long firstByte = fileLength - 3000; long lastByte = fileLength - 1; long numBytes = lastByte - firstByte + 1; requestHeaders.set("Range", "bytes=" + firstByte + "-" + lastByte); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, requestHeaders); ResponseEntity<byte[]> response = httpClient.exchange(url, HttpMethod.GET, requestEntity, byte[].class); System.out.println(response); assertEquals("The server doesn't respond with http status code 206 to a request with ranges", response.getStatusCode(), HttpStatus.PARTIAL_CONTENT); long responseContentLength = Long.parseLong(response.getHeaders().get("Content-Length").get(0)); assertEquals("The server doesn't send the requested bytes", numBytes, responseContentLength); assertEquals("The server doesn't send the requested bytes", responseContentLength, response.getBody().length); } }
From source file:org.seasar.doma.boot.DomaBootSampleSimpleApplicationTest.java
@Test public void test() { Message message1 = restTemplate.getForObject(UriComponentsBuilder.fromUriString("http://localhost") .port(port).queryParam("text", "hello").build().toUri(), Message.class); assertThat(message1.id, is(1));//www . j a va2 s. c om assertThat(message1.text, is("hello")); Message message2 = restTemplate.getForObject(UriComponentsBuilder.fromUriString("http://localhost") .port(port).queryParam("text", "world").build().toUri(), Message.class); assertThat(message2.id, is(2)); assertThat(message2.text, is("world")); { List<Message> messages = restTemplate .exchange(UriComponentsBuilder.fromUriString("http://localhost").port(port).build().toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference) .getBody(); assertThat(messages.size(), is(2)); assertThat(messages.get(0).id, is(message1.id)); assertThat(messages.get(0).text, is(message1.text)); assertThat(messages.get(1).id, is(message2.id)); assertThat(messages.get(1).text, is(message2.text)); } { List<Message> messages = restTemplate.exchange( UriComponentsBuilder.fromUriString("http://localhost").port(port).queryParam("page", "1") .queryParam("size", "1").build().toUri(), HttpMethod.GET, HttpEntity.EMPTY, typedReference).getBody(); assertThat(messages.size(), is(1)); assertThat(messages.get(0).id, is(message2.id)); assertThat(messages.get(0).text, is(message2.text)); } }
From source file:comsat.sample.mustache.SampleWebMustacheApplicationTests.java
@Test public void testMustacheErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody().contains("Something went wrong: 404 Not Found")); }
From source file:comsat.sample.velocity.SampleWebVelocityApplicationTests.java
@Test public void testVelocityErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertTrue("Wrong body:\n" + responseEntity.getBody(), responseEntity.getBody().contains("Something went wrong: 404 Not Found")); }
From source file:com.consol.citrus.http.client.BasicAuthClientRequestFactoryTest.java
@Test public void testCreateRequestWithAuthScope() throws IOException { ClientHttpRequest request = requestFactory.createRequest(URI.create("http://localhost:8088"), HttpMethod.GET); Assert.assertNotNull(request);//from ww w.j a v a 2 s .c om }
From source file:com.tce.oauth2.spring.client.controller.UserInfoController.java
@RequestMapping("/userinfo") public String index(HttpServletRequest request) { if (request.getSession().getAttribute("access_token") == null) { return "redirect:/"; }//www . j a va2s . com String accessToken = (String) request.getSession().getAttribute("access_token"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Bearer " + accessToken); HttpEntity<?> entity = new HttpEntity<>(headers); ResponseEntity<User> response = restTemplate.exchange(OAUTH_URL + "/userinfo", HttpMethod.GET, entity, User.class); if (response.getStatusCode().is4xxClientError()) { return "redirect:/login"; } User user = response.getBody(); request.getSession(false).setAttribute("username", user.getUsername()); return "redirect:/"; }
From source file:org.energyos.espi.thirdparty.repository.impl.ResourceRESTRepositoryImplTests.java
@SuppressWarnings("unchecked") @Test//from w ww.j av a2 s .c o m public void get_fetchesResource() throws JAXBException { repository.get(authorization, uri); verify(template).exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), any(Class.class)); }