use of com.github.scribejava.core.model.OAuthRequest in project sonarqube by SonarSource.
the class OAuthRestClient method executeRequest.
public static Response executeRequest(String requestUrl, OAuth20Service scribe, OAuth2AccessToken accessToken) throws IOException {
OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl);
scribe.signRequest(accessToken, request);
try {
Response response = scribe.execute(request);
if (!response.isSuccessful()) {
throw unexpectedResponseCode(requestUrl, response);
}
return response;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
} catch (ExecutionException e) {
throw new IllegalStateException(e);
}
}
use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.
the class OkHttpHttpClientTest method shouldReadResponseStream.
@Test
public void shouldReadResponseStream() throws Exception {
final String expectedResponseBody = "response body";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream()));
final RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET", recordedRequest.getMethod());
server.shutdown();
}
use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.
the class OkHttpHttpClientTest method shouldSendPostRequest.
@Test
public void shouldSendPostRequest() throws Exception {
final String expectedResponseBody = "response body";
final String expectedRequestBody = "request body";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
// request with body
OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString());
request.setPayload(expectedRequestBody);
Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, response.getBody());
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8());
// request with empty body
request = new OAuthRequest(Verb.POST, baseUrl.toString());
response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, response.getBody());
recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertEquals("", recordedRequest.getBody().readUtf8());
server.shutdown();
}
use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.
the class OkHttpHttpClientTest method shouldSendGetRequest.
@Test
public void shouldSendGetRequest() throws Exception {
final String expectedResponseBody = "response body";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, response.getBody());
final RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET", recordedRequest.getMethod());
server.shutdown();
}
use of com.github.scribejava.core.model.OAuthRequest in project scribejava by scribejava.
the class ObjectMother method createSampleOAuthRequestPort80v2.
public static OAuthRequest createSampleOAuthRequestPort80v2() {
final OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com:80/test");
request.addOAuthParameter(OAuthConstants.TIMESTAMP, "123456");
request.addOAuthParameter(OAuthConstants.CONSUMER_KEY, "AS#$^*@&");
request.addOAuthParameter(OAuthConstants.CALLBACK, "http://example/callback");
request.addOAuthParameter(OAuthConstants.SIGNATURE, "OAuth-Signature");
return request;
}
Aggregations