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:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilterTest.java
@Test public void should_keep_anonymous_type() throws Exception { final AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", "principal", Collections.<GrantedAuthority>singletonList(Permission.INVOKE_UPDATE)); token.setDetails("details"); setAuthentication(token);/*from w w w . j a v a2 s . co m*/ request.setMethod(HttpMethod.GET.name()); subject.doFilter(request, response, chain); final Authentication filtered = getAuthentication(); assertThat(filtered, instanceOf(AnonymousAuthenticationToken.class)); assertThat(filtered.getPrincipal(), equalTo(token.getPrincipal())); assertThat(filtered.getDetails(), equalTo(token.getDetails())); }
From source file:com.wisemapping.test.rest.RestAccountITCase.java
private ResponseEntity<RestUser> findUserByEmail(HttpHeaders requestHeaders, RestTemplate templateRest, final String email) { HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders); // Add extension only to avoid the fact that the last part is extracted ... final String url = BASE_REST_URL + "/admin/users/email/{email}.json"; return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class, email); }
From source file:org.openlmis.fulfillment.service.referencedata.BaseReferenceDataServiceTest.java
@Test(expected = DataRetrievalException.class) public void shouldThrowExceptionIfThereIsOtherProblemWithFindingById() throws Exception { // given//from www .j av a2 s .co m BaseReferenceDataService<T> service = prepareService(); UUID id = UUID.randomUUID(); // when when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(service.getResultClass()))).thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); service.findOne(id); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchPharmaceuticals.java
/** * Method, where all pharmaceuticals are read from server. * All heavy lifting is made here./*from w w w .j a v a 2 s . c o m*/ * * @param params omitted here * @return list of fetched pharmaceuticals */ @Override protected List<Pharmaceutical> 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_PHARMACEUTICAL; setState(RUNNING, R.string.working_ws_pharmaceutical); 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 { // Make the network request Log.d(TAG, url); ResponseEntity<PharmaceuticalList> response = restTemplate.exchange(url, HttpMethod.GET, entity, PharmaceuticalList.class); PharmaceuticalList body = response.getBody(); if (body != null) { return body.getPharmaceuticals(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:com.appglu.impl.StorageTemplateTest.java
@Test(expected = AppGluRestClientException.class) public void streamStorageFile_eTagDoesNotMatch() { downloadMockServer.expect(requestTo(URL)).andExpect(method(HttpMethod.GET)) .andRespond(withStatus(HttpStatus.OK).body(CONTENT).headers(responseHeaders)); this.storageOperations.streamStorageFile(new StorageFile(URL), new InputStreamCallback() { public void doWithInputStream(InputStream inputStream) throws IOException { //do not read the content so the md5 will not be calculated and then will not match with the server side }//from w w w . ja v a 2 s .c o m }); }
From source file:com.ge.predix.acceptance.test.zone.admin.DefaultZoneAuthorizationIT.java
/** * 1. Create a token from zone issuer with scopes for accessing: a. zone specific resources, AND b. * acs.zones.admin/*from w ww . ja v a 2 s . c o m*/ * * 2. Try to access a zone specific resource . This should work 3. Try to access /v1/zone - THIS SHOULD FAIL * * @throws Exception */ public void testAccessGlobalResourceWithZoneIssuer() throws Exception { OAuth2RestTemplate zone2AcsTemplate = this.acsRestTemplateFactory.getACSZone2RogueTemplate(); HttpHeaders zoneTwoHeaders = new HttpHeaders(); zoneTwoHeaders.set(PolicyHelper.PREDIX_ZONE_ID, this.zoneHelper.getZone2Name()); // Write a resource to zone2. This should work ResponseEntity<Object> responseEntity = this.privilegeHelper.postResources(zone2AcsTemplate, zoneHelper.getAcsBaseURL(), zoneTwoHeaders, new BaseResource("/sites/sanramon")); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.NO_CONTENT); // Try to get global resource from global/baseUrl. This should FAIL try { zone2AcsTemplate.exchange(this.zoneHelper.getAcsBaseURL() + "/v1/zone/" + this.zone2Name, HttpMethod.GET, null, Zone.class); Assert.fail("Able to access non-zone specific resource with a zone specific issuer token!"); } catch (OAuth2AccessDeniedException e) { // expected } // Try to get global resource from zone2Url. This should FAIL try { zone2AcsTemplate.exchange(this.zoneHelper.getAcsBaseURL() + "/v1/zone/" + this.zone2Name, HttpMethod.GET, new HttpEntity<>(zoneTwoHeaders), Zone.class); Assert.fail("Able to access non-zone specific resource from a zone specific URL, " + "with a zone specific issuer token!"); } catch (InvalidRequestException e) { // expected } }
From source file:com.cemeterylistingswebtest.test.rest.RegistrationControllerTest.java
@Test(enabled = false) public void testreadClubById() { String cemeteryID = "2"; HttpEntity<?> requestEntity = getHttpEntity(); ResponseEntity<Cemetery> responseEntity = restTemplate.exchange(URL + "api/Registration/id/" + cemeteryID, HttpMethod.GET, requestEntity, Cemetery.class); Cemetery cemetery = responseEntity.getBody(); Assert.assertNotNull(cemetery);/*from w ww. ja v a2s . c o m*/ }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchElectrodeSystems.java
/** * Method, where all electrodeSystems are read from server. * All heavy lifting is made here./*from www . j av a2s . c o m*/ * * @param params omitted here * @return list of fetched electrodeSystems */ @Override protected List<ElectrodeSystem> 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_ELECTRODE_SYSTEMS; setState(RUNNING, R.string.working_ws_electrode_system); 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 { // Make the network request Log.d(TAG, url); ResponseEntity<ElectrodeSystemList> response = restTemplate.exchange(url, HttpMethod.GET, entity, ElectrodeSystemList.class); ElectrodeSystemList body = response.getBody(); if (body != null) { return body.getElectrodeSystems(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:org.client.one.service.OAuthAuthenticationService.java
public Profile getCurrentUserProfile(String token) throws JSONException { RestOperations rest = new RestTemplate(); HttpHeaders headersA = new HttpHeaders(); headersA.set("Authorization", "Bearer " + token); ResponseEntity<String> responseA = rest.exchange(oauthServerBaseURL + "/resources/profile/read", HttpMethod.GET, new HttpEntity<String>(headersA), String.class); JSONObject profile = new JSONObject(responseA.getBody()); profile = profile.getJSONObject("profile"); Profile u = new Profile(); u.setFirstName(profile.getString("firstName")); u.setLastName(profile.getString("lastName")); u.setPhoneNumber(profile.getString("phoneNumber")); u.setUsername(profile.getString("username")); return u;//from w w w. j a v a2 s .co m }
From source file:com.acc.test.ProductWebServiceTest.java
@Test() public void testGetProductByCode_Success_XML_Deep() { final HttpEntity<String> requestEntity = new HttpEntity<String>(getXMLHeaders()); final ResponseEntity<ProductData> response = template.exchange(URL + "/{code}", HttpMethod.GET, requestEntity, ProductData.class, TestConstants.PRODUCT_CODE); final ProductData productData = response.getBody(); assertEquals(TestConstants.PRODUCT_CODE, productData.getCode()); assertEquals("EASYSHARE V1253, Black", productData.getName()); assertEquals(5, productData.getImages().size()); }