當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpRequestFactory類代碼示例

本文整理匯總了Java中com.google.api.client.http.HttpRequestFactory的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequestFactory類的具體用法?Java HttpRequestFactory怎麽用?Java HttpRequestFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpRequestFactory類屬於com.google.api.client.http包,在下文中一共展示了HttpRequestFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: PostOrderWithTokensOnly

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
/**
 * Post an order using the token and secret token to authenticate in DEAL.
 * To demonstrate successful authentication a POST request is executed.
 * 
 * @param messageToBePosted the JSON string representing the order
 * @return the result of the post action
 * 
 * @throws Exception on an exception occurring
 */
public static String PostOrderWithTokensOnly(String messageToBePosted)
		throws Exception
{
	// utilize accessToken to access protected resource in DEAL
	HttpRequestFactory factory = TRANSPORT
			.createRequestFactory(getParameters());
	GenericUrl url = new GenericUrl(PROTECTED_ORDERS_URL);
	InputStream stream = new ByteArrayInputStream(
			messageToBePosted.getBytes());
	InputStreamContent content = new InputStreamContent(JSON_IDENTIFIER,
			stream);
	HttpRequest req = factory.buildPostRequest(url, content);

	HttpResponse resp = req.execute();
	String response = resp.parseAsString();

	// log the response
	if (resp.getStatusCode() != 200 && LOG.isInfoEnabled())
	{
		LOG.info("Response Status Code: " + resp.getStatusCode());
		LOG.info("Response body:" + response);
	}

	return response;
}
 
開發者ID:krevelen,項目名稱:coala,代碼行數:35,代碼來源:DealOAuth1Util.java

示例2: build

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
public OAuthAccessToken build() throws IOException {
  Url = new GenericUrl(config.getAccessTokenUrl());

  transport = new ApacheHttpTransport();

  HttpRequestFactory requestFactory = transport.createRequestFactory();
  request = requestFactory.buildRequest(HttpMethods.GET, Url, null);

  HttpHeaders headers = new HttpHeaders();
  headers.setUserAgent(config.getUserAgent());
  headers.setAccept(config.getAccept());

  request.setHeaders(headers);
  createRefreshParameters().intercept(request);

  return this;
}
 
開發者ID:XeroAPI,項目名稱:Xero-Java,代碼行數:18,代碼來源:OAuthAccessToken.java

示例3: 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);
	}
}
 
開發者ID:MakeITBologna,項目名稱:zefiro,代碼行數:22,代碼來源:AlfrescoHelper.java

示例4: 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);
	}
}
 
開發者ID:MakeITBologna,項目名稱:zefiro,代碼行數:21,代碼來源:AlfrescoHelper.java

示例5: 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);
	}
}
 
開發者ID:MakeITBologna,項目名稱:zefiro,代碼行數:17,代碼來源:AlfrescoHelper.java

示例6: executeStmt

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
public String executeStmt(String method, String urlString, String statement, List<NameValuePair> qparams)
		throws IOException {
	Check.notNull(statement);

	GenericUrl url = setParams(new GenericUrl(urlString), qparams);
	UrlEncodedContent urlEntity = setMediaType(getUrlEncodedSql(statement));

	HttpRequestFactory rf = httpTransport.createRequestFactory(credential);

	HttpResponse response = rf.buildRequest(method, url, urlEntity).execute();
	String result = readGoogleResponse(response);

	if (response.getStatusCode() != HttpServletResponse.SC_OK)
		throw new RuntimeException(result.toString() + statement);

	return result;
}
 
開發者ID:curiosag,項目名稱:ftc,代碼行數:18,代碼來源:RestApi.java

示例7: post

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> T post(String path, Object request, Type responseType)
    throws RepoException, ValidationException {
  HttpRequestFactory requestFactory = getHttpRequestFactory(getCredentials());

  GenericUrl url = new GenericUrl(URI.create(API_URL + "/" + path));
  try {
    HttpRequest httpRequest = requestFactory.buildPostRequest(url,
        new JsonHttpContent(JSON_FACTORY, request));
    HttpResponse response = httpRequest.execute();
    return (T) response.parseAs(responseType);
  } catch (IOException e) {
    throw new RepoException("Error running GitHub API operation " + path, e);
  }
}
 
開發者ID:google,項目名稱:copybara,代碼行數:17,代碼來源:GitHubApiTransportImpl.java

示例8: getHttpRequestFactory

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
/**
 * TODO(malcon): Consolidate GitHub and this one in one class
 */
private HttpRequestFactory getHttpRequestFactory(@Nullable UserPassword userPassword)
    throws RepoException, ValidationException {
  return httpTransport.createRequestFactory(
      request -> {
        request.setConnectTimeout((int) Duration.ofMinutes(1).toMillis());
        request.setReadTimeout((int) Duration.ofMinutes(1).toMillis());
        HttpHeaders httpHeaders = new HttpHeaders();
        if (userPassword != null) {
          httpHeaders.setBasicAuthentication(userPassword.getUsername(),
                                             userPassword.getPassword_BeCareful());
        }
        request.setHeaders(httpHeaders);
        request.setParser(new JsonObjectParser(JSON_FACTORY));
      });
}
 
開發者ID:google,項目名稱:copybara,代碼行數:19,代碼來源:GerritApiTransportImpl.java

示例9: 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;
	}
}
 
開發者ID:Gaso-UFS,項目名稱:gaso,代碼行數:20,代碼來源:GooglePlaces.java

示例10: 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;
    }
}
 
開發者ID:zubiix,項目名稱:nearby-places,代碼行數:25,代碼來源:GooglePlaces.java

示例11: setUp

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
@Before
public void setUp() throws ConfigException {
	config = new ConfigBuilder().setRegion("sandbox").setApiKey("someApiKey").build();
	handler = new Handler(config) {
		@Override
		public <T extends Response> T execute(HttpRequestFactory requestFactory, String method, PostmenUrl endpoint, Object body, Class<T> type) throws IOException {
			T c = null;
			try {
				c = type.newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return c;
		}
	};
}
 
開發者ID:postmen,項目名稱:postmen-sdk-java,代碼行數:21,代碼來源:HandlerTest.java

示例12: testCallAsString

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
@Test
public void testCallAsString() {
	IOException ex = null;
	handler = new Handler(config) {
		@Override
		public <T extends Response> T execute(HttpRequestFactory requestFactory, String method, PostmenUrl endpoint, Object body, Class<T> type) throws IOException {
			MapResponse response = new MapResponse();
			response.setData(new HashMap<Object, Object>());
			return (T) response;
		}
	};
	try {
		String response = handler.callAndParseAsString(null, null, null);
		assertNotNull(response);
	} catch (IOException e) {
		ex = e;
	}
	assertNull(ex);
}
 
開發者ID:postmen,項目名稱:postmen-sdk-java,代碼行數:20,代碼來源:HandlerTest.java

示例13: addAllToCacheQueue

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
@Scheduled(fixedRate = MONTHLY, initialDelay = MONTHLY)
@RequestMapping(value = "/cache", method = RequestMethod.DELETE)
@ResponseBody
public String addAllToCacheQueue() throws IOException, FitbitClientException {
    HttpRequestFactory requestFactory = getHttpRequestFactory();

    FitbitUserClient userRepo = new FitbitUserClient(requestFactory);

    LocalDate firstDate = userRepo.getAuthorisedUser().getMemberSince();
    LocalDate today = LocalDate.now();
    for (LocalDate date : new LocalDateRange(firstDate, today)) {
        if (!cacheQueue.contains(date)) {
            cacheQueue.add(date);
        }
    }
    return "cache cleared";
}
 
開發者ID:TickleThePanda,項目名稱:health-vis,代碼行數:18,代碼來源:FitbitCacheController.java

示例14: updateCacheQueue

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
@Scheduled(fixedRate = HOURLY, initialDelay = IMMEDIATE)
public void updateCacheQueue() throws IOException, FitbitClientException {

    HttpRequestFactory requestFactory = getHttpRequestFactory();

    FitbitUserClient userRepo = new FitbitUserClient(requestFactory);

    LocalDate firstDate = userRepo.getAuthorisedUser().getMemberSince();
    LocalDate today = LocalDate.now();

    for (LocalDate date : new LocalDateRange(firstDate, today)) {
        if (!activityService.hasCompleteEntry(date)
                || date.isAfter(today.minusDays(FORCE_UPDATE_THRESHOLD_DAYS))) {
            if (!cacheQueue.contains(date)) {
                cacheQueue.add(date);
            }
        }
    }
}
 
開發者ID:TickleThePanda,項目名稱:health-vis,代碼行數:20,代碼來源:FitbitCacheController.java

示例15: cacheFitbitData

import com.google.api.client.http.HttpRequestFactory; //導入依賴的package包/類
@Scheduled(cron = "0 0 * * * *")
@Async
public void cacheFitbitData() throws IOException, FitbitClientException {

    logger.info("refreshing cache");

    HttpRequestFactory requestFactory = getHttpRequestFactory();

    FitbitIntradayActivityClient intradayActivityDao = new FitbitIntradayActivityClient(requestFactory);

    DayActivityFitbitToEntity transformer = new DayActivityFitbitToEntity();

    ListIterator<LocalDate> listIterator = cacheQueue.listIterator();
    while (listIterator.hasNext()) {
        LocalDate date = listIterator.next();
        logger.info("getting activity from fitbit for " + date.toString());
        FitbitIntradayActivity activity = intradayActivityDao.getDayActivity(date);
        logger.info("replacing activity for " + date.toString());
        activityService.replaceActivities(transformer.transform(activity));

        listIterator.remove();
    }

}
 
開發者ID:TickleThePanda,項目名稱:health-vis,代碼行數:25,代碼來源:FitbitCacheController.java


注:本文中的com.google.api.client.http.HttpRequestFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。