当前位置: 首页>>代码示例>>Java>>正文


Java URLFetchService类代码示例

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


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


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