Search in sources :

Example 26 with ClientHttpRequest

use of org.springframework.http.client.ClientHttpRequest in project spring-security-oauth by spring-projects.

the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetErrorFromForm.

@Test
public void testGetErrorFromForm() throws Exception {
    final HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    requestFactory = new ClientHttpRequestFactory() {

        public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
            return new StubClientHttpRequest(HttpStatus.BAD_REQUEST, responseHeaders, "error=invalid_client&error_description=FOO");
        }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAuthorizationCode("foo");
    request.setPreservedState(new Object());
    resource.setAccessTokenUri("http://localhost/oauth/token");
    expected.expect(OAuth2AccessDeniedException.class);
    expected.expect(hasCause(instanceOf(InvalidClientException.class)));
    setUpRestTemplate();
    provider.obtainAccessToken(resource, request);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) IOException(java.io.IOException) DefaultAccessTokenRequest(org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest) AccessTokenRequest(org.springframework.security.oauth2.client.token.AccessTokenRequest) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) HttpMethod(org.springframework.http.HttpMethod) DefaultAccessTokenRequest(org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest) Test(org.junit.Test)

Example 27 with ClientHttpRequest

use of org.springframework.http.client.ClientHttpRequest in project spring-boot by spring-projects.

the class DelayedLiveReloadTrigger method isUp.

private boolean isUp() {
    try {
        ClientHttpRequest request = createRequest();
        ClientHttpResponse response = request.execute();
        return response.getStatusCode() == HttpStatus.OK;
    } catch (Exception ex) {
        return false;
    }
}
Also used : ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 28 with ClientHttpRequest

use of org.springframework.http.client.ClientHttpRequest in project spring-boot by spring-projects.

the class RootUriRequestExpectationManagerTests method validateRequestWhenRequestUriAssertionIsThrownShouldReplaceUriInMessage.

@Test
public void validateRequestWhenRequestUriAssertionIsThrownShouldReplaceUriInMessage() throws Exception {
    ClientHttpRequest request = mock(ClientHttpRequest.class);
    given(request.getURI()).willReturn(new URI(this.uri + "/hello"));
    given(this.delegate.validateRequest((ClientHttpRequest) any())).willThrow(new AssertionError("Request URI expected:</hello> was:<http://example.com/bad>"));
    this.thrown.expect(AssertionError.class);
    this.thrown.expectMessage("Request URI expected:<http://example.com/hello>");
    this.manager.validateRequest(request);
}
Also used : ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) Test(org.junit.Test)

Example 29 with ClientHttpRequest

use of org.springframework.http.client.ClientHttpRequest in project spring-boot by spring-projects.

the class RootUriRequestExpectationManagerTests method validateRequestWhenUriStartsWithRootUriShouldReplaceUri.

@Test
public void validateRequestWhenUriStartsWithRootUriShouldReplaceUri() throws Exception {
    ClientHttpRequest request = mock(ClientHttpRequest.class);
    given(request.getURI()).willReturn(new URI(this.uri + "/hello"));
    this.manager.validateRequest(request);
    verify(this.delegate).validateRequest(this.requestCaptor.capture());
    HttpRequestWrapper actual = (HttpRequestWrapper) this.requestCaptor.getValue();
    assertThat(actual.getRequest()).isSameAs(request);
    assertThat(actual.getURI()).isEqualTo(new URI("/hello"));
}
Also used : HttpRequestWrapper(org.springframework.http.client.support.HttpRequestWrapper) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) Test(org.junit.Test)

Example 30 with ClientHttpRequest

use of org.springframework.http.client.ClientHttpRequest in project spring-boot by spring-projects.

the class AbstractServletWebServerFactoryTests method getClientResponse.

protected ClientHttpResponse getClientResponse(String url, HttpMethod method, HttpComponentsClientHttpRequestFactory requestFactory, String... headers) throws IOException, URISyntaxException {
    ClientHttpRequest request = requestFactory.createRequest(new URI(url), method);
    request.getHeaders().add("Cookie", "JSESSIONID=" + "123");
    for (String header : headers) {
        String[] parts = header.split(":");
        request.getHeaders().add(parts[0], parts[1]);
    }
    ClientHttpResponse response = request.execute();
    return response;
}
Also used : ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse)

Aggregations

ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)36 URI (java.net.URI)19 Test (org.junit.Test)13 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)13 IOException (java.io.IOException)11 HttpMethod (org.springframework.http.HttpMethod)9 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)9 HttpHeaders (org.springframework.http.HttpHeaders)6 MockClientHttpRequest (org.springframework.mock.http.client.MockClientHttpRequest)6 RequestMatcher (org.springframework.test.web.client.RequestMatcher)6 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)4 AccessTokenRequest (org.springframework.security.oauth2.client.token.AccessTokenRequest)4 DefaultAccessTokenRequest (org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 MediaType (org.springframework.http.MediaType)2 ClientHttpRequestInterceptor (org.springframework.http.client.ClientHttpRequestInterceptor)2 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)2