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.appverse.web.framework.backend.frontfacade.rest.MvcExceptionHandlerTests.java
@Test public void testExceptionHandler() throws Exception { // Login first TestLoginInfo loginInfo = login();/*from w ww .j av a 2s. c om*/ HttpHeaders headers = new HttpHeaders(); headers.set("Cookie", loginInfo.getJsessionid()); HttpEntity<String> entity = new HttpEntity<String>(headers); // Calling protected resource - requires CSRF token UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl("http://localhost:" + port + baseApiPath + "/exc") .queryParam(DEFAULT_CSRF_PARAMETER_NAME, loginInfo.getXsrfToken()); ResponseEntity<ResponseDataVO> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, ResponseDataVO.class); ResponseDataVO data = responseEntity.getBody(); assertEquals(500, data.getErrorVO().getCode()); assertTrue("contains message", data.getErrorVO().getMessage().contains("kk")); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); }
From source file:com.catalog.core.Api.java
@Override public int login(String username, String password) { setStartTime();//w ww . java 2s . c om String url = "http://" + IP + EXTENSION + "/resources/j_spring_security_check"; // Set the username and password for creating a Basic Auth request HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); // Make the HTTP GET request, marshaling the response from JSON to // an array of Events try { restTemplate.exchange(url, HttpMethod.GET, requestEntity, Object.class); } catch (Exception e) { // Unauthorized, probably. // maybe check for network status? e.printStackTrace(); if (e.getMessage().contains("Unauthorized")) return UNAUTHORIZED; return BAD_CONNECTION; } // everything went fine setLoginCredentials(username, password); getElapsedTime("login - "); return SUCCESS; }
From source file:org.openlmis.fulfillment.service.ObjReferenceExpanderTest.java
@Test public void shouldNotFailIfResourceDoesNotExist() { when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(Map.class))) .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); objReferenceExpander.expandDto(testDto, singleton(EXPANDED_OBJECT_REFERENCE_DTO_FIELD)); assertNotNull(testDto);//from w w w. jav a2s.com ExpandedObjectReferenceDto actual = testDto.getExpandedObjectReferenceDto(); checkOriginalProperties(actual); // No expanded properties should be set assertNull(actual.getExpandedStringProperty()); assertNull(actual.getExpandedListProperty()); assertNull(actual.getExpandedUuidProperty()); assertNull(actual.getExpandedNestedProperty()); }
From source file:fi.helsinki.opintoni.integration.oodi.OodiRestClient.java
public <T> List<T> getOodiData(String url, ParameterizedTypeReference<OodiResponse<T>> typeReference, Object... uriVariables) { List<T> data;/* w ww .j ava 2 s .c om*/ try { data = Optional .ofNullable( restTemplate.exchange(url, HttpMethod.GET, null, typeReference, uriVariables).getBody()) .map(r -> r.data).orElse(Lists.newArrayList()); } catch (Exception e) { LOGGER.error("Caught OodiIntegrationException", e); throw new OodiIntegrationException(e.getMessage(), e); } return data; }
From source file:com.acc.test.ProductWebServiceTest.java
@Test() public void testGetProductByCode_Success_XML_Options_Description() { final HttpEntity<String> requestEntity = new HttpEntity<String>(getXMLHeaders()); final ResponseEntity<ProductData> response = template.exchange(URL + "/{code}?options=DESCRIPTION", 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()); assertTrue("Description may not be null!", productData.getDescription() != null); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchReservationsToDate.java
/** * Method, where all reservations to specified date are read from server. * All heavy lifting is made here./* w w w. j ava 2s . co m*/ * * @param params only one TimeContainer parameter is allowed here - specifies day, month and year * @return list of fetched reservations */ @Override protected List<Reservation> doInBackground(TimeContainer... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_RESERVATION; if (params.length == 1) { TimeContainer time = params[0]; url = url + time.getDay() + "-" + time.getMonth() + "-" + time.getYear(); } else { Log.e(TAG, "Invalid params count! There must be one TimeContainer instance"); setState(ERROR, "Invalid params count! There must be one TimeContainer instance"); return Collections.emptyList(); } setState(RUNNING, R.string.working_ws_msg); // Populate the HTTP Basic Authentication header with the username and // password HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); 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<ReservationList> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<Object>(requestHeaders), ReservationList.class); ReservationList body = response.getBody(); if (body != null) { return body.getReservations(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilterTest.java
@Test public void should_keep_rememberme_type() throws Exception { final RememberMeAuthenticationToken token = new RememberMeAuthenticationToken("key", "principal", Collections.<GrantedAuthority>singletonList(Permission.INVOKE_UPDATE)); token.setDetails("details"); setAuthentication(token);/*from w w w. j a v a2s .com*/ request.setMethod(HttpMethod.GET.name()); subject.doFilter(request, response, chain); final Authentication filtered = getAuthentication(); assertThat(filtered, instanceOf(RememberMeAuthenticationToken.class)); assertThat(filtered.getPrincipal(), equalTo(token.getPrincipal())); assertThat(filtered.getDetails(), equalTo(token.getDetails())); }
From source file:org.craftercms.profile.services.impl.AbstractProfileRestClientBase.java
protected <T> T doGetForObject(URI url, ParameterizedTypeReference<T> responseType) throws ProfileException { try {/*from w w w .j a v a 2 s . c o m*/ return restTemplate.exchange(url, HttpMethod.GET, null, responseType).getBody(); } catch (RestServiceException e) { handleRestServiceException(e); } catch (Exception e) { handleException(e); } return null; }