本文整理汇总了Java中com.google.api.client.http.HttpRequestFactory.buildGetRequest方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestFactory.buildGetRequest方法的具体用法?Java HttpRequestFactory.buildGetRequest怎么用?Java HttpRequestFactory.buildGetRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.http.HttpRequestFactory
的用法示例。
在下文中一共展示了HttpRequestFactory.buildGetRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUsers
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
public static List<Person> getUsers(HttpRequestFactory pHttpRequestFactory, AlfrescoConfig pConfig) {
mLog.debug("START getUsers()");
// FIXME (Alessio): Alfresco non supporta questo metodo!
PeopleUrl lPeopleUrl = new PeopleUrl(pConfig.getHost());
try {
HttpRequest lRequest = pHttpRequestFactory.buildGetRequest(lPeopleUrl);
@SuppressWarnings("unchecked")
MultipleEntry<Person> lResponse =
(MultipleEntry<Person>) lRequest.execute().parseAs(
(new TypeReference<MultipleEntry<Person>>() {}).getType());
mLog.debug("END getUsers()");
return lResponse.getEntries();
} catch (Exception e) {
// TODO (Alessio): gestione decente delle eccezioni
mLog.error("Unexpected failure", e);
throw new AlfrescoException(e, AlfrescoException.GENERIC_EXCEPTION);
}
}
示例2: getUser
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
public static Person getUser(String pStrUserId, HttpRequestFactory pHttpRequestFactory, AlfrescoConfig pConfig) {
mLog.debug("START getUser(String)");
PeopleUrl lPeopleUrl = new PeopleUrl(pConfig.getHost());
lPeopleUrl.setUserId(pStrUserId);
try {
HttpRequest lRequest = pHttpRequestFactory.buildGetRequest(lPeopleUrl);
@SuppressWarnings("unchecked")
SingleEntry<Person> lResponse =
(SingleEntry<Person>) lRequest.execute().parseAs(
(new TypeReference<SingleEntry<Person>>() {}).getType());
mLog.debug("END getUser(String)");
return lResponse.getEntry();
} catch (Exception e) {
mLog.error("Unexpected failure", e);
throw new AlfrescoException(e, AlfrescoException.GENERIC_EXCEPTION);
}
}
示例3: getGroups
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
public static GroupsList getGroups(HttpRequestFactory pHttpRequestFactory, AlfrescoConfig pConfig) {
mLog.debug("START getGroups()");
GroupsUrl lUrl = new GroupsUrl(pConfig.getHost());
try {
HttpRequest lRequest = pHttpRequestFactory.buildGetRequest(lUrl);
GroupsList lResponse = lRequest.execute().parseAs(GroupsList.class);
mLog.debug("END getGroups()");
return lResponse;
} catch (Exception e) {
// TODO (Alessio): gestione decente delle eccezioni
mLog.error("Unexpected failure", e);
throw new AlfrescoException(e, AlfrescoException.GENERIC_EXCEPTION);
}
}
示例4: getStationDetails
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
public Station getStationDetails(Station station) throws Exception {
try {
HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
HttpRequest request = httpRequestFactory
.buildGetRequest(new GenericUrl(PLACES_DETAILS_URL));
request.getUrl().put("key", API_KEY);
request.getUrl().put("reference", station.getReference());
request.getUrl().put("sensor", "false");
String place = request.execute().parseAsString();
return parser.stationFromJson(station, place);
} catch (HttpResponseException e) {
Log.e("ErrorDetails", e.getMessage());
throw e;
}
}
示例5: getPlaceDetails
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
/**
* Searching single place full details
* @param reference - reference id of place
* - which you will get in search api request
* */
public PlaceDetails getPlaceDetails(String reference) throws Exception {
try {
HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
HttpRequest request = httpRequestFactory
.buildGetRequest(new GenericUrl(PLACES_DETAILS_URL));
request.getUrl().put("key", API_KEY);
request.getUrl().put("reference", reference);
request.getUrl().put("sensor", "false");
PlaceDetails place = request.execute().parseAs(PlaceDetails.class);
return place;
} catch (HttpResponseException e) {
Log.e("Error in Perform Details", e.getMessage());
throw e;
}
}
示例6: listBucket
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
/**
* Fetches the listing of the given bucket.
*
* @param bucketName the name of the bucket to list.
*
* @return the raw XML containing the listing of the bucket.
* @throws IOException if there's an error communicating with Cloud Storage.
* @throws GeneralSecurityException for errors creating https connection.
*/
public static String listBucket(final String bucketName)
throws IOException, GeneralSecurityException {
//[START snippet]
// Build an account credential.
GoogleCredential credential = GoogleCredential.getApplicationDefault()
.createScoped(Collections.singleton(STORAGE_SCOPE));
// Set up and execute a Google Cloud Storage request.
String uri = "https://storage.googleapis.com/"
+ URLEncoder.encode(bucketName, "UTF-8");
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory(
credential);
GenericUrl url = new GenericUrl(uri);
HttpRequest request = requestFactory.buildGetRequest(url);
HttpResponse response = request.execute();
String content = response.parseAsString();
//[END snippet]
return content;
}
示例7: getPlaceDetails
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
public PlaceDetails getPlaceDetails(Place place) throws Exception {
try {
System.out.println("Perform Place Detail....");
HttpRequestFactory httpRequestFactory = createRequestFactory(transport);
HttpRequest request = httpRequestFactory.buildGetRequest(new GenericUrl(PLACES_DETAILS_URL));
request.getUrl().put("key", this.apiKey);
request.getUrl().put("reference", place.reference);
request.getUrl().put("sensor", "false");
if (PRINT_AS_STRING) {
System.out.println(request.execute().parseAsString());
} else {
PlaceDetails placeDetails = request.execute().parseAs(PlaceDetails.class);
System.out.println(placeDetails);
return placeDetails;
}
} catch (HttpResponseException e) {
System.err.println(e.getStatusMessage());
throw e;
}
return null;
}
示例8: getOrderWithTokensOnly
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
/**
* get a message using the token and secret token to authenticate in DEAL.
* To demonstrate successfull authentication a POST request is executed.
*
* @throws Exception on an exception occuring
*/
public static String getOrderWithTokensOnly(String urlToBeGet)
throws Exception
{
// utilize accessToken to access protected resource in DEAL
HttpRequestFactory factory = TRANSPORT
.createRequestFactory(getParameters());
GenericUrl url = new GenericUrl(urlToBeGet);
HttpRequest req = factory.buildGetRequest(url);
HttpResponse resp = req.execute();
req.getContent().writeTo(System.out);
String responseString = resp.parseAsString();
// Log
if (LOG.isInfoEnabled())
{
LOG.info("Response Status Code: " + resp.getStatusCode());
LOG.info("Response body:" + responseString);
}
return responseString;
}
示例9: performSearch
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
private static List<Place> performSearch( String kind, String type, double lat, double lng )
throws IOException
{
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory hrf = httpTransport.createRequestFactory();
String paramsf = "%s?location=%f,%f&rankby=distance&keyword=%s&type=%s&sensor=true&key=%s";
String params = String.format(paramsf, SearchData.BASE_URL, lat, lng, type, kind, AuthUtils.API_KEY);
GenericUrl url = new GenericUrl(params);
HttpRequest hreq = hrf.buildGetRequest(url);
HttpResponse hres = hreq.execute();
InputStream content = hres.getContent();
JsonParser p = new JacksonFactory().createJsonParser(content);
SearchData searchData = p.parse(SearchData.class, null);
return searchData.buildPlaces();
}
示例10: populateDetails
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
private static Place populateDetails( Place place )
throws IOException
{
// grab more restaurant details
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory hrf = httpTransport.createRequestFactory();
String paramsf = "%s?reference=%s&sensor=true&key=%s";
String params = String.format(paramsf, DetailsData.BASE_URL, place.getReference(), AuthUtils.API_KEY);
GenericUrl url = new GenericUrl(params);
HttpRequest hreq = hrf.buildGetRequest(url);
HttpResponse hres = hreq.execute();
// ByteArrayOutputStream os = new ByteArrayOutputStream();
// IOUtils.copy(hres.getContent(), os, false);
// System.out.println( os.toString() );
InputStream content2 = hres.getContent();
JsonParser p = new JacksonFactory().createJsonParser(content2);
DetailsData details = p.parse(DetailsData.class, null);
details.populatePlace( place );
return place;
}
示例11: getAccessToken
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
public static String getAccessToken(String email, KeyStore pks) throws Exception {
PrivateKey pk = getPrivateKey(pks);
if (pk != null && !email.equals("")) {
try {
GoogleCredential credential = new GoogleCredential.Builder().setTransport(GoogleSpreadsheet.HTTP_TRANSPORT)
.setJsonFactory(GoogleSpreadsheet.JSON_FACTORY).setServiceAccountScopes(GoogleSpreadsheet.SCOPES).setServiceAccountId(email)
.setServiceAccountPrivateKey(pk).build();
HttpRequestFactory requestFactory = GoogleSpreadsheet.HTTP_TRANSPORT.createRequestFactory(credential);
GenericUrl url = new GenericUrl(GoogleSpreadsheet.getSpreadsheetFeedURL().toString());
HttpRequest request = requestFactory.buildGetRequest(url);
request.execute();
return credential.getAccessToken();
} catch (Exception e) {
throw new Exception("Error fetching Access Token", e);
}
}
return null;
}
示例12: callApi
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
public HttpResponse callApi(String apimethod, String httpmethod) throws IOException {
HttpTransport http_transport = new ApacheHttpTransport();
OAuthParameters parameters = tokmgr.getOAuthParameters();
HttpRequestFactory factory = http_transport.createRequestFactory(parameters);
GenericUrl url = new GenericUrl(API_URL + apimethod);
HttpRequest req = factory.buildGetRequest(url);
req.setRequestMethod(httpmethod);
HttpResponse resp = req.execute();
return resp;
}
示例13: testInterceptorWithHeader
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
@Test
public void testInterceptorWithHeader() throws URISyntaxException, IOException, RequestSigningException {
HttpRequestFactory requestFactory = createSigningRequestFactory();
URI uri = URI.create("https://endpoint.net/billing-usage/v1/reportSources");
HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(uri));
request.getHeaders().put("Host", "ignored-hostname.com");
// Mimic what the library does to process the interceptor.
request.getInterceptor().intercept(request);
assertThat(request.getHeaders().containsKey("Host"), is(false));
assertThat(request.getHeaders().containsKey("host"), is(true));
assertThat((String) request.getHeaders().get("host"), equalTo("endpoint.net"));
assertThat(request.getUrl().getHost(), equalTo("endpoint.net"));
assertThat(request.getHeaders().getAuthorization(), not(isEmptyOrNullString()));
}
开发者ID:akamai,项目名称:AkamaiOPEN-edgegrid-java,代码行数:17,代码来源:GoogleHttpClientEdgeGridInterceptorTest.java
示例14: lowLevelGetRequest
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
/**
* An annoying workaround to the issue that some github APi calls
* are not exposed by egit library
*
* @param url
* @return
* @throws IOException
*/
private Map<String, Object> lowLevelGetRequest(String url) throws IOException {
NetHttpTransport transport = new NetHttpTransport.Builder().build();
HttpRequestFactory requestFactory = transport.createRequestFactory();
HttpRequest httpRequest = requestFactory.buildGetRequest(new GenericUrl(url));
HttpResponse execute = httpRequest.execute();
InputStream content = execute.getContent();
String s = IOUtils.toString(content, StandardCharsets.UTF_8);
Gson gson = new Gson();
Type stringStringMap = new TypeToken<Map<String, Object>>() {
}.getType();
return gson.fromJson(s, stringStringMap);
}
示例15: get
import com.google.api.client.http.HttpRequestFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T get(String path, Type responseType) throws RepoException, ValidationException {
HttpRequestFactory requestFactory = getHttpRequestFactory(getCredentialsIfPresent());
GenericUrl url = new GenericUrl(URI.create(API_URL + "/" + path));
try {
HttpRequest httpRequest = requestFactory.buildGetRequest(url);
HttpResponse response = httpRequest.execute();
return (T) response.parseAs(responseType);
} catch (IOException e) {
throw new RepoException("Error running GitHub API operation " + path, e);
}
}