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:cec.easyshop.storefront.filters.StorefrontFilterTest.java
@Test public void shouldStoreOriginalRefererOnGET() throws IOException, ServletException { Mockito.when(request.getMethod()).thenReturn(HttpMethod.GET.toString()); filter.doFilterInternal(request, response, filterChain); Mockito.verify(session).setAttribute(StorefrontFilter.ORIGINAL_REFERER, REQUESTEDURL); }
From source file:com.marklogic.samplestack.security.ApplicationSecurity.java
@Override /**/* www .jav a 2 s .co m*/ * Standard practice in Spring Security is to provide * this implementation method for building security. This method * configures the endpoints' security characteristics. * @param http Security object projided by the framework. */ protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers(HttpMethod.GET, "/session", "/questions/**", "/tags/**").permitAll() .and().authorizeRequests().antMatchers(HttpMethod.POST, "/search").permitAll().and() .authorizeRequests().antMatchers("/questions/**", "/contributors/**").authenticated().and() .authorizeRequests().anyRequest().denyAll(); http.formLogin().failureHandler(failureHandler).successHandler(successHandler).permitAll().and().logout() .logoutSuccessHandler(logoutSuccessHandler).permitAll(); http.csrf().disable(); http.exceptionHandling().authenticationEntryPoint(entryPoint) .accessDeniedHandler(samplestackAccessDeniedHandler); }
From source file:jetbrains.buildServer.vsoRooms.rest.impl.VSOTeamRoomsAPIConnectionImpl.java
@NotNull public Collection<TeamRoom> getListOfRooms(@NotNull String account) { final HttpEntity<String> request = new HttpEntity<String>(getRequestHeaders()); final ResponseEntity<TeamRoomList> responseEntity = myRestTemplate.exchange(getListOfRoomsUrl(account), HttpMethod.GET, request, TeamRoomList.class); return responseEntity.getBody().getRooms(); }
From source file:org.openlmis.fulfillment.service.referencedata.FacilityReferenceDataServiceTest.java
@Test public void shouldFindFacilitiesByIds() { // given/*from w ww.j a va 2s. c o m*/ UUID id = UUID.randomUUID(); UUID id2 = UUID.randomUUID(); List<UUID> ids = Arrays.asList(id, id2); FacilityDto facility = generateInstance(); facility.setId(id); FacilityDto anotherFacility = generateInstance(); anotherFacility.setId(id2); Map<String, Object> payload = new HashMap<>(); payload.put("id", ids); ResponseEntity response = mock(ResponseEntity.class); // when when(response.getBody()).thenReturn(new FacilityDto[] { facility, anotherFacility }); when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(service.getArrayResultClass()))).thenReturn(response); Collection<FacilityDto> facilities = service.findByIds(ids); // then verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), eq(service.getArrayResultClass())); assertTrue(facilities.contains(facility)); assertTrue(facilities.contains(anotherFacility)); String actualUrl = uriCaptor.getValue().toString(); assertTrue(actualUrl.startsWith(service.getServiceUrl() + service.getUrl())); assertTrue(actualUrl.contains(id.toString())); assertTrue(actualUrl.contains(id2.toString())); assertAuthHeader(entityCaptor.getValue()); }
From source file:fi.helsinki.opintoni.server.UnisportServer.java
public void expectUserReservations() { server.expect(requestTo(unisportBaseUrl + "/api/v1/fi/ext/opintoni/reservations")) .andExpect(method(HttpMethod.GET)) .andExpect(header("Authorization", MockUnisportJWTService.MOCK_JWT_TOKEN)) .andRespond(withSuccess(toText("unisport/user-reservations.json"), MediaType.APPLICATION_JSON)); }
From source file:fi.helsinki.opintoni.server.OodiServer.java
public void expectTeacherEventsRequest(String teacherNumber) { server.expect(requestTo(teacherEventsUrl(teacherNumber))).andExpect(method(HttpMethod.GET)).andRespond( withSuccess(SampleDataFiles.toText("oodi/teacherevents.json"), MediaType.APPLICATION_JSON)); }
From source file:com.bodybuilding.argos.discovery.ClusterListDiscoveryTest.java
@Test public void testGetClusters_withHttpError() { RestTemplate restTemplate = new RestTemplate(); MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); mockServer.expect(requestTo("http://127.0.0.1")).andExpect(method(HttpMethod.GET)) .andRespond(withServerError()); ClusterListDiscovery discovery = new ClusterListDiscovery(Sets.newHashSet("http://127.0.0.1"), restTemplate);/*from w ww . ja va 2 s. c om*/ Collection<Cluster> clusters = discovery.getCurrentClusters(); mockServer.verify(); assertNotNull(clusters); assertEquals(0, clusters.size()); }
From source file:com.compomics.colims.core.service.impl.UniProtServiceImpl.java
@Override public Map<String, String> getUniProtByAccession(String accession) throws RestClientException, IOException { Map<String, String> uniProt = new HashMap<>(); try {/*from w ww.jav a 2s.com*/ // Set XML content type explicitly to force response in XML (If not spring gets response in JSON) HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML)); HttpEntity<String> entity = new HttpEntity<>("parameters", headers); ResponseEntity<String> response = restTemplate.exchange(UNIPROT_BASE_URL + "/" + accession + ".xml", HttpMethod.GET, entity, String.class); String responseBody = response.getBody(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(responseBody)); Document document = (Document) builder.parse(is); document.getDocumentElement().normalize(); NodeList recommendedName = document.getElementsByTagName("recommendedName"); Node node = recommendedName.item(0); Element element = (Element) node; if (element.getElementsByTagName("fullName").item(0).getTextContent() != null && !element.getElementsByTagName("fullName").item(0).getTextContent().equals("")) { uniProt.put("description", element.getElementsByTagName("fullName").item(0).getTextContent()); } NodeList organism = document.getElementsByTagName("organism"); node = organism.item(0); element = (Element) node; if (element.getElementsByTagName("name").item(0).getTextContent() != null && !element.getElementsByTagName("name").item(0).getTextContent().equals("")) { uniProt.put("species", element.getElementsByTagName("name").item(0).getTextContent()); } NodeList dbReference = document.getElementsByTagName("dbReference"); node = dbReference.item(0); element = (Element) node; if (element.getAttribute("id") != null && !element.getAttribute("id").equals("")) { uniProt.put("taxid", element.getAttribute("id")); } } catch (HttpClientErrorException ex) { LOGGER.error(ex.getMessage(), ex); //ignore the exception if the namespace doesn't correspond to an ontology if (!ex.getStatusCode().equals(HttpStatus.NOT_FOUND)) { throw ex; } } catch (ParserConfigurationException | SAXException ex) { java.util.logging.Logger.getLogger(UniProtServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } return uniProt; }
From source file:com.epl.ticketws.services.QueryService.java
public T query(String url, String method, String accept, Class<T> rc, Map<String, String> parameters) { try {//from w w w . j a v a2 s. co m URI uri = new URL(url).toURI(); long timestamp = new Date().getTime(); HttpMethod httpMethod; if (method.equalsIgnoreCase("post")) { httpMethod = HttpMethod.POST; } else { httpMethod = HttpMethod.GET; } String stringToSign = getStringToSign(uri, httpMethod.name(), timestamp, parameters); // logger.info("String to sign: " + stringToSign); String authorization = generate_HMAC_SHA1_Signature(stringToSign, password + license); // logger.info("Authorization string: " + authorization); // Setting Headers HttpHeaders headers = new HttpHeaders(); if (accept.equalsIgnoreCase("json")) { headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); } else { headers.setAccept(Arrays.asList(MediaType.TEXT_XML)); } headers.add("Authorization", authorization); headers.add("OB_DATE", "" + timestamp); headers.add("OB_Terminal", terminal); headers.add("OB_User", user); headers.add("OB_Channel", channel); headers.add("OB_POS", pos); headers.add("Content-Type", "application/x-www-form-urlencoded"); HttpEntity<String> entity; if (httpMethod == HttpMethod.POST) { // Adding post parameters to POST body String parameterStringBody = getParametersAsString(parameters); entity = new HttpEntity<String>(parameterStringBody, headers); // logger.info("POST Body: " + parameterStringBody); } else { entity = new HttpEntity<String>(headers); } RestTemplate restTemplate = new RestTemplate( new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>(); interceptors.add(new LoggingRequestInterceptor()); restTemplate.setInterceptors(interceptors); // Converting to UTF-8. OB Rest replies in windows charset. //restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName(UTF_8))); if (accept.equalsIgnoreCase("json")) { restTemplate.getMessageConverters().add(0, new org.springframework.http.converter.json.MappingJackson2HttpMessageConverter()); } else { restTemplate.getMessageConverters().add(0, new org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter()); } ResponseEntity<T> response = restTemplate.exchange(uri, httpMethod, entity, rc); if (!response.getStatusCode().is2xxSuccessful()) throw new HttpClientErrorException(response.getStatusCode()); return response.getBody(); } catch (HttpClientErrorException e) { logger.error(e.getMessage()); e.printStackTrace(); } catch (MalformedURLException e) { logger.error(e.getMessage()); e.printStackTrace(); } catch (SignatureException e) { logger.error(e.getMessage()); e.printStackTrace(); } catch (URISyntaxException e) { logger.error(e.getMessage()); e.printStackTrace(); } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); } return null; }