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.openlmis.fulfillment.service.stockmanagement.ValidSourceDestinationsStockManagementServiceTest.java
@Test public void shouldFindOne() { // given/*www . ja v a 2 s . c om*/ UUID facility = UUID.randomUUID(); ValidSourceDestinationDto destination = new ValidSourceDestinationDtoDataBuilder().withNode(facility) .build(); ResponseEntity<ValidSourceDestinationDto[]> response = new ResponseEntity<>( new ValidSourceDestinationDto[] { destination }, HttpStatus.OK); when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(service.getArrayResultClass()))).thenReturn(response); // when UUID program = UUID.randomUUID(); UUID facilityType = UUID.randomUUID(); Optional<ValidSourceDestinationDto> validSourceDestination = service.search(program, facilityType, facility); // then assertThat(validSourceDestination.isPresent(), is(true)); assertThat(validSourceDestination.get(), is(destination)); verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), eq(service.getArrayResultClass())); String uri = uriCaptor.getValue().toString(); String url = service.getServiceUrl() + getUrl(); assertThat(uri, allOf(startsWith(url), containsString("program=" + program), containsString("facilityType=" + facilityType))); HttpEntity<String> entity = entityCaptor.getValue(); assertAuthHeader(entity); assertThat(entity.getBody(), is(nullValue())); }
From source file:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilterTest.java
@Test public void should_remove__PERMISSION_UPDATE__from__GET__request() throws Exception { final TestingAuthenticationToken token = new TestingAuthenticationToken("user", "secret", Arrays.<GrantedAuthority>asList(Permission.INVOKE_QUERY, Permission.INVOKE_UPDATE)); setAuthentication(token);// w w w . j av a 2 s . c o m request.setMethod(HttpMethod.GET.name()); subject.doFilter(request, response, chain); assertThat(getAuthentication().getAuthorities(), Matchers.<GrantedAuthority>contains(Permission.INVOKE_QUERY)); }
From source file:com.muhardin.endy.training.ws.aplikasi.absen.rest.client.AbsenRestClient.java
public List<Karyawan> semuaKaryawan() { ParameterizedTypeReference<List<Karyawan>> typeRef = new ParameterizedTypeReference<List<Karyawan>>() { };/*from www . j a v a2s .c om*/ ResponseEntity<List<Karyawan>> response = restTemplate.exchange(SERVER_URL + "/karyawan/", HttpMethod.GET, null, typeRef); System.out.println("Response Status : " + response.getStatusCode()); return response.getBody(); }
From source file:com.himanshu.poc.springbootsec.SampleControllerSecurityTestIT.java
@Test public void testSecureGetWithToken() { ResponseEntity<String> response = new TestRestTemplate("Himanshu", "Bhardwaj") .getForEntity(url.concat("/secure/generate/token/Himanshu"), String.class); logger.info("Response is :->" + response); String tokenReceived = response.getBody(); Assert.assertThat(response.getStatusCode(), Matchers.equalTo(HttpStatus.OK)); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic ".concat(generateAuthorizationToken(tokenReceived))); HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers); ResponseEntity<String> response2 = new TestRestTemplate().exchange(url.concat("/secure/sample/test"), HttpMethod.GET, requestEntity, String.class); logger.info("Response2 is :->" + response2); Assert.assertThat(response2.getStatusCode(), Matchers.equalTo(HttpStatus.OK)); ResponseEntity<String> response3 = new TestRestTemplate() .exchange(url.concat("/secure/sample/test/forbidden"), HttpMethod.GET, requestEntity, String.class); logger.info("Response3 is :->" + response3); Assert.assertThat(response3.getStatusCode(), Matchers.equalTo(HttpStatus.FORBIDDEN)); }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping(value = "/login", method = RequestMethod.POST) public @ResponseBody String loginToJvoid( @RequestParam(required = false, value = "params") JSONObject jsonParams) { System.out.println("Login:jsonParams=>" + jsonParams.toString()); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(ServerUris.CUSTOMER_SERVER_URI + URIConstants.GET_CUSTOMER_BY_EMAIL) .queryParam("params", jsonParams); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); return returnString.getBody(); }
From source file:fi.helsinki.opintoni.server.CoursePageServer.java
public void expectTeacherCourseImplementationEventsRequest(String courseImplementationId) { server.expect(requestTo(eventsUrl(courseImplementationId))).andExpect(method(HttpMethod.GET)).andRespond( withSuccess(SampleDataFiles.toText("coursepage/teacherevents.json"), MediaType.APPLICATION_JSON)); }
From source file:fragment.web.SystemHealthControllerTest.java
@Test public void testRouting() throws Exception { logger.debug("Testing routing...."); DispatcherTestServlet servlet = this.getServletInstance(); Class<? extends SystemHealthController> controllerClass = controller.getClass(); Method expected = locateMethod(controllerClass, "health", new Class[] { String.class, int.class, ModelMap.class }); Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/health")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "showStatusDetails", new Class[] { String.class, String.class, String.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/health/show_status_details")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "getHealthStatusForServiceInstance", new Class[] { String.class, HttpServletRequest.class, ModelMap.class }); handler = servlet//w w w .ja v a2 s . c o m .recognize(getRequestTemplate(HttpMethod.GET, "/health/get_health_status_for_service_instance")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "showAddStatus", new Class[] { String.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/health/add_status")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "showAddSchedMaintenance", new Class[] { String.class, String.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/health/add_scheduled_maintenance")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "addStatus", new Class[] { ServiceNotificationForm.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/health/add_status")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "saveMaintenanceSchedule", new Class[] { ServiceNotificationForm.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/health/save_maintenance_schedule")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "updateMaintenanceSchedule", new Class[] { ServiceNotificationForm.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/health/update_maintenance_schedule")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "editStatusDetails", new Class[] { String.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/health/edit_status_details")); Assert.assertEquals(expected, handler); }
From source file:fi.helsinki.opintoni.server.FlammaServer.java
public void expectStudentOpenUniversityNews() { server.expect(requestTo(flammaBaseUrl + "/infotaulu/atom-tiedotteet-avoin.xml")) .andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(toText("flamma/studentopenuniversitynews.xml"), MediaType.TEXT_XML)); }
From source file:com.hatta.consumer.App.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void listAllCustomers(AuthTokenInfo tokenInfo) { Assert.notNull(tokenInfo, "Authenticate first please......"); RestTemplate restTemplate = new RestTemplate(); //// w ww.ja va 2 s. c o m // HttpHeaders headers = new HttpHeaders(); // headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<String> request = new HttpEntity<String>(getHeaders()); ResponseEntity<List> response = restTemplate.exchange( REST_SERVICE_URI + "/api/user" + QPM_ACCESS_TOKEN + tokenInfo.getAccess_token(), HttpMethod.GET, request, List.class); List<LinkedHashMap<String, Object>> customerMap = (List<LinkedHashMap<String, Object>>) response.getBody(); // // List<LinkedHashMap<String, Object>> customerMap = restTemplate.getForObject(REST_SERVICE_URI + "/api/user", List.class); if (customerMap != null) { System.out.println("Retrieve all customers:"); for (LinkedHashMap<String, Object> map : customerMap) { System.out.println("Customer : id=" + map.get("id") + ", Name=" + map.get("name") + ", Address=" + map.get("email") + ", Email=" + map.get("password") + map.get("enabled")); } } else { System.out.println("No customer exist----------"); } }
From source file:com.springsource.html5expense.security.EndpointTokenServices.java
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException { // TODO: Probably should catch REST client exceptions and rethrow as AuthenticationException HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + accessToken); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<OAuth2Authentication> response = restTemplate.exchange(oauthAuthenticationUrl, HttpMethod.GET, requestEntity, OAuth2Authentication.class); OAuth2Authentication oauth2Authentication = response.getBody(); return oauth2Authentication; }