Example usage for org.springframework.http HttpMethod GET

List of usage examples for org.springframework.http HttpMethod GET

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod GET.

Prototype

HttpMethod GET

To view the source code for org.springframework.http HttpMethod GET.

Click Source Link

Usage

From source file:com.marklogic.samplestack.mock.MockApplicationSecurity.java

@Override
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();/*  w  ww  .jav a  2s . c om*/
    http.exceptionHandling().authenticationEntryPoint(entryPoint)
            .accessDeniedHandler(samplestackAccessDeniedHandler);

}

From source file:org.cloudfoundry.identity.statsd.integration.UaaMetricsEmitterIT.java

@Test
public void testStatsDClientEmitsMetricsCollectedFromUAA() throws InterruptedException, IOException {
    RestTemplate template = new RestTemplate();

    HttpHeaders headers = new HttpHeaders();
    headers.set(headers.ACCEPT, MediaType.TEXT_HTML_VALUE);
    ResponseEntity<String> loginResponse = template.exchange(UAA_BASE_URL + "/login", HttpMethod.GET,
            new HttpEntity<>(null, headers), String.class);

    if (loginResponse.getHeaders().containsKey("Set-Cookie")) {
        for (String cookie : loginResponse.getHeaders().get("Set-Cookie")) {
            headers.add("Cookie", cookie);
        }//from  w w  w  .  jav a 2 s  .c  om
    }
    String csrf = IntegrationTestUtils.extractCookieCsrf(loginResponse.getBody());

    LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>();
    body.add("username", TEST_USERNAME);
    body.add("password", TEST_PASSWORD);
    body.add(CookieBasedCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME, csrf);
    loginResponse = template.exchange(UAA_BASE_URL + "/login.do", HttpMethod.POST,
            new HttpEntity<>(body, headers), String.class);
    assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode());
    assertNotNull(getMessage("uaa.audit_service.user_authentication_count:1", 5000));
}

From source file:org.dthume.spring.http.client.httpcomponents.HttpComponentsClientRequestFactoryTest.java

@Test
public void testCreateRequest() throws Exception {
    final URI uri = new URI("http://www.google.com");
    final Header[] responseHeaders = new Header[] {};

    expect(client.execute(isA(HttpUriRequest.class))).andReturn(response);
    expect(response.getAllHeaders()).andReturn(responseHeaders);

    replayMocks();//from w  w  w .j a v a 2  s  . c o  m

    final ClientHttpRequest request = factory.createRequest(uri, HttpMethod.GET);

    final ClientHttpResponse actualResponse = request.execute();

    verify(client, response);
}

From source file:org.zalando.github.spring.IssuesTemplateTest.java

@Test
public void listAllIssues() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/issues?per_page=25")).andExpect(method(HttpMethod.GET))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(withSuccess(new ClassPathResource("listIssues.json", getClass()),
                    MediaType.APPLICATION_JSON));

    List<Issue> issueList = issuesTemplate.listAllIssues();

    Assertions.assertThat(issueList).isNotNull();
    Assertions.assertThat(issueList.size()).isEqualTo(1);
    Assertions.assertThat(issueList.get(0).getId()).isEqualTo(1);
}

From source file:org.zalando.github.spring.UsersTemplatePublicKeyTest.java

@Test
public void getPublicKeysForUser() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/users/klaus/keys")).andExpect(method(HttpMethod.GET))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(withSuccess(new ClassPathResource("listPublicKeysForUser.json", getClass()),
                    MediaType.APPLICATION_JSON));

    List<PubKey> pubKeyList = usersTemplate.listPublicKeys("klaus");

    Assertions.assertThat(pubKeyList).isNotNull();
    Assertions.assertThat(pubKeyList.size()).isEqualTo(1);
    Assertions.assertThat(pubKeyList.get(0).getKey()).isEqualTo("ssh-rsa AAA...");
}

From source file:org.zalando.github.spring.TeamsTemplateTest.java

@Test
public void getTeam() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/teams/1")).andExpect(method(HttpMethod.GET))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(//w w  w  . ja v a2  s.c om
                    withSuccess(new ClassPathResource("getTeam.json", getClass()), MediaType.APPLICATION_JSON));

    Team team = teamsTemplate.getTeam(1);

    Assertions.assertThat(team).isNotNull();
    Assertions.assertThat(team.getId()).isEqualTo(1);
    Assertions.assertThat(team.getName()).isEqualTo("Justice League");
}

From source file:org.openlmis.fulfillment.service.referencedata.BaseReferenceDataServiceTest.java

@Test
public void shouldFindById() throws Exception {
    // given//from   w  w  w .  j  av  a  2  s. com
    BaseReferenceDataService<T> service = prepareService();
    UUID id = UUID.randomUUID();
    T instance = generateInstance();
    ResponseEntity<T> response = mock(ResponseEntity.class);

    // when
    when(response.getBody()).thenReturn(instance);
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class),
            eq(service.getResultClass()))).thenReturn(response);

    T found = service.findOne(id);

    // then
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(),
            eq(service.getResultClass()));

    URI uri = uriCaptor.getValue();
    String url = service.getServiceUrl() + service.getUrl() + id;

    assertThat(uri.toString(), is(equalTo(url)));
    assertThat(found, is(instance));

    assertAuthHeader(entityCaptor.getValue());
    assertThat(entityCaptor.getValue().getBody(), is(nullValue()));
}

From source file:fi.helsinki.opintoni.server.LeikiServer.java

public void expectCourseRecommendationsErrorResult(String studentNumber) {
    server.expect(requestTo(courseRecommendationsUrl(studentNumber))).andExpect(method(HttpMethod.GET))
            .andRespond(withServerError());
}

From source file:uk.ac.ebi.eva.vcfdump.cellbasewsclient.CellbaseWSClient.java

public Set<String> getChromosomes() {
    try {//from w w w .  j a va2 s. co m
        // call cellbase chromosomes WS
        RestTemplate restTemplate = new RestTemplate();
        ParameterizedTypeReference<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>> responseType = new ParameterizedTypeReference<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>>() {
        };

        String cellbaseGetChromosomesUrl = cellbaseRestURL + "/" + cellbaseRestVersion + "/" + species
                + "/genomic/chromosome/all";
        logger.debug("Getting chromosomes list from {} ...", cellbaseGetChromosomesUrl);
        ResponseEntity<QueryResponse<QueryResult<CellbaseChromosomesWSOutput>>> wsOutput = restTemplate
                .exchange(cellbaseGetChromosomesUrl, HttpMethod.GET, null, responseType);

        // parse WS output and return all chromosome names
        QueryResponse<QueryResult<CellbaseChromosomesWSOutput>> response = wsOutput.getBody();
        QueryResult<CellbaseChromosomesWSOutput> result = response.getResponse().get(0);
        CellbaseChromosomesWSOutput results = result.getResult().get(0);
        return results.getAllChromosomeNames();
    } catch (Exception e) {
        logger.debug("Error retrieving list of chromosomes: {}", e.getMessage());
        throw new RuntimeException("Error retrieving list of chromosomes", e);
    }
}

From source file:sample.jetty.SampleJetty8ApplicationTests.java

@Test
public void testHomeBasicAuth() throws Exception {
    //      ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
    //            "http://localhost:" + this.port + "/static.html", String.class);

    ResponseEntity<String> entity = new TestRestTemplate().exchange(
            "http://localhost:" + this.port + "/static.html", HttpMethod.GET,
            new HttpEntity<String>(createHeaders("admin", "admin")), String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals("static", entity.getBody());
}