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:nd.dev.framework.basedemo.controllers.StudentActionServerSideTest.java
public void getAddress() { request.setMethod(HttpMethod.GET.name()); request.setRequestURI("/student/{id}"); HashMap<String, String> pathVariablesMap = new HashMap<>(1); pathVariablesMap.put("id", "1"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariablesMap); Class<?>[] parameterTypes = new Class<?>[] { Integer.class }; ModelAndView mv = null;/* w w w.ja v a 2s. c o m*/ try { mv = handlerAdapter.handle(request, response, new HandlerMethod(studentAction, "retrieve", parameterTypes)); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.work.petclinic.SampleWebUiApplicationTests.java
@After public void cleanSession() throws Exception { ResponseEntity<String> page = sendRequest("http://localhost:" + this.port, HttpMethod.GET); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.set("_csrf", csrfValue); httpHeaders.set("X-CSRF-TOKEN", csrfValue); page = sendRequest("http://localhost:" + this.port + "/logout", HttpMethod.GET, form); assertEquals(HttpStatus.FOUND, page.getStatusCode()); if (page.getStatusCode() == HttpStatus.FOUND) { page = sendRequest(page.getHeaders().getLocation(), HttpMethod.GET); }/*w ww . j av a 2 s . co m*/ httpHeaders = null; csrfValue = null; }
From source file:com.wmfsystem.eurekaserver.broadcast.Server.java
public void run() { try {// w ww . j a v a 2s . co m socket = new DatagramSocket(DEFAULT_PORT); } catch (Exception ex) { System.out.println("Problem creating socket on port: " + DEFAULT_PORT); } packet = new DatagramPacket(new byte[1], 1); while (true) { try { socket.receive(packet); System.out.println("Received from: " + packet.getAddress() + ":" + packet.getPort()); byte[] outBuffer = new java.util.Date().toString().getBytes(); packet.setData(outBuffer); packet.setLength(outBuffer.length); socket.setBroadcast(true); socket.send(packet); Set<InetAddress> localAddress = getLocalAddress(); Set<String> ips = localAddress.stream().map(ad -> ad.getHostAddress()).collect(Collectors.toSet()) .stream().sorted().collect(Collectors.toSet()); RestTemplate template = new RestTemplate(); ips.forEach(ip -> { template.exchange("http://" + packet.getAddress().getHostAddress().concat(":8000?ip={ip}"), HttpMethod.GET, HttpEntity.EMPTY, Void.class, ip.concat(":8000")); try { template.exchange("http://" + packet.getAddress().getHostAddress().concat(":8000?ip={ip}"), HttpMethod.GET, HttpEntity.EMPTY, Void.class, ip.concat(":8000")); } catch (Exception e) { e.printStackTrace(); } }); System.out.println("Message ----> " + packet.getAddress().getHostAddress()); } catch (IOException ie) { ie.printStackTrace(); } } }
From source file:org.starfishrespect.myconsumption.android.tasks.UserUpdater.java
@Override protected Void doInBackground(Void... params) { RestTemplate template = new RestTemplate(); HttpHeaders httpHeaders = CryptoUtils.createHeaders(username, password); template.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); try {/*from w w w. j av a 2 s .c o m*/ ResponseEntity<UserDTO> response = template.exchange( SingleInstance.getServerUrl() + "users/" + username, HttpMethod.GET, new HttpEntity<>(httpHeaders), UserDTO.class); UserDTO user = response.getBody(); UserData userData = new UserData(user); for (String sensor : user.getSensors()) { try { ResponseEntity<SensorDTO> responseSensor = template.exchange( SingleInstance.getServerUrl() + "sensors/" + sensor, HttpMethod.GET, new HttpEntity<>(httpHeaders), SensorDTO.class); SensorDTO SensorDTO = responseSensor.getBody(); userData.addSensor(new SensorData(SensorDTO)); } catch (RestClientException e) { e.printStackTrace(); } } publishProgress(userData); } catch (RestClientException e) { e.printStackTrace(); publishProgress(null); } return null; }
From source file:io.fabric8.quickstarts.camel.ApplicationOpenshiftIT.java
@Test @RunAsClient//from w ww. ja v a2 s.c o m @InSequence(2) public void booksTest() { TestRestTemplate restTemplate = new TestRestTemplate(); ResponseEntity<List<Book>> response = restTemplate.exchange( "http://" + client.adapt(OpenShiftClient.class).routes().withName("camel-rest-jpa").get().getSpec() .getHost() + "/camel-rest-jpa/books", HttpMethod.GET, null, new ParameterizedTypeReference<List<Book>>() { }); Assertions.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); List<Book> books = response.getBody(); Assertions.assertThat(books).hasSize(2); Assertions.assertThat(books).element(0).hasFieldOrPropertyWithValue("item", "Camel") .hasFieldOrPropertyWithValue("description", "Camel in Action"); Assertions.assertThat(books).element(1).hasFieldOrPropertyWithValue("item", "ActiveMQ") .hasFieldOrPropertyWithValue("description", "ActiveMQ in Action"); }
From source file:uk.ac.ebi.ep.ebeye.EbeyeRestServiceTest.java
/** * Test of ebeyeAutocompleteSearch method, of class EbeyeRestService. *//*from ww w . ja v a 2s . c o m*/ @Test public void testEbeyeAutocompleteSearch() { try { LOGGER.info("ebeyeAutocompleteSearch"); String searchTerm = "phos"; String url = ebeyeIndexUrl.getDefaultSearchIndexUrl() + "/autocomplete?term=" + searchTerm + "&format=json"; String filename = "suggestions.json"; String json = getJsonFile(filename); mockRestServer.expect(requestTo(url)).andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(json, MediaType.APPLICATION_JSON)); EbeyeAutocomplete aut = restTemplate.getForObject(url.trim(), EbeyeAutocomplete.class); List<Suggestion> expResult = aut.getSuggestions().stream().sorted().collect(Collectors.toList()); List<Suggestion> result = ebeyeRestService.ebeyeAutocompleteSearch(searchTerm).stream().sorted() .collect(Collectors.toList()); Suggestion suggestion = expResult.stream().sorted().findAny().get(); mockRestServer.verify(); assertThat(result, hasItem(suggestion)); } catch (IOException ex) { LOGGER.error(ex.getMessage(), ex); } }
From source file:HCEngine.java
@Override public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception { ResponseEntity<String> stringResponseEntity = null; try (CloseableHttpClient hc = createCloseableHttpClient()) { for (int i = 0; i < requestOptions.getCount(); i++) { final HttpHeaders headers = new HttpHeaders(); for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) { headers.put(e.getKey(), Collections.singletonList(e.getValue())); }//w w w. j av a 2 s . co m final HttpEntity<Void> requestEntity = new HttpEntity<>(headers); RestTemplate template = new RestTemplate(new HttpComponentsClientHttpRequestFactory(hc)); stringResponseEntity = template.exchange(requestOptions.getUrl(), HttpMethod.GET, requestEntity, String.class); System.out.println(stringResponseEntity.getBody()); } return stringResponseEntity; } }
From source file:org.zalando.github.spring.IssuesTemplate.java
@Override public List<Issue> listUserIssues() { return getRestOperations() .exchange(buildUri("/user/issues?per_page=25"), HttpMethod.GET, null, issueListTypeRef).getBody(); }
From source file:org.energyos.espi.thirdparty.repository.impl.ResourceRESTRepositoryImplTests.java
@SuppressWarnings("unchecked") @Before/*w w w . j a v a 2s .co m*/ public void before() { repository = new ResourceRESTRepositoryImpl(); marshaller = mock(Jaxb2Marshaller.class); template = mock(RestTemplate.class); ResponseEntity<String> response = new ResponseEntity<String>(HttpStatus.OK); when(template.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), any(Class.class))) .thenReturn(response); repository.setRestTemplate(template); repository.setJaxb2Marshaller(marshaller); authorization = new Authorization(); authorization.setAccessToken("token"); uri = Routes.DATA_CUSTODIAN_REST_USAGE_POINT_GET; }
From source file:fr.putnami.pwt.plugin.ajaxbot.filter.DeleteCacheFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; if (HttpMethod.GET.toString().equals(request.getMethod()) && null != request.getParameter(QUERY_PARAM_RESET_FILTER)) { this.resetCache(); }/*from w w w. j a va 2 s. c o m*/ chain.doFilter(req, resp); }