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);
}
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;
}
}
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);
}
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"));
}
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;
}
Aggregations