请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java URLFetchService类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.appengine.api.urlfetch.URLFetchService的典型用法代码示例。如果您正苦于以下问题:Java URLFetchService类的具体用法?Java URLFetchService怎么用?Java URLFetchService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



URLFetchService类属于com.google.appengine.api.urlfetch包,在下文中一共展示了URLFetchService类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: AffinityMutationProcessor

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Inject
public AffinityMutationProcessor(
    Random random,
    RandomBase64Generator random64,
    URLFetchService fetchService,
    BackendService backends,
    LocalMutationProcessor localProcessor,
    MemcacheTable.Factory memcacheFactory,
    Secret secret,
    @StoreBackendInstanceCount int numStoreServers,
    @StoreBackendName String storeServer,
    MonitoringVars monitoring) {
  this.random = random;
  this.random64 = random64;
  this.fetchService = fetchService;
  this.backends = backends;
  this.localProcessor = localProcessor;
  this.objectServerMappings = memcacheFactory.create(MEMCACHE_TAG);
  this.secret = secret;
  this.numStoreServers = numStoreServers;
  this.storeServerName = storeServer;
  this.monitoring = monitoring;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:24,代码来源:AffinityMutationProcessor.java


示例2: _doRequest

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
/**
 * Hace la llamada a URLFetch de google
 * @throws IOException
 */
private void _doRequest() throws IOException {
	URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();

	FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();
	fetchOptions.doNotValidateCertificate();
	fetchOptions.setDeadline(_conxTimeOut);

	HTTPRequest request = new HTTPRequest(this.getURL(),_requestMethod,
										  fetchOptions);
	if (_requestOS != null) {
		byte[] bytes = _requestOS.toByteArray();
		if (bytes != null && bytes.length > 0) {
			request.setPayload(bytes);
		}
	}
	HTTPResponse httpResponse = urlFetchService.fetch(request);
	_responseCode = httpResponse.getResponseCode();
	_responseIS = new ByteArrayInputStream(httpResponse.getContent());
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:24,代码来源:HttpGoogleURLFetchConnectionWrapper.java


示例3: doGet

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
    ServletException {
  String trackingId = System.getenv("GA_TRACKING_ID");
  URIBuilder builder = new URIBuilder();
  builder.setScheme("http").setHost("www.google-analytics.com").setPath("/collect")
      .addParameter("v", "1") // API Version.
      .addParameter("tid", trackingId) // Tracking ID / Property ID.
      // Anonymous Client Identifier. Ideally, this should be a UUID that
      // is associated with particular user, device, or browser instance.
      .addParameter("cid", "555")
      .addParameter("t", "event") // Event hit type.
      .addParameter("ec", "example") // Event category.
      .addParameter("ea", "test action"); // Event action.
  URI uri = null;
  try {
    uri = builder.build();
  } catch (URISyntaxException e) {
    throw new ServletException("Problem building URI", e);
  }
  URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
  URL url = uri.toURL();
  fetcher.fetch(url);
  resp.getWriter().println("Event tracked.");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:26,代码来源:AnalyticsServlet.java


示例4: doGet

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws IOException, ServletException {
  String url = req.getParameter("url");
  String deadlineSecs = req.getParameter("deadline");
  URLFetchService service = URLFetchServiceFactory.getURLFetchService();
  HTTPRequest fetchReq = new HTTPRequest(new URL(url));
  if (deadlineSecs != null) {
    fetchReq.getFetchOptions().setDeadline(Double.valueOf(deadlineSecs));
  }
  HTTPResponse fetchRes = service.fetch(fetchReq);
  for (HTTPHeader header : fetchRes.getHeaders()) {
    res.addHeader(header.getName(), header.getValue());
  }
  if (fetchRes.getResponseCode() == 200) {
    res.getOutputStream().write(fetchRes.getContent());
  } else {
    res.sendError(fetchRes.getResponseCode(), "Error while fetching");
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:20,代码来源:CurlServlet.java


示例5: GaePendingResult

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
/**
 * @param request HTTP request to execute.
 * @param client The client used to execute the request.
 * @param responseClass Model class to unmarshal JSON body content.
 * @param fieldNamingPolicy FieldNamingPolicy for unmarshaling JSON.
 * @param errorTimeOut Number of milliseconds to re-send erroring requests.
 * @param maxRetries Number of times allowed to re-send erroring requests.
 */
public GaePendingResult(
    HTTPRequest request,
    URLFetchService client,
    Class<R> responseClass,
    FieldNamingPolicy fieldNamingPolicy,
    long errorTimeOut,
    Integer maxRetries,
    ExceptionsAllowedToRetry exceptionsAllowedToRetry) {
  this.request = request;
  this.client = client;
  this.responseClass = responseClass;
  this.fieldNamingPolicy = fieldNamingPolicy;
  this.errorTimeOut = errorTimeOut;
  this.maxRetries = maxRetries;
  this.exceptionsAllowedToRetry = exceptionsAllowedToRetry;

  this.call = client.fetchAsync(request);
}
 
开发者ID:googlemaps,项目名称:google-maps-services-java,代码行数:27,代码来源:GaePendingResult.java


示例6: testAsyncOps

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Test
public void testAsyncOps() throws Exception {
    URLFetchService service = URLFetchServiceFactory.getURLFetchService();

    URL adminConsole = findAvailableUrl(URLS);
    Future<HTTPResponse> response = service.fetchAsync(adminConsole);
    printResponse(response.get(5, TimeUnit.SECONDS));

    response = service.fetchAsync(new HTTPRequest(adminConsole));
    printResponse(response.get(5, TimeUnit.SECONDS));

    URL jbossOrg = new URL("http://www.jboss.org");
    if (available(jbossOrg)) {
        response = service.fetchAsync(jbossOrg);
        printResponse(response.get(30, TimeUnit.SECONDS));
    }

    sync(5000L); // wait a bit for async to finish
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:20,代码来源:URLFetchTest.java


示例7: AffinityMutationProcessor

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Inject
public AffinityMutationProcessor(Random random, URLFetchService fetchService,
    BackendService backends, LocalMutationProcessor localProcessor,
    MemcacheTable.Factory memcacheFactory, Secret secret,
    @StoreBackendInstanceCount int numStoreServers, @StoreBackendName String storeServer,
    MonitoringVars monitoring) {
  this.random = random;
  this.idGenerator = new IdGenerator(random);
  this.fetchService = fetchService;
  this.backends = backends;
  this.localProcessor = localProcessor;
  this.objectServerMappings = memcacheFactory.create(MEMCACHE_TAG);
  this.secret = secret;
  this.numStoreServers = numStoreServers;
  this.storeServerName = storeServer;
  this.monitoring = monitoring;
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:18,代码来源:AffinityMutationProcessor.java


示例8: getResponseDELETE

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
public static String getResponseDELETE(String url, Map<String, String> params, Map<String, String> headers) {
	int retry = 0;
	while (retry < 3) {
		long start = System.currentTimeMillis();
		try {
			URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
			String urlStr = ToolString.toUrl(url.trim(), params);
			logger.debug("DELETE : " + urlStr);
			HTTPRequest httpRequest = new HTTPRequest(new URL(urlStr), HTTPMethod.DELETE, FetchOptions.Builder.withDeadline(deadline));
			HTTPResponse response = fetcher.fetch(httpRequest);
			return processResponse(response);
		} catch (Throwable e) {
			retry++;
			if (e instanceof RuntimeException) {
				throw (RuntimeException) e;
			} else if (retry < 3) {
				logger.warn("retrying after " + (System.currentTimeMillis() - start) + " and " + retry + " retries\n" + e.getClass() + e.getMessage());
			} else {
				logger.error(e.getClass() + "\n" + ToolString.stack2string(e));
			}
		}
	}
	return null;
}
 
开发者ID:rafali,项目名称:flickr-uploader,代码行数:25,代码来源:HttpClientGAE.java


示例9: getResponseProxyPOST

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
public static String getResponseProxyPOST(URL url) throws MalformedURLException, UnsupportedEncodingException, IOException {
	URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
	String base64payload = "base64url=" + Base64UrlSafe.encodeServer(url.toString());
	String urlStr = url.toString();
	if (urlStr.contains("?")) {
		base64payload = "base64url=" + Base64UrlSafe.encodeServer(urlStr.substring(0, urlStr.indexOf("?")));
		base64payload += "&base64content=" + Base64UrlSafe.encodeServer(urlStr.substring(urlStr.indexOf("?") + 1));
	} else {
		base64payload = "base64url=" + Base64UrlSafe.encodeServer(urlStr);
	}
	HTTPRequest httpRequest = new HTTPRequest(new URL(HttpClientGAE.POSTPROXY_PHP), HTTPMethod.POST, FetchOptions.Builder.withDeadline(30d).doNotValidateCertificate());
	httpRequest.setPayload(base64payload.getBytes(UTF8));
	HTTPResponse response = fetcher.fetch(httpRequest);
	String processResponse = HttpClientGAE.processResponse(response);
	logger.info("proxying " + url + "\nprocessResponse:" + processResponse);
	return processResponse;
}
 
开发者ID:rafali,项目名称:flickr-uploader,代码行数:18,代码来源:HttpClientGAE.java


示例10: makeHttpRequest

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
/**
 * Creates an HTTPRequest with the information passed in.
 *
 * @param accessToken the access token necessary to authorize the request.
 * @param url the url to query.
 * @param payload the payload for the request.
 * @return the created HTTP request.
 * @throws IOException
 */
public static HTTPResponse makeHttpRequest(
    String accessToken, final String url, String payload, HTTPMethod method) throws IOException {

  // Create HTTPRequest and set headers
  HTTPRequest httpRequest = new HTTPRequest(new URL(url.toString()), method);
  httpRequest.addHeader(new HTTPHeader("Authorization", "OAuth " + accessToken));
  httpRequest.addHeader(new HTTPHeader("Host", "www.googleapis.com"));
  httpRequest.addHeader(new HTTPHeader("Content-Length", Integer.toString(payload.length())));
  httpRequest.addHeader(new HTTPHeader("Content-Type", "application/json"));
  httpRequest.addHeader(new HTTPHeader("User-Agent", "google-api-java-client/1.0"));
  httpRequest.setPayload(payload.getBytes());

  URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
  HTTPResponse httpResponse = fetcher.fetch(httpRequest);
  return httpResponse;
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-google-compute-engine-orchestrator,代码行数:26,代码来源:GceApiUtils.java


示例11: GadgetsHandler

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Inject
public GadgetsHandler(
    @Named("gadget serve path") String source,
    @Named("gadget server") String target,
    URLFetchService fetch) {
  delegate = new ProxyHandler(source, target, fetch);
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:8,代码来源:GadgetsHandler.java


示例12: FetchAttachmentsProcessor

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Inject
public FetchAttachmentsProcessor(SourceInstance.Factory sourceInstanceFactory,
    RawAttachmentService rawAttachmentService,
    URLFetchService urlfetch) {
  this.sourceInstanceFactory = sourceInstanceFactory;
  this.rawAttachmentService = rawAttachmentService;
  this.urlfetch = urlfetch;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:9,代码来源:FetchAttachmentsProcessor.java


示例13: ProxyHandler

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
/**
 * Creates a proxy servlet.
 *
 * @param sourceUriPrefix prefix of incoming requests to rewrite
 * @param targetUriPrefix value to replace the source prefix
 * @param fetch
 */
public ProxyHandler(String sourceUriPrefix, String targetUriPrefix, URLFetchService fetch) {
  // To prevent silly things like fowarding to ../
  Preconditions.checkArgument(!targetUriPrefix.contains(".."));
  this.sourceUriPrefix = sourceUriPrefix;
  this.targetUriPrefix = targetUriPrefix;
  this.fetch = fetch;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:15,代码来源:ProxyHandler.java


示例14: doGet

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException, ServletException {
  String trackingId = System.getenv("GA_TRACKING_ID");
  URIBuilder builder = new URIBuilder();
  builder
      .setScheme("http")
      .setHost("www.google-analytics.com")
      .setPath("/collect")
      .addParameter("v", "1") // API Version.
      .addParameter("tid", trackingId) // Tracking ID / Property ID.
      // Anonymous Client Identifier. Ideally, this should be a UUID that
      // is associated with particular user, device, or browser instance.
      .addParameter("cid", "555")
      .addParameter("t", "event") // Event hit type.
      .addParameter("ec", "example") // Event category.
      .addParameter("ea", "test action"); // Event action.
  URI uri = null;
  try {
    uri = builder.build();
  } catch (URISyntaxException e) {
    throw new ServletException("Problem building URI", e);
  }
  URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
  URL url = uri.toURL();
  fetcher.fetch(url);
  resp.getWriter().println("Event tracked.");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:29,代码来源:AnalyticsServlet.java


示例15: perform

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Override
public Page perform(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
    int id = Integer.parseInt(req.getParameter("id"));

    String remoteAddr = req.getRemoteAddr();
    Objectify ob = DefaultServlet.getObjectify();

    String secretParameter = getSetting(ob, "ReCaptchaPrivateKey", "");
    String recap = req.getParameter("g-recaptcha-response");
    URLFetchService us = URLFetchServiceFactory.getURLFetchService();
    URL url = new URL(
            "https://www.google.com/recaptcha/api/siteverify?secret=" +
            secretParameter + "&response=" + recap + "&remoteip=" + req.
            getRemoteAddr());
    HTTPResponse r = us.fetch(url);
    JSONObject json = null;
    try {
        json = new JSONObject(new String(r.getContent(), Charset.
                forName("UTF-8")));

        String s;
        if (json.getBoolean("success")) {
            Editor e = ob.query(Editor.class).filter("id =", id).get();
            s = "Email address: " + e.name;
        } else {
            s = "Answer is wrong";
        }

        return new MessagePage(s);
    } catch (JSONException ex) {
        throw new IOException(ex);
    }
}
 
开发者ID:tim-lebedkov,项目名称:npackd-gae-web,代码行数:35,代码来源:ReCaptchaAnswerAction.java


示例16: checkURL

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
/**
 * Checks an URL using the Google Safe Browsing Lookup API
 *
 * @param ofy Objectify
 * @param url this URL will be checked
 * @return GET_RESP_BODY = “phishing” | “malware” | "unwanted" |
 * “phishing,malware” | "phishing,unwanted" | "malware,unwanted" |
 * "phishing,malware,unwanted" | ""
 * @throws java.io.IOException there was a communication problem, the server
 * is unavailable, over quota or something different.
 */
public static String checkURL(Objectify ofy, String url) throws IOException {
    try {
        URL u = new URL(
                "https://sb-ssl.google.com/safebrowsing/api/lookup?client=npackdweb&key=" +
                getSetting(ofy, "PublicAPIKey", "") +
                "&appver=1&pver=3.1&url=" +
                NWUtils.encode(url));
        URLFetchService s = URLFetchServiceFactory.getURLFetchService();

        HTTPRequest ht = new HTTPRequest(u);
        HTTPResponse r = s.fetch(ht);
        int rc = r.getResponseCode();
        if (rc == 200) {
            return new String(r.getContent());
        } else if (rc == 204) {
            return "";
        } else if (rc == 400) {
            throw new IOException(new String(r.getContent()));
        } else {
            throw new IOException(
                    "Unknown exception from the Google Safe Browsing API");
        }
    } catch (MalformedURLException ex) {
        throw new IOException(ex);
    }
}
 
开发者ID:tim-lebedkov,项目名称:npackd-gae-web,代码行数:38,代码来源:NWUtils.java


示例17: setUrlFetchService

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
public GoogleAnalyticsTracking setUrlFetchService(URLFetchService urlFetchService)
    throws IOException {
  if (urlFetchService == null) {
    throw new IllegalArgumentException("Can't set urlFetchService to a null value.");
  }
  this.urlFetchService = urlFetchService;
  return this;
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-googleanalytics-java,代码行数:9,代码来源:GoogleAnalyticsTracking.java


示例18: setupUrlFetchService

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Before
public void setupUrlFetchService() throws IOException {
  mockUrlFetchService = mock(URLFetchService.class, RETURNS_MOCKS);
  mockHTTPResponse = mock(HTTPResponse.class);
  tracking = new GoogleAnalyticsTracking(TEST_GA_TRACKING_ID)
      .setUrlFetchService(mockUrlFetchService);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-googleanalytics-java,代码行数:8,代码来源:GoogleAnalyticsTrackingTest.java


示例19: testAuthIsRetried

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Test
public void testAuthIsRetried() throws IOException, InterruptedException, ExecutionException {
  URLFetchService urlFetchService = mock(URLFetchService.class, RETURNS_MOCKS);
  FailingFetchService failingFetchService = new FailingFetchService(urlFetchService, 1);
  failingFetchService.fetch(mock(HTTPRequest.class));

  failingFetchService = new FailingFetchService(urlFetchService, 1);
  failingFetchService.fetchAsync(mock(HTTPRequest.class)).get();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:10,代码来源:AppIdenityOauthTest.java


示例20: fetchNonExistentLocalAppThrowsException

import com.google.appengine.api.urlfetch.URLFetchService; //导入依赖的package包/类
@Test(expected = IOException.class)
public void fetchNonExistentLocalAppThrowsException() throws Exception {
    URL selfURL = new URL("BOGUS-" + appUrlBase + "/");
    FetchOptions fetchOptions = FetchOptions.Builder.withDefaults()
        .doNotFollowRedirects()
        .setDeadline(10.0);
    HTTPRequest httpRequest = new HTTPRequest(selfURL, HTTPMethod.GET, fetchOptions);
    URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
    HTTPResponse httpResponse = urlFetchService.fetch(httpRequest);
    fail("expected exception, got " + httpResponse.getResponseCode());
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:12,代码来源:URLFetchServiceTest.java



注:本文中的com.google.appengine.api.urlfetch.URLFetchService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NumberStringConverter类代码示例发布时间:2022-05-21
下一篇:
Java AmazonCloudFormation类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap