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:fi.helsinki.opintoni.integration.leiki.LeikiRestClient.java
public <T> List<T> getLeikiItemsData(URI uri, ParameterizedTypeReference<LeikiResponse<T>> typeReference) { LeikiData<T> leikiData = restTemplate.exchange(uri, HttpMethod.GET, null, typeReference).getBody().data; return leikiData.items != null ? leikiData.items : Lists.newArrayList(); }
From source file:org.openlmis.fulfillment.service.BaseCommunicationServiceTest.java
@Test public void shouldRetryObtainingAccessTokenIfResponseBodyIsEmpty() throws Exception { // given/* w w w .j a v a 2 s . com*/ BaseCommunicationService<T> service = prepareService(); HttpStatusCodeException exception = mock(HttpStatusCodeException.class); when(exception.getStatusCode()).thenReturn(HttpStatus.UNAUTHORIZED); when(exception.getResponseBodyAsString()).thenReturn(""); // when when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(service.getArrayResultClass()))).thenThrow(exception); expectedException.expect(DataRetrievalException.class); service.findAll("", RequestParameters.init()); verify(authService, times(1)).clearTokenCache(); verify(authService, times(2)).obtainAccessToken(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchExperiments.java
/** * Method, where all experiments are read from server. * All heavy lifting is made here./* w w w .j av a2 s .com*/ * * @param params not used (omitted) here * @return list of fetched experiments */ @Override protected List<Experiment> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_EXPERIMENTS; setState(RUNNING, R.string.working_ws_experiments); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { //obtain all public records if qualifier is all if (Values.SERVICE_QUALIFIER_ALL.equals(qualifier)) { String countUrl = url + "count"; ResponseEntity<RecordCount> count = restTemplate.exchange(countUrl, HttpMethod.GET, entity, RecordCount.class); url += "public/" + count.getBody().getPublicRecords(); } else url += qualifier; // Make the network request Log.d(TAG, url); ResponseEntity<ExperimentList> response = restTemplate.exchange(url, HttpMethod.GET, entity, ExperimentList.class); ExperimentList body = response.getBody(); if (body != null) { return body.getExperiments(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:com.github.dactiv.fear.user.web.AccountController.java
/** * ??//from w ww. j av a 2 s.c om * * @param entity map * @param request http servlet request * * @return ??:WEB-INF/page/index.ftl * * @throws Exception */ @RequestMapping(value = "registration", method = { RequestMethod.GET, RequestMethod.POST }) public String registration(@RequestParam Map<String, Object> entity, HttpServletRequest request) throws Exception { if (request.getMethod().equals(HttpMethod.GET.name())) { return "registration"; } else { accountService.registration(entity); String username = entity.get("username").toString(); String password = entity.get("password").toString(); SecurityUtils.getSubject() .login(new UsernamePasswordToken(username, password, request.getRemoteHost())); return "redirect:/account/user-profile"; } }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRouteCreatingStepTest.java
@Test public void createAppRoute_allCloudFoundryCallsOccured() throws Exception { // given// w ww .ja v a 2 s .c o m AppRouteCreatingStep step = new AppRouteCreatingStep(restTemplateMock, testCfApi, testAppGuid); // when when(domainsResponseMock.getBody()).thenReturn(validDomainsResponse); when(routesResponseMock.getBody()).thenReturn(oneRouteResponse); step.createAppRoute(testSpaceGuid, testSubdomain); // then verify(restTemplateMock).exchange(eq(testCfDomainsEndpoint), same(HttpMethod.GET), eq(HttpCommunication.simpleJsonRequest()), same(String.class)); verify(restTemplateMock).exchange(eq(testCfGetRoutesEndpoint), same(HttpMethod.GET), eq(HttpCommunication.simpleJsonRequest()), same(String.class), eq(testSubdomain), eq(testDomainGuid)); verify(restTemplateMock).exchange(eq(testCfBindRouteEndpoint), same(HttpMethod.PUT), eq(HttpCommunication.simpleJsonRequest()), same(String.class), eq(testAppGuid), eq(testRouteGuid)); }
From source file:uk.ac.ebi.ep.ebeye.EbeyeRestServiceTest.java
/** * Test of queryEbeyeForAccessions method, of class EbeyeRestService. *//*from w w w . j av a 2 s . c o m*/ @Test public void testQueryEbeyeForAccessions_String_boolean() { LOGGER.info("queryEbeyeForAccessions paginate:false"); try { boolean paginate = false; String url = ebeyeIndexUrl.getDefaultSearchIndexUrl() + "?format=json&size=100&query="; String json = getJsonFile(ebeyeJsonFile); mockRestServer.expect(requestTo(url)).andExpect(method(HttpMethod.GET)) .andRespond(withSuccess(json, MediaType.APPLICATION_JSON)); EbeyeSearchResult searchResult = restTemplate.getForObject(url.trim(), EbeyeSearchResult.class); Set<String> accessions = new LinkedHashSet<>(); for (Entry entry : searchResult.getEntries()) { accessions.add(entry.getUniprotAccession()); } List<String> expResult = accessions.stream().distinct().collect(Collectors.toList()); String accession = expResult.stream().findAny().get(); List<String> result = ebeyeRestService.queryEbeyeForAccessions(query, paginate); mockRestServer.verify(); assertThat(result.stream().findAny().get(), containsString(accession)); assertEquals(expResult, result); } catch (IOException ex) { LOGGER.error(ex.getMessage(), ex); } }
From source file:org.drugis.addis.config.SecurityConfig.java
@Override protected void configure(HttpSecurity http) throws Exception { String[] whitelist = { "/", "/trialverse", "/trialverse/**", "/patavi", // allow POST mcda models anonymously "/favicon.ico", "/favicon.png", "/app/**", "/auth/**", "/signin", "/signup", "/**/modal/*.html", "/manual.html" }; // Disable CSFR protection on the following urls: List<AntPathRequestMatcher> requestMatchers = Arrays.asList(whitelist).stream() .map(AntPathRequestMatcher::new).collect(Collectors.toList()); CookieCsrfTokenRepository csrfTokenRepository = new CookieCsrfTokenRepository(); csrfTokenRepository.setCookieHttpOnly(false); http.formLogin().loginPage("/signin").loginProcessingUrl("/signin/authenticate") .failureUrl("/signin?param.error=bad_credentials").and().authorizeRequests().antMatchers(whitelist) .permitAll().antMatchers(HttpMethod.GET, "/**").permitAll().antMatchers(HttpMethod.POST, "/**") .authenticated().antMatchers(HttpMethod.PUT, "/**").authenticated() .antMatchers(HttpMethod.DELETE, "/**").authenticated().and().rememberMe().and().exceptionHandling() .authenticationEntryPoint(new Http403ForbiddenEntryPoint()).and() .apply(new SpringSocialConfigurer().alwaysUsePostLoginUrl(false)).and().csrf() .csrfTokenRepository(csrfTokenRepository) .requireCsrfProtectionMatcher( request -> !(requestMatchers.stream().anyMatch(matcher -> matcher.matches(request)) || Optional.fromNullable(request.getHeader("X-Auth-Application-Key")).isPresent() || HttpMethod.GET.toString().equals(request.getMethod()))) .and().setSharedObject(ApplicationContext.class, context); http.addFilterBefore(new AuthenticationFilter(authenticationManager()), BasicAuthenticationFilter.class); }
From source file:org.craftercms.profile.services.impl.AbstractProfileRestClientBase.java
protected <T> T doGetForObject(String url, ParameterizedTypeReference<T> responseType, Object... uriVariables) throws ProfileException { try {//from w w w.j av a2s. com return restTemplate.exchange(url, HttpMethod.GET, null, responseType, uriVariables).getBody(); } catch (RestServiceException e) { handleRestServiceException(e); } catch (Exception e) { handleException(e); } return null; }
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategyTest.java
@Test public void testCheckStatus() throws IOException, URISyntaxException, ResponseStatusException { final URI location = new URI( "https://my.eu1.fredhopperservices.com:443/fas:test1/trigger/load-data/2001-01-01_21-12-21"); mockServer.expect(requestTo(/*from w ww. ja v a 2 s.c o m*/ "https://my.eu1.fredhopperservices.com:443/fas:test1/trigger/load-data/2001-01-01_21-12-21/status")) .andExpect(method(HttpMethod.GET)).andRespond(withSuccess("SUCCESS", MediaType.TEXT_PLAIN)); final String response = strategy.checkStatus(config, location); Assert.assertTrue(response.contains("SUCCESS")); }