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:de.muenchen.eaidemo.AbstractIntegrationTest.java
/** * @param requestMappingUrl should be exactly the same as defined in your * RequestMapping value attribute (including the parameters in {}) * RequestMapping(value = yourRestUrl)/*from w w w . ja v a2s .c o m*/ * @param serviceListReturnTypeClass should be the the generic type of the * list the service returns, eg: List<serviceListReturnTypeClass> * @param parametersInOrderOfAppearance should be the parameters of the * requestMappingUrl ({}) in order of appearance * @return the result of the service, or null on error */ protected <T> List<T> getList(final String requestMappingUrl, final Class<T> serviceListReturnTypeClass, final Object... parametersInOrderOfAppearance) { final ObjectMapper mapper = new ObjectMapper(); final TestRestTemplate restTemplate = new TestRestTemplate(); final HttpEntity<String> requestEntity = new HttpEntity<String>(new HttpHeaders()); try { // Retrieve list final ResponseEntity<List> entity = restTemplate.exchange(getBaseUrl() + requestMappingUrl, HttpMethod.GET, requestEntity, List.class, parametersInOrderOfAppearance); final List<Map<String, String>> entries = entity.getBody(); final List<T> returnList = new ArrayList<T>(); for (final Map<String, String> entry : entries) { // Fill return list with converted objects returnList.add(mapper.convertValue(entry, serviceListReturnTypeClass)); } return returnList; } catch (final Exception ex) { // Handle exceptions } return null; }
From source file:org.cloudfoundry.caldecott.client.TunnelHelper.java
public static Map<String, String> getTunnelServiceInfo(CloudFoundryClient client, String serviceName) { String urlToUse = getTunnelUri(client) + "/services/" + serviceName; HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Auth-Token", getTunnelAuth(client)); HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); HttpEntity<String> response = restTemplate.exchange(urlToUse, HttpMethod.GET, requestEntity, String.class); String json = response.getBody().trim(); Map<String, String> svcInfo = new HashMap<String, String>(); try {/*from w w w . ja v a 2s. co m*/ svcInfo = convertJsonToMap(json); } catch (IOException e) { return new HashMap<String, String>(); } if (svcInfo.containsKey("url")) { String svcUrl = svcInfo.get("url"); try { URI uri = new URI(svcUrl); String[] userInfo; if (uri.getUserInfo().contains(":")) { userInfo = uri.getUserInfo().split(":"); } else { userInfo = new String[2]; userInfo[0] = uri.getUserInfo(); userInfo[1] = ""; } svcInfo.put("user", userInfo[0]); svcInfo.put("username", userInfo[0]); svcInfo.put("password", userInfo[1]); svcInfo.put("host", uri.getHost()); svcInfo.put("hostname", uri.getHost()); svcInfo.put("port", "" + uri.getPort()); svcInfo.put("path", (uri.getPath().startsWith("/") ? uri.getPath().substring(1) : uri.getPath())); svcInfo.put("vhost", svcInfo.get("path")); } catch (URISyntaxException e) { } } return svcInfo; }
From source file:org.trustedanalytics.h2oscoringengine.publisher.http.FilesDownloaderTest.java
@Test public void download_serverResponse404_excpetionWithProperMessageThrown() throws IOException { // given/*from w w w .j a va2 s . co m*/ FilesDownloader downloader = new FilesDownloader(testCredentials, restTemplateMock); String expectedExceptionMessage = "Resource not found."; // when when(restTemplateMock.exchange(testCredentials.getHost() + testResource, HttpMethod.GET, HttpCommunication.basicAuthRequest(testCredentials.getBasicAuthToken()), byte[].class)) .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); // then thrown.expect(IOException.class); thrown.expectMessage(expectedExceptionMessage); downloader.download(testResource, testPath); }
From source file:com.aktios.appthree.server.service.OAuthAuthenticationService.java
public String getAuthorizationCode(String accessTokenA, String redirectUri, String appTokenClientTwo) { RestOperations rest = new RestTemplate(); HttpHeaders headersA = new HttpHeaders(); headersA.set("Authorization", "Bearer " + accessTokenA); ResponseEntity<String> resAuth2 = rest.exchange( MessageFormat.format( "{0}/oauth/authorize?" + "client_id={1}&response_type=code&redirect_uri={2}&scope=read,write", oauthServerBaseURL, appTokenClientTwo, redirectUri), HttpMethod.GET, new HttpEntity<String>(headersA), String.class); String sessionId = resAuth2.getHeaders().get("Set-Cookie").get(0); int p1 = sessionId.indexOf("=") + 1; int p2 = sessionId.indexOf(";"); sessionId = sessionId.substring(p1, p2); headersA.add("Cookie", "JSESSIONID=" + sessionId); resAuth2 = rest.exchange(/* w ww.j av a 2 s .co m*/ MessageFormat.format("{0}/oauth/authorize?" + "user_oauth_approval=true&authorize=Authorize", oauthServerBaseURL), HttpMethod.POST, new HttpEntity<String>(headersA), String.class); String code = resAuth2.getHeaders().get("location").get(0); p1 = code.lastIndexOf("=") + 1; code = code.substring(p1); return code; }
From source file:net.eusashead.hateoas.hal.response.impl.HalResponseBuilderITCase.java
@Test public void tesGetNotModified() throws Exception { // Execute controller method this.mockMvc//from w w w .ja v a 2 s . co m .perform(request(HttpMethod.GET, "http://localhost/order/123") .contentType(HalHttpMessageConverter.HAL_JSON).accept(HalHttpMessageConverter.HAL_JSON) .header("If-None-Match", "W/\"123456789\"")) .andExpect(status().isNotModified()).andReturn(); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.CreatingPlanVisibilityStepTest.java
License:asdf
@Test public void addServicePlanVisibility_allCloduFoundryCallsOccured() throws Exception { // given/*from w ww . j ava 2 s . c o m*/ CreatingPlanVisibilityStep step = new CreatingPlanVisibilityStep(testCfApi, restTemplateMock); // when when(serviceGuidResponseMock.getBody()).thenReturn(serviceGuidResponse); when(servicePlanResponseMock.getBody()).thenReturn(planGuidResponse); step.addServicePlanVisibility(testOrgGuid, testServiceName); // then verify(restTemplateMock).exchange(testCfServiceGuidEndpoint, HttpMethod.GET, HttpCommunication.simpleJsonRequest(), String.class, testServiceName); verify(restTemplateMock).exchange(testCfServicePlanEndpoint, HttpMethod.GET, HttpCommunication.simpleJsonRequest(), String.class, testServiceGuid); verify(restTemplateMock).exchange(testCfPlanVisibilityEndpoint, HttpMethod.POST, HttpCommunication.postRequest(setVisibilityRequestBody), String.class); }
From source file:fi.helsinki.opintoni.service.usefullink.UsefulLinkService.java
public SearchPageTitleDto searchPageTitle(SearchPageTitleDto searchPageTitleDto) throws NotFoundException { try {/* w ww .j a va2 s . co m*/ HttpHeaders headers = new HttpHeaders(); headers.setAccept(Lists.newArrayList(MediaType.TEXT_HTML)); headers.add("User-Agent", "Mozilla"); HttpEntity<String> entity = new HttpEntity<>("parameters", headers); ResponseEntity<String> responseEntity = linkUrlLoaderRestTemplate.exchange(searchPageTitleDto.searchUrl, HttpMethod.GET, entity, String.class); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Document document = Jsoup.parse(responseEntity.getBody()); searchPageTitleDto.searchResult = document.title(); } } catch (Exception e) { } return searchPageTitleDto; }
From source file:org.openlmis.fulfillment.service.referencedata.PeriodReferenceDataServiceTest.java
@Test public void shouldFindPeriodsByIds() { // given//from w ww .jav a 2 s . com UUID id = UUID.randomUUID(); UUID id2 = UUID.randomUUID(); List<UUID> ids = Arrays.asList(id, id2); ProcessingPeriodDto period = generateInstance(); period.setId(id); ProcessingPeriodDto anotherPeriod = generateInstance(); anotherPeriod.setId(id2); Map<String, Object> payload = new HashMap<>(); payload.put("id", ids); ResponseEntity response = mock(ResponseEntity.class); // when when(response.getBody()).thenReturn(new PageDto<>(new PageImpl<>(Arrays.asList(period, anotherPeriod)))); when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), any(ParameterizedTypeReference.class))).thenReturn(response); List<ProcessingPeriodDto> periods = service.findByIds(ids); // then verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), any(ParameterizedTypeReference.class)); assertTrue(periods.contains(period)); assertTrue(periods.contains(anotherPeriod)); String actualUrl = uriCaptor.getValue().toString(); assertTrue(actualUrl.startsWith(service.getServiceUrl() + service.getUrl())); assertTrue(actualUrl.contains(id.toString())); assertTrue(actualUrl.contains(id2.toString())); assertAuthHeader(entityCaptor.getValue()); }
From source file:fragment.web.HomeControllerTest.java
@Test public void testHomeRouting() throws Exception { logger.debug("Testing routing...."); DispatcherTestServlet servlet = this.getServletInstance(); Method expected = locateMethod(controller.getClass(), "home", new Class[] { Tenant.class, String.class, Boolean.TYPE, ModelMap.class, HttpSession.class, HttpServletRequest.class }); Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/home")); Assert.assertEquals(expected, handler); expected = locateMethod(controller.getClass(), "forum", new Class[] { HttpServletResponse.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/forum")); Assert.assertEquals(expected, handler); expected = locateMethod(controller.getClass(), "acceptCookies", new Class[] {}); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/acceptCookies")); Assert.assertEquals(expected, handler); }
From source file:fragment.web.AccessDecisionTest.java
@Test public void testAuthenticatedUrls() { Object[][] authenticatedAccessValid = { { HttpMethod.GET, "/portal/portal/" }, { HttpMethod.GET, "/portal/portal/home" }, { HttpMethod.GET, "/portal/portal/profile" }, { HttpMethod.GET, "/portal/portal/profile/edit" }, { HttpMethod.POST, "/portal/portal/profile" }, { HttpMethod.POST, "/portal/portal/acceptCookies" }, { HttpMethod.GET, "/portal/portal/users" }, { HttpMethod.GET, "/portal/portal/users/new" }, { HttpMethod.POST, "/portal/portal/users" }, { HttpMethod.GET, "/portal/portal/users/1" }, { HttpMethod.PUT, "/portal/portal/users/1" }, { HttpMethod.GET, "/portal/portal/tenants" }, { HttpMethod.POST, "/portal/portal/tenants" }, { HttpMethod.GET, "/portal/portal/tenants/new" }, { HttpMethod.GET, "/portal/portal/tenants/1" }, { HttpMethod.GET, "/portal/portal/tenants/1/edit" }, { HttpMethod.PUT, "/portal/portal/tenants/1" }, { HttpMethod.GET, "/portal/portal/tasks/" }, { HttpMethod.GET, "/portal/portal/tasks/1/" }, { HttpMethod.GET, "/portal/portal/tasks/approval-task/1" }, { HttpMethod.POST, "/portal/portal/tasks/approval-task" } }; User user = getRootUser();//w w w .j ava 2 s .c om Authentication auth = createAuthenticationToken(user); verify(auth, authenticatedAccessValid, null); }