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.zalando.github.spring.UsersTemplate.java
@Override public List<ExtPubKey> listPublicKeys() { return getRestOperations().exchange(buildUri("/user/keys"), HttpMethod.GET, null, extPubKeyListTypeRef) .getBody();/*from www.j a v a 2 s . com*/ }
From source file:com.example.RestTemplateStoreGatherer.java
/** * Get a page of stores from the backend, Blocking. * * @param page the page number (starting at 0) * @return a page of stores (or empty)//from w w w. j a va2s.c om */ private Flux<Store> page(int page) { Map<String, Object> map = this.restTemplate.exchange(url + "/stores?page={page}", HttpMethod.GET, null, new ParameterizedTypeReference<Map<String, Object>>() { }, page).getBody(); @SuppressWarnings("unchecked") List<Map<String, Object>> list = (List<Map<String, Object>>) ((Map<String, Object>) map.get("_embedded")) .get("stores"); List<Store> stores = new ArrayList<>(); for (Map<String, Object> store : list) { stores.add(new Store((String) store.get("id"), (String) store.get("name"))); } log.info("Fetched " + stores.size() + " stores for page: " + page); return Flux.fromIterable(stores); }
From source file:org.terasoluna.gfw.functionaltest.app.logging.LoggingTest.java
@Test public void test01_04_checkConsistencyXtrackMDCRequestToResponse() { // test Check consistency HTTP Request Header to Response Header HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("X-Track", "12345678901234567890123456789012"); ResponseEntity<byte[]> response = restTemplate.exchange( applicationContextUrl + "/logging/xTrackMDCPutFilter/1_4", HttpMethod.GET, new HttpEntity<byte[]>(requestHeaders), byte[].class); HttpHeaders headers = response.getHeaders(); assertThat(headers.getFirst("X-Track"), is("12345678901234567890123456789012")); }
From source file:cec.easyshop.storefront.filters.StorefrontFilterTest.java
@Test public void shouldNotStoreOriginalRefererOnAjax() throws IOException, ServletException { Mockito.when(request.getMethod()).thenReturn(HttpMethod.GET.toString()); Mockito.when(request.getHeader(StorefrontFilter.AJAX_REQUEST_HEADER_NAME)).thenReturn("1"); filter.doFilterInternal(request, response, filterChain); Mockito.verify(session, Mockito.never()).setAttribute(StorefrontFilter.ORIGINAL_REFERER, REQUESTEDURL); }
From source file:jp.go.aist.six.util.core.web.spring.Http.java
/** * HTTP GET: Receives the contents from the specified URL and writes them to the given stream. * * @throws HttpException//from ww w . j a va 2s. co m * when an exceptional condition occurred during the HTTP method execution. */ public static void getTo(final URL from_url, final OutputStream to_stream, final List<MediaType> accept_media_types) { _LOG_.debug("HTTP GET: from URL=" + from_url + ", accept=" + accept_media_types); AcceptHeaderRequestCallback callback = new AcceptHeaderRequestCallback(accept_media_types); OutputStreamResponseExtractor extractor = new OutputStreamResponseExtractor(to_stream); _execute(from_url, HttpMethod.GET, callback, extractor); }
From source file:com.mycompany.CPUTAuction.restapi.BidRestControllerTest.java
public void testreadBidByNameName() { int bid_id = 1001; HttpEntity<?> requestEntity = getHttpEntity(); ResponseEntity<Bid> responseEntity = restTemplate.exchange(URL + "api/bid/name/" + bid_id, HttpMethod.GET, requestEntity, Bid.class); Bid bid = responseEntity.getBody();/* w w w.j a v a 2s. c om*/ Assert.assertNotNull(bid); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.http.FilesDownloaderTest.java
@Test public void download_serverResponse401_excpetionWithProperMessageThrown() throws IOException { // given//from w w w .jav a 2 s .c om FilesDownloader downloader = new FilesDownloader(testCredentials, restTemplateMock); String expectedExceptionMessage = "Login to " + testCredentials.getHost() + " with credentials " + new String(Base64.decodeBase64(testCredentials.getBasicAuthToken().getBytes())) + " failed"; // when when(restTemplateMock.exchange(testCredentials.getHost() + testResource, HttpMethod.GET, HttpCommunication.basicAuthRequest(testCredentials.getBasicAuthToken()), byte[].class)) .thenThrow(new HttpClientErrorException(HttpStatus.UNAUTHORIZED)); // then thrown.expect(IOException.class); thrown.expectMessage(expectedExceptionMessage); downloader.download(testResource, testPath); }
From source file:org.openmhealth.shim.OAuth1Utils.java
/** * Signs an HTTP post request for cases where OAuth 1.0 posts are * required instead of GET./*from w w w . j av a2s .c o m*/ * * @param unsignedUrl - The unsigned URL * @param clientId - The external provider assigned client id * @param clientSecret - The external provider assigned client secret * @param token - The access token * @param tokenSecret - The 'secret' parameter to be used (Note: token secret != client secret) * @param oAuthParameters - Any additional parameters * @return The request to be signed and sent to external data provider. */ public static HttpRequestBase getSignedRequest(HttpMethod method, String unsignedUrl, String clientId, String clientSecret, String token, String tokenSecret, Map<String, String> oAuthParameters) throws ShimException { URL requestUrl = buildSignedUrl(unsignedUrl, clientId, clientSecret, token, tokenSecret, oAuthParameters); String[] signedParams = requestUrl.toString().split("\\?")[1].split("&"); HttpRequestBase postRequest = method == HttpMethod.GET ? new HttpGet(unsignedUrl) : new HttpPost(unsignedUrl); String oauthHeader = ""; for (String signedParam : signedParams) { String[] parts = signedParam.split("="); oauthHeader += parts[0] + "=\"" + parts[1] + "\","; } oauthHeader = "OAuth " + oauthHeader.substring(0, oauthHeader.length() - 1); postRequest.setHeader("Authorization", oauthHeader); CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(clientId, clientSecret); consumer.setSendEmptyTokens(false); if (token != null) { consumer.setTokenWithSecret(token, tokenSecret); } try { consumer.sign(postRequest); return postRequest; } catch (OAuthMessageSignerException | OAuthExpectationFailedException | OAuthCommunicationException e) { e.printStackTrace(); throw new ShimException("Could not sign POST request, cannot continue"); } }
From source file:fi.helsinki.opintoni.server.OodiServer.java
public void expectTeacherCoursesRequest(String teacherNumber, String sinceDateString, String responseFile) { server.expect(requestTo(teachingUrl(teacherNumber, sinceDateString))).andExpect(method(HttpMethod.GET)) .andRespond(/*from w w w. ja v a 2s. co m*/ withSuccess(SampleDataFiles.toText("oodi/" + responseFile), MediaType.APPLICATION_JSON)); }
From source file:com.orange.ngsi.client.NgsiRestClient.java
/** * Retrieve a context element//from w ww.ja va2s .com * @param url the URL of the broker * @param httpHeaders the HTTP header to use, or null for default * @param entityID the ID of the entity * @return a future for a ContextElementResponse */ public ListenableFuture<ContextElementResponse> getContextElement(String url, HttpHeaders httpHeaders, String entityID) { return request(HttpMethod.GET, url + entitiesPath + entityID, httpHeaders, null, ContextElementResponse.class); }