use of com.google.api.client.http.HttpTransport in project cogcomp-nlp by CogComp.
the class QueryMQL method getCursorAndResponse.
public JSONObject getCursorAndResponse(String mqlQuery, String cursor) throws IOException, ParseException {
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
JSONParser parser = new JSONParser();
GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread");
url.put("query", mqlQuery);
url.put("key", apikey);
url.put("cursor", cursor);
logger.debug("QUERY URL: " + url.toString());
HttpRequest request = requestFactory.buildGetRequest(url);
HttpResponse httpResponse = request.execute();
JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString());
return response;
}
use of com.google.api.client.http.HttpTransport in project cogcomp-nlp by CogComp.
the class QueryMQL method getResponse.
public JSONObject getResponse(String mqlQuery) throws IOException, ParseException {
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
JSONParser parser = new JSONParser();
GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread");
url.put("query", mqlQuery);
url.put("key", apikey);
logger.debug("Querying Freebase QUERY URL: " + url.toString());
HttpRequest request = requestFactory.buildGetRequest(url);
HttpResponse httpResponse;
try {
httpResponse = request.execute();
} catch (HttpResponseException e) {
e.printStackTrace();
int statusCode = e.getStatusCode();
logger.error("StatusCode " + statusCode);
logger.error("Query URL was " + url.toString());
logger.error("Query was " + mqlQuery);
if (// max limit reached for a day
statusCode == 403) {
System.exit(-1);
}
return null;
} catch (SocketTimeoutException e) {
e.printStackTrace();
return null;
}
JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString());
return response;
}
use of com.google.api.client.http.HttpTransport in project ddf by codice.
the class PaosInInterceptor method getHttpResponse.
@VisibleForTesting
HttpResponseWrapper getHttpResponse(String responseConsumerURL, String soapResponse, Message message) throws IOException {
// This used to use the ApacheHttpTransport which appeared to not work with 2 way TLS auth but
// this one does
HttpTransport httpTransport = new NetHttpTransport();
HttpContent httpContent = new ByteArrayContent(TEXT_XML, soapResponse.getBytes("UTF-8"));
HttpRequest httpRequest = httpTransport.createRequestFactory().buildPostRequest(new GenericUrl(responseConsumerURL), httpContent);
HttpUnsuccessfulResponseHandler httpUnsuccessfulResponseHandler = getHttpUnsuccessfulResponseHandler(message);
httpRequest.setUnsuccessfulResponseHandler(httpUnsuccessfulResponseHandler);
httpRequest.getHeaders().put(SOAP_ACTION, HTTP_WWW_OASIS_OPEN_ORG_COMMITTEES_SECURITY);
// has 20 second timeout by default
HttpResponse httpResponse = httpRequest.execute();
HttpResponseWrapper httpResponseWrapper = new HttpResponseWrapper();
httpResponseWrapper.statusCode = httpResponse.getStatusCode();
httpResponseWrapper.content = httpResponse.getContent();
httpResponseWrapper.headers = httpResponse.getHeaders().entrySet();
return httpResponseWrapper;
}
use of com.google.api.client.http.HttpTransport in project quickutil by quickutil.
the class GAUtil method buildData.
private static Data buildData(String clientID, InputStream p12InputStream, String applicationName) {
try {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(p12InputStream, null);
PrivateKey privateKey = (PrivateKey) keystore.getKey("privatekey", "notasecret".toCharArray());
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(clientID).setServiceAccountPrivateKey(privateKey).setServiceAccountScopes(Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY)).build();
return new Analytics.Builder(httpTransport, jsonFactory, credential).setApplicationName(applicationName).build().data();
} catch (Exception e) {
LOGGER.error(Symbol.BLANK, e);
return null;
}
}
use of com.google.api.client.http.HttpTransport in project googleads-java-lib by googleads.
the class DependencyBootstrapperImplTest method testGetNonSessionUtility.
/**
* Tests that the bootstrapper is able to retrieve an instance of a type that is not annotated
* with {@link SessionUtility}.
*/
@Test
public void testGetNonSessionUtility() {
HttpTransport httpTransport = bootstrapper.getInstanceOf(session, HttpTransport.class);
assertThat(httpTransport, Matchers.instanceOf(NetHttpTransport.class));
}
Aggregations