当前位置: 首页>>代码示例>>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;未经允许,请勿转载。