本文整理汇总了Java中com.google.appengine.api.urlfetch.URLFetchServiceFactory类的典型用法代码示例。如果您正苦于以下问题:Java URLFetchServiceFactory类的具体用法?Java URLFetchServiceFactory怎么用?Java URLFetchServiceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
URLFetchServiceFactory类属于com.google.appengine.api.urlfetch包,在下文中一共展示了URLFetchServiceFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: _doRequest
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例2: doGet
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例3: doGet
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try {
URLFetchServiceFactory.getURLFetchService()
.fetchAsync(new URL("http://www.example.com/asyncWithGet"))
.get();
} catch (Exception anythingMightGoWrongHere) {
// fall through
}
URLFetchServiceFactory.getURLFetchService()
.fetchAsync(new URL("http://www.example.com/asyncWithoutGet"));
MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
String randomKey = "" + Math.random();
String randomValue = "" + Math.random();
memcache.put(randomKey, randomValue);
resp.setContentType("text/plain");
resp.getOutputStream().println(randomKey);
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:19,代码来源:AppstatsMonitoredServlet.java
示例4: doGet
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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: testAsyncOps
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例6: getResponseDELETE
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例7: getResponseProxyPOST
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例8: makeHttpRequest
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例9: doGet
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例10: perform
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例11: checkURL
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例12: fetchNonExistentLocalAppThrowsException
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的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
示例13: testBasicOps
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
@Test
public void testBasicOps() throws Exception {
URLFetchService service = URLFetchServiceFactory.getURLFetchService();
URL adminConsole = findAvailableUrl(URLS);
HTTPResponse response = service.fetch(adminConsole);
printResponse(response);
URL jbossOrg = new URL("http://www.jboss.org");
if (available(jbossOrg)) {
response = service.fetch(jbossOrg);
printResponse(response);
}
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:15,代码来源:URLFetchTest.java
示例14: testPayload
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
@Test
public void testPayload() throws Exception {
URLFetchService service = URLFetchServiceFactory.getURLFetchService();
URL url = getFetchUrl();
HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
req.setHeader(new HTTPHeader("Content-Type", "application/octet-stream"));
req.setPayload("Tralala".getBytes(UTF_8));
HTTPResponse response = service.fetch(req);
String content = new String(response.getContent());
Assert.assertEquals("Hopsasa", content);
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:15,代码来源:URLFetchTest.java
示例15: testFollowRedirectsExternal
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
@Test
public void testFollowRedirectsExternal() throws Exception {
final URL redirectUrl = new URL("http://google.com/");
final String expectedDestinationURLPrefix = "http://www.google.";
FetchOptions options = FetchOptions.Builder.followRedirects();
HTTPRequest request = new HTTPRequest(redirectUrl, HTTPMethod.GET, options);
URLFetchService service = URLFetchServiceFactory.getURLFetchService();
HTTPResponse response = service.fetch(request);
String destinationUrl = response.getFinalUrl().toString();
assertTrue("Did not get redirected.", destinationUrl.startsWith(expectedDestinationURLPrefix));
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:14,代码来源:FetchOptionsBuilderTest.java
示例16: getResponsePUT
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
public static String getResponsePUT(String url, Map<String, String> params, String json, 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("PUT : " + urlStr);
HTTPRequest httpRequest = new HTTPRequest(new URL(urlStr), HTTPMethod.PUT, FetchOptions.Builder.withDeadline(deadline));
if (headers != null) {
for (String header : headers.keySet()) {
httpRequest.addHeader(new HTTPHeader(header, headers.get(header)));
}
}
httpRequest.setPayload(json.getBytes());
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,代码行数:31,代码来源:HttpClientGAE.java
示例17: getResponseGET
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
public static String getResponseGET(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);
HTTPRequest httpRequest = new HTTPRequest(new URL(urlStr), HTTPMethod.GET, FetchOptions.Builder.withDeadline(deadline));
if (headers != null) {
for (String name : headers.keySet()) {
httpRequest.addHeader(new HTTPHeader(name, headers.get(name)));
}
}
return processResponse(fetcher.fetch(httpRequest));
} 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,代码行数:28,代码来源:HttpClientGAE.java
示例18: provideUrlFetchService
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
@Provides
URLFetchService provideUrlFetchService() {
return URLFetchServiceFactory.getURLFetchService();
}
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:5,代码来源:WalkaroundServerModule.java
示例19: providerUrlFetchService
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
@Provides @Singleton
public URLFetchService providerUrlFetchService() {
return URLFetchServiceFactory.getURLFetchService();
}
开发者ID:jbufu,项目名称:openid4java,代码行数:5,代码来源:AppEngineGuiceModule.java
示例20: AppEngineTransport
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //导入依赖的package包/类
public AppEngineTransport() {
this(URLFetchServiceFactory.getURLFetchService());
}
开发者ID:stickfigure,项目名称:hattery,代码行数:4,代码来源:AppEngineTransport.java
注:本文中的com.google.appengine.api.urlfetch.URLFetchServiceFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论