use of com.google.api.client.http.GenericUrl in project OpenRefine by OpenRefine.
the class DeAuthorizeCommand method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
String sessionToken = TokenCookie.getToken(request);
if (sessionToken != null) {
// No method to do this in Google's client lib, so roll our own
HttpRequestFactory factory = HTTP_TRANSPORT.createRequestFactory();
GenericUrl url = new GenericUrl("https://accounts.google.com/o/oauth2/revoke?token=" + sessionToken);
HttpRequest rqst = factory.buildGetRequest(url);
HttpResponse resp = rqst.execute();
if (resp.getStatusCode() != 200) {
respond(response, String.valueOf(resp.getStatusCode()), resp.getStatusMessage());
}
TokenCookie.deleteToken(request, response);
}
respond(response, "200 OK", "");
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.api.client.http.GenericUrl in project pinpoint by naver.
the class HttpRequestIT method executeAsync.
@Test
public void executeAsync() throws Exception {
HttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport();
HttpRequestFactory requestFactory = NET_HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) {
}
});
GenericUrl url = new GenericUrl("http://google.com");
HttpRequest request = null;
HttpResponse response = null;
try {
request = requestFactory.buildGetRequest(url);
response = request.executeAsync().get();
response.disconnect();
} catch (IOException ignored) {
} finally {
if (response != null) {
response.disconnect();
}
}
Method executeAsyncMethod = HttpRequest.class.getDeclaredMethod("executeAsync", Executor.class);
Method callMethod = Callable.class.getDeclaredMethod("call");
Method executeMethod = HttpRequest.class.getDeclaredMethod("execute");
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
// async
verifier.verifyTrace(Expectations.async(Expectations.event("GOOGLE_HTTP_CLIENT_INTERNAL", executeAsyncMethod), Expectations.event("ASYNC", "Asynchronous Invocation")));
}
use of com.google.api.client.http.GenericUrl in project pinpoint by naver.
the class HttpRequestIT method execute.
@Test
public void execute() throws Exception {
HttpTransport NET_HTTP_TRANSPORT = new NetHttpTransport();
HttpRequestFactory requestFactory = NET_HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) {
}
});
GenericUrl url = new GenericUrl("http://google.com");
HttpRequest request = null;
HttpResponse response = null;
try {
request = requestFactory.buildGetRequest(url);
response = request.execute();
response.disconnect();
} catch (IOException ignored) {
} finally {
if (response != null) {
response.disconnect();
}
}
Method executeMethod = HttpRequest.class.getDeclaredMethod("execute");
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(Expectations.event("GOOGLE_HTTP_CLIENT_INTERNAL", executeMethod));
}
use of com.google.api.client.http.GenericUrl in project api-samples by youtube.
the class RetrieveReports method downloadReport.
/**
* Download the report specified by the URL. (media.download)
*
* @param reportUrl The URL of the report to be downloaded.
* @throws IOException
*/
private static boolean downloadReport(String reportUrl) throws IOException {
// Call the YouTube Reporting API's media.download method to download a report.
Download request = youtubeReporting.media().download("");
FileOutputStream fop = new FileOutputStream(new File("report"));
request.getMediaHttpDownloader().download(new GenericUrl(reportUrl), fop);
return true;
}
use of com.google.api.client.http.GenericUrl in project google-cloud-java by GoogleCloudPlatform.
the class HttpStorageRpc method write.
@Override
public void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length, boolean last) {
try {
if (length == 0 && !last) {
return;
}
GenericUrl url = new GenericUrl(uploadId);
HttpRequest httpRequest = storage.getRequestFactory().buildPutRequest(url, new ByteArrayContent(null, toWrite, toWriteOffset, length));
long limit = destOffset + length;
StringBuilder range = new StringBuilder("bytes ");
if (length == 0) {
range.append('*');
} else {
range.append(destOffset).append('-').append(limit - 1);
}
range.append('/');
if (last) {
range.append(limit);
} else {
range.append('*');
}
httpRequest.getHeaders().setContentRange(range.toString());
int code;
String message;
IOException exception = null;
try {
HttpResponse response = httpRequest.execute();
code = response.getStatusCode();
message = response.getStatusMessage();
} catch (HttpResponseException ex) {
exception = ex;
code = ex.getStatusCode();
message = ex.getStatusMessage();
}
if (!last && code != 308 || last && !(code == 200 || code == 201)) {
if (exception != null) {
throw exception;
}
GoogleJsonError error = new GoogleJsonError();
error.setCode(code);
error.setMessage(message);
throw translate(error);
}
} catch (IOException ex) {
throw translate(ex);
}
}
Aggregations