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:com.appglu.impl.StorageTemplateTest.java
@Test(expected = AppGluRestClientException.class) public void streamStorageFile_invalidETag() { String invalidETag = "\"1234567890\""; HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setETag(invalidETag); 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 { IOUtils.copy(inputStream, new ByteArrayOutputStream()); }//from w w w . java2 s. c o m }); }
From source file:org.esupportail.filex.web.WebController.java
@RequestMapping("VIEW") protected ModelAndView renderView(RenderRequest request, RenderResponse response) throws Exception { ModelMap model = new ModelMap(); final PortletPreferences prefs = request.getPreferences(); String eppnAttr = prefs.getValue(PREF_EPPN_ATTR, null); String restUrl = prefs.getValue(PREF_REST_URL, null); Map userInfos = (Map) request.getAttribute(PortletRequest.USER_INFO); String eppn = (String) userInfos.get(eppnAttr); log.info("Try to get FileX info for " + eppn); try {/*from ww w . j a v a2 s. c om*/ MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>(); headers.add("eppn", eppn); HttpEntity<MultiValueMap<String, String>> httpRequest = new HttpEntity<MultiValueMap<String, String>>( null, headers); ResponseEntity<Filex> filexEntity = restTemplate.exchange(restUrl, HttpMethod.GET, httpRequest, Filex.class); log.debug("FileX info for " + eppn + " : " + filexEntity.getBody().toString()); model.put("filex", filexEntity.getBody()); } catch (HttpClientErrorException e) { return new ModelAndView("error", model); } model.put("serviceUrl", prefs.getValue(PREF_SERVICE_URL, null)); return new ModelAndView("view", model); }
From source file:org.openlmis.fulfillment.service.BaseCommunicationServiceTest.java
@Test public void shouldRetryObtainingAccessToken() throws Exception { // given/*from w w w . java2s. c o m*/ BaseCommunicationService<T> service = prepareService(); HttpStatusCodeException exception = mock(HttpStatusCodeException.class); when(exception.getStatusCode()).thenReturn(HttpStatus.UNAUTHORIZED); when(exception.getResponseBodyAsString()) .thenReturn("{\"error\":\"invalid_token\",\"error_description\":\"" + UUID.randomUUID() + "}"); // 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:access.test.PiazzaEnvironmentTests.java
@Test public void testResourcesDoNotExist() { Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces"), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{\"result\": \"all good\"}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.xml"), Mockito.eq(HttpMethod.PUT), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{\"result\": \"all good\"}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{invalid JSON}", HttpStatus.OK)); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores"), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(String.class))) .thenReturn(new ResponseEntity<String>("{\"result\": \"all good\"}", HttpStatus.OK)); piazzaEnvironment.initializeEnvironment(); assertTrue(true); // no error occurred }
From source file:org.moserp.common.modules.ModuleRegistry.java
public void loadResources() { for (String serviceId : discoveryClient.getServices()) { log.debug("Analyzing service " + serviceId); if (!serviceId.endsWith(MODULE_POST_FIX)) { continue; }/* ww w . j av a 2s .c o m*/ URI uri = getInstanceUri(serviceId); if (uri == null) { continue; } ParameterizedTypeReference<Map<String, ResourceSupport>> typeReference = new ParameterizedTypeReference<Map<String, ResourceSupport>>() { }; String url = uri.toString() + "/structure"; ResponseEntity<Map<String, ResourceSupport>> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, typeReference); Map<String, ResourceSupport> groupMap = responseEntity.getBody(); for (String group : groupMap.keySet()) { ResourceSupport support = groupMap.get(group); for (Link link : support.getLinks()) { resourceToModuleMap.put(link.getRel(), serviceId); } } } }
From source file:fi.helsinki.opintoni.server.OodiServer.java
public void expectStudentStudyAttainmentsRequest(String studentNumber) { server.expect(requestTo(studyAttainmentsUrl(studentNumber))).andExpect(method(HttpMethod.GET)).andRespond( withSuccess(SampleDataFiles.toText("oodi/studyattainments.json"), MediaType.APPLICATION_JSON)); }
From source file:com.expedia.client.WunderGroundClient.java
@Override public ResponseEntity<ResponseWrapper> getJSONResponse(Object request) { ResponseEntity<ResponseWrapper> responseEntity = null; Weather weather = null;/* w ww .java 2 s .c o m*/ if (request instanceof Weather) { weather = (Weather) request; List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.APPLICATION_JSON); HttpHeaders headers = new HttpHeaders(); headers.setAccept(mediaTypes); HttpEntity<Weather> httpEntity = new HttpEntity<Weather>(null, headers); try { System.out.println("Hitting weather service for JSON response!"); responseEntity = restTemplate.exchange(weatherServiceJsonUrl, HttpMethod.GET, httpEntity, ResponseWrapper.class, weatherApiKey, weather.getZipCode()); } catch (RuntimeException e) { e.printStackTrace(); weather.setErrorDesc("Get failed" + e.getMessage()); } } return responseEntity; }
From source file:com.wisemapping.test.rest.RestAccountITCase.java
private ResponseEntity<RestUser> findUser(HttpHeaders requestHeaders, RestTemplate templateRest, URI location) { HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders); final String url = HOST_PORT + location; return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class); }
From source file:com.xyxy.platform.examples.showcase.functional.rest.UserRestFT.java
/** * exchange()?Headers.//from w w w . j av a 2s . c o m * xml??. * jdk connection. */ @Test public void getUserAsXML() { // Http Basic? HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(com.google.common.net.HttpHeaders.AUTHORIZATION, Servlets.encodeHttpBasic("admin", "admin")); System.out.println("Http header is" + requestHeaders); HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); try { HttpEntity<UserDTO> response = jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET, requestEntity, UserDTO.class, 1L); assertThat(response.getBody().getLoginName()).isEqualTo("admin"); assertThat(response.getBody().getName()).isEqualTo("?"); assertThat(response.getBody().getTeamId()).isEqualTo(1); // ?XML HttpEntity<String> xml = jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET, requestEntity, String.class, 1L); System.out.println("xml output is " + xml.getBody()); } catch (HttpStatusCodeException e) { fail(e.getMessage()); } }
From source file:de.zib.gndms.gndmc.utils.HTTPGetter.java
private EnhancedResponseExtractor get(final String url, final RequestCallback requestCallback) throws NoSuchAlgorithmException, KeyManagementException { return get(HttpMethod.GET, url, requestCallback); }