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


Java HTTPResponse.getContent方法代码示例

本文整理汇总了Java中com.google.appengine.api.urlfetch.HTTPResponse.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java HTTPResponse.getContent方法的具体用法?Java HTTPResponse.getContent怎么用?Java HTTPResponse.getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.appengine.api.urlfetch.HTTPResponse的用法示例。


在下文中一共展示了HTTPResponse.getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: _doRequest

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的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: createInstance

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
/**
 * Creates a new instance.
 *
 * @param instanceName the name of the instance to create.
 * @param bootDiskName the name of the disk to create the instance with.
 * @param projectApiKey the project API key.
 * @param accessToken the access token.
 * @param configProperties the configuration properties.
 * @throws MalformedURLException
 * @throws IOException
 * @throws OrchestratorException if the REST API call failed to create instance.
 */
private void createInstance(String instanceName, String bootDiskName, String projectApiKey,
    String accessToken, Map<String, String> configProperties)
    throws MalformedURLException, IOException, OrchestratorException {
  String url = GceApiUtils.composeInstanceApiUrl(
      ConfigProperties.urlPrefixWithProjectAndZone, projectApiKey);
  String payload = createPayload_instance(instanceName, bootDiskName, configProperties);
  logger.info(
      "Calling " + url + " to create instance " + instanceName + "with payload " + payload);
  HTTPResponse httpResponse =
      GceApiUtils.makeHttpRequest(accessToken, url, payload, HTTPMethod.POST);
  int responseCode = httpResponse.getResponseCode();
  if (!(responseCode == 200 || responseCode == 204)) {
    throw new OrchestratorException("Failed to create GCE instance. " + instanceName
        + ". Response code " + responseCode + " Reason: "
        + new String(httpResponse.getContent()));
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-google-compute-engine-orchestrator,代码行数:30,代码来源:GceInstanceCreator.java

示例3: checkDiskOrInstance

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
/**
 * Checks whether the disk or instance is available.
 *
 * @param accessToken the access token.
 * @param url the URL to check whether the disk/instance has been created.
 * @return true if the disk/instance is available, false otherwise.
 * @throws MalformedURLException
 * @throws IOException
 */
private boolean checkDiskOrInstance(String accessToken, String url)
    throws MalformedURLException, IOException {
  HTTPResponse httpResponse = GceApiUtils.makeHttpRequest(accessToken, url, "", HTTPMethod.GET);
  int responseCode = httpResponse.getResponseCode();
  if (!(responseCode == 200 || responseCode == 204)) {
    logger.fine("Disk/instance not ready. Response code " + responseCode + " Reason: "
        + new String(httpResponse.getContent()));
    return false;
  }
  // Check if the disk/instance is in status "READY".
  String contentStr = new String(httpResponse.getContent());
  JsonParser parser = new JsonParser();
  JsonObject o = (JsonObject) parser.parse(contentStr);
  String status = o.get("status").getAsString();
  if (!status.equals("READY") && !status.equals("RUNNING")) {
    return false;
  }
  return true;
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-google-compute-engine-orchestrator,代码行数:29,代码来源:GceInstanceCreator.java

示例4: deleteInstance

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
/**
 * Deletes an instance.
 *
 * @param name the name of the instance to delete.
 * @throws OrchestratorException if delete failed.
 */
private void deleteInstance(String name, String accessToken, String url)
    throws OrchestratorException {
  logger.info("Shutting down instance: " + name);
  HTTPResponse httpResponse;
  try {
    httpResponse = GceApiUtils.makeHttpRequest(accessToken, url, "", HTTPMethod.DELETE);
    int responseCode = httpResponse.getResponseCode();
    if (!(responseCode == 200 || responseCode == 204)) {
      throw new OrchestratorException("Delete Instance failed. Response code " + responseCode
          + " Reason: " + new String(httpResponse.getContent()));
    }
  } catch (IOException e) {
    throw new OrchestratorException(e);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-google-compute-engine-orchestrator,代码行数:22,代码来源:GceInstanceDestroyer.java

示例5: getMethod

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
public String getMethod(URL url) throws IOException {
	log.finer("Calling GET on " + url);
	HTTPRequest req = new HTTPRequest(url);
	if(cookie!=null) 
		req.setHeader(cookie);
	HTTPResponse resp = getURLFetchService().fetch(req);
	updateCookies(resp);
	int responseCode = -1;
	if (resp != null) {
		responseCode = resp.getResponseCode();
		if (responseCode == 200) {
			String response = new String(resp.getContent(), RESPONSE_CONTENT_ENCODING);
			log.finer("GET returns: " + response);
			return response;
		}
	}
	throw new IOException("Problem calling GET on: " + url.toString() + " response: " + responseCode);
}
 
开发者ID:marcusschiesser,项目名称:openbahn-api,代码行数:19,代码来源:HTTPSession.java

示例6: postMethod

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
public String postMethod(URL url, String params) throws IOException {
	log.finer("Calling POST on " + url + " with params: " + params);
	HTTPRequest req = new HTTPRequest(url, POST, followRedirects()); //.withDeadline(10.0));
	//req.setHeader(new HTTPHeader("x-header-one", "some header"));
	if(cookie!=null)
		req.setHeader(cookie);
	if(sessionParam!=null)
		params = sessionParam + "&" + params;
	req.setPayload(params.getBytes(RESPONSE_CONTENT_ENCODING));

	HTTPResponse resp = getURLFetchService().fetch(req);
	updateCookies(resp);
	int responseCode = -1;
	if (resp != null) {
		responseCode = resp.getResponseCode();
		if (responseCode == 200) {
			// List<HTTPHeader> headers = resp.getHeaders();
			String response = new String(resp.getContent(), RESPONSE_CONTENT_ENCODING);
			log.finer("POST returns: " + response);
			return response;
		}
	}
	throw new IOException("Problem calling GET on: " + url.toString() + " response: " + responseCode);
}
 
开发者ID:marcusschiesser,项目名称:openbahn-api,代码行数:25,代码来源:HTTPSession.java

示例7: describeResponse

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private String describeResponse(HTTPResponse resp, boolean includeBody) {
  StringBuilder b = new StringBuilder(resp.getResponseCode()
      + " with " + resp.getContent().length + " bytes of content");
  for (HTTPHeader h : resp.getHeaders()) {
    b.append("\n" + h.getName() + ": " + h.getValue());
  }
  if (includeBody) {
    b.append("\n" + new String(resp.getContent(), Charsets.UTF_8));
  } else {
    b.append("\n<content elided>");
  }
  return "" + b;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:14,代码来源:OAuthedFetchService.java

示例8: getUtf8ResponseBodyUnchecked

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
/** Returns the body of {@code resp}, assuming that its encoding is UTF-8. */
private static String getUtf8ResponseBodyUnchecked(HTTPResponse resp) {
  byte[] rawResponseBody = resp.getContent();
  if (rawResponseBody == null) {
    return "";
  } else {
    return new String(rawResponseBody, Charsets.UTF_8);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:10,代码来源:OAuthedFetchService.java

示例9: describeResponse

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private String describeResponse(HTTPResponse resp) {
  StringBuilder b = new StringBuilder(resp.getResponseCode()
      + " with " + resp.getContent().length + " bytes of content");
  for (HTTPHeader h : resp.getHeaders()) {
    b.append("\n" + h.getName() + ": " + h.getValue());
  }
  b.append("\n" + new String(resp.getContent(), Charsets.UTF_8));
  return "" + b;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:10,代码来源:AffinityMutationProcessor.java

示例10: fetch

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private String fetch(HTTPRequest req) throws IOException {
  HTTPResponse response = fetchService.fetch(req);
  int responseCode = response.getResponseCode();

  if (responseCode >= 300 && responseCode < 400) {
    throw new RuntimeException("Unexpected redirect for url " + req.getURL()
        + ": " + describeResponse(response));
  }

  byte[] rawResponseBody = response.getContent();
  String responseBody;
  if (rawResponseBody == null) {
    responseBody = "";
  } else {
    responseBody = new String(rawResponseBody, Charsets.UTF_8);
  }

  if (responseCode != 200) {
    String msg = req.getURL() + " gave response code " + responseCode
        + ", body: " + responseBody;
    if (responseCode >= 500) {
      throw new IOException(msg);
    } else {
      throw new InvalidStoreRequestException(msg);
    }
  }

  return responseBody;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:30,代码来源:AffinityMutationProcessor.java

示例11: fetch

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
byte[] fetch(URL url, Optional<String> login) throws IOException {
  HTTPRequest req = new HTTPRequest(url, GET, validateCertificate().setDeadline(60d));
  setAuthorizationHeader(req, login);
  HTTPResponse rsp = fetchService.fetch(req);
  if (rsp.getResponseCode() != SC_OK) {
    throw new UrlFetchException("Failed to fetch from MarksDB", req, rsp);
  }
  return rsp.getContent();
}
 
开发者ID:google,项目名称:nomulus,代码行数:10,代码来源:Marksdb.java

示例12: parseResult

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
/**
 * Unmarshals IIRDEA XML result object from {@link HTTPResponse} payload.
 *
 * @see <a href="http://tools.ietf.org/html/draft-lozano-icann-registry-interfaces-05#section-4.1">
 *     ICANN Registry Interfaces - IIRDEA Result Object</a>
 */
private XjcIirdeaResult parseResult(HTTPResponse rsp) throws XmlException {
  byte[] responseBytes = rsp.getContent();
  logger.infofmt("Received response:\n%s", new String(responseBytes, UTF_8));
  XjcIirdeaResponseElement response = XjcXmlTransformer.unmarshal(
      XjcIirdeaResponseElement.class, new ByteArrayInputStream(responseBytes));
  return response.getResult();
}
 
开发者ID:google,项目名称:nomulus,代码行数:14,代码来源:RdeReporter.java

示例13: getContentLength

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private static int getContentLength(HTTPResponse httpResponse) {
  byte[] content = httpResponse.getContent();
  if (content == null) {
    return 0;
  } else {
    return content.length;
  }
}
 
开发者ID:jbufu,项目名称:openid4java,代码行数:9,代码来源:AppEngineHttpFetcher.java

示例14: perform

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的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

示例15: checkURL

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的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


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