本文整理了Java中com.google.api.client.http.HttpResponse.getHeaders()
方法的一些代码示例,展示了HttpResponse.getHeaders()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getHeaders()
方法的具体详情如下:
包路径:com.google.api.client.http.HttpResponse
类名称:HttpResponse
方法名:getHeaders
暂无
代码示例来源:origin: GoogleContainerTools/jib
/**
* @param headerName the header name
* @return a list of headers in the response
*/
public List<String> getHeader(String headerName) {
return httpResponse.getHeaders().getHeaderStringValues(headerName);
}
代码示例来源:origin: GoogleContainerTools/jib
/**
* @return the first {@code Content-Length} header, or {@code -1} if not found
* @throws NumberFormatException if parsing the content length header fails
*/
public long getContentLength() throws NumberFormatException {
String contentLengthHeader =
httpResponse.getHeaders().getFirstHeaderStringValue(HttpHeaders.CONTENT_LENGTH);
if (contentLengthHeader == null) {
return -1;
}
try {
return Long.parseLong(contentLengthHeader);
} catch (NumberFormatException ex) {
return -1;
}
}
代码示例来源:origin: googleapis/google-cloud-java
@InternalApi("Visible for testing")
static boolean headerContainsMetadataFlavor(HttpResponse response) {
String metadataFlavorValue = response.getHeaders().getFirstHeaderStringValue("Metadata-Flavor");
return "Google".equals(metadataFlavorValue);
}
代码示例来源:origin: google/data-transfer-project
private static void validateResponse(HttpResponse response, int expectedCode) throws IOException {
if (response.getStatusCode() != expectedCode) {
throw new IOException("Unexpected return code: "
+ response.getStatusCode()
+ "\nMessage:\n"
+ response.getStatusMessage()
+ "\nHeaders:\n"
+ response.getHeaders());
}
}
代码示例来源:origin: google/data-transfer-project
private static void validateResponse(
HttpRequest request, HttpResponse response, int expectedCode) throws IOException {
if (response.getStatusCode() != expectedCode) {
throw new IOException("Unexpected return code: "
+ response.getStatusCode()
+ "\nMessage:\n"
+ response.getStatusMessage()
+ "\nfrom:\n"
+ request.getUrl()
+ "\nHeaders:\n"
+ response.getHeaders());
}
}
代码示例来源:origin: google/data-transfer-project
private String makeCall(HttpTransport transport) throws IOException {
HttpRequest get =
transport.createRequestFactory()
.buildPostRequest(new GenericUrl(INRPUT_LOGIN_SERVER), null)
.setFollowRedirects(false)
.setThrowExceptionOnExecuteError(false);
HttpResponse response = get.execute();
if (response.getStatusCode() != 302) {
throw new IOException("Unexpected return code: "
+ response.getStatusCode()
+ "\nMessage:\n"
+ response.getStatusMessage());
}
String cookieValue = response.getHeaders().getFirstHeaderStringValue("set-cookie");
if (Strings.isNullOrEmpty(cookieValue)) {
throw new IOException("Couldn't extract cookie value from headers: " + response.getHeaders());
}
return cookieValue;
}
}
代码示例来源:origin: google/data-transfer-project
/** Posts an RDF model to a Solid server. **/
public String postContent(
String url,
String slug,
String type,
Model model)
throws IOException {
StringWriter stringWriter = new StringWriter();
model.write(stringWriter, "TURTLE");
HttpContent content = new ByteArrayContent("text/turtle", stringWriter.toString().getBytes());
HttpRequest postRequest = factory.buildPostRequest(
new GenericUrl(url), content);
HttpHeaders headers = new HttpHeaders();
headers.setCookie(authCookie);
headers.set("Link", "<" + type + ">; rel=\"type\"");
headers.set("Slug", slug);
postRequest.setHeaders(headers);
HttpResponse response = postRequest.execute();
validateResponse(response, 201);
return response.getHeaders().getLocation();
}
代码示例来源:origin: googleapis/google-cloud-java
@Override
public String open(Job loadJob) {
try {
String builder = BASE_RESUMABLE_URI + options.getProjectId() + "/jobs";
GenericUrl url = new GenericUrl(builder);
url.set("uploadType", "resumable");
JsonFactory jsonFactory = bigquery.getJsonFactory();
HttpRequestFactory requestFactory = bigquery.getRequestFactory();
HttpRequest httpRequest =
requestFactory.buildPostRequest(url, new JsonHttpContent(jsonFactory, loadJob));
httpRequest.getHeaders().set("X-Upload-Content-Value", "application/octet-stream");
HttpResponse response = httpRequest.execute();
return response.getHeaders().getLocation();
} catch (IOException ex) {
throw translate(ex);
}
}
代码示例来源:origin: googleapis/google-cloud-java
throw translate(error);
return response.getHeaders().getLocation();
} catch (IOException ex) {
span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
代码示例来源:origin: org.ctoolkit.restapi/ctoolkit-rest-facade-adapter
@Override
public void interceptResponse( HttpResponse response ) throws IOException
{
headers = response.getHeaders();
}
代码示例来源:origin: gradle.plugin.com.google.cloud.tools/jib-gradle-plugin
/**
* @param headerName the header name
* @return a list of headers in the response
*/
public List<String> getHeader(String headerName) {
return httpResponse.getHeaders().getHeaderStringValues(headerName);
}
代码示例来源:origin: com.google.cloud.tools/jib-maven-plugin
/**
* @param headerName the header name
* @return a list of headers in the response
*/
public List<String> getHeader(String headerName) {
return httpResponse.getHeaders().getHeaderStringValues(headerName);
}
代码示例来源:origin: gradle.plugin.com.google.cloud.tools/jib-gradle-plugin
/**
* @return the first {@code Content-Length} header, or {@code -1} if not found
* @throws NumberFormatException if parsing the content length header fails
*/
public long getContentLength() throws NumberFormatException {
String contentLengthHeader =
httpResponse.getHeaders().getFirstHeaderStringValue(HttpHeaders.CONTENT_LENGTH);
if (contentLengthHeader == null) {
return -1;
}
try {
return Long.parseLong(contentLengthHeader);
} catch (NumberFormatException ex) {
return -1;
}
}
代码示例来源:origin: com.google.cloud.tools/jib-maven-plugin
/**
* @return the first {@code Content-Length} header, or {@code -1} if not found
* @throws NumberFormatException if parsing the content length header fails
*/
public long getContentLength() throws NumberFormatException {
String contentLengthHeader =
httpResponse.getHeaders().getFirstHeaderStringValue(HttpHeaders.CONTENT_LENGTH);
if (contentLengthHeader == null) {
return -1;
}
try {
return Long.parseLong(contentLengthHeader);
} catch (NumberFormatException ex) {
return -1;
}
}
代码示例来源:origin: com.github.mjeanroy/rest-assert-core
@Override
public List<String> getHeader(String name) {
HttpHeaders headers = response.getHeaders();
if (headers == null || headers.isEmpty()) {
return emptyList();
}
return headers.getHeaderStringValues(name);
}
代码示例来源:origin: com.google.cloud/google-cloud-core
@InternalApi("Visible for testing")
static boolean headerContainsMetadataFlavor(HttpResponse response) {
String metadataFlavorValue = response.getHeaders().getFirstHeaderStringValue("Metadata-Flavor");
return "Google".equals(metadataFlavorValue);
}
代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.rt.server.commons
protected void writeResponseHeaders(HttpServletResponse resp, HttpResponse httpResp) {
for (Entry<String, Object> entry : httpResp.getHeaders().entrySet()) {
String name = entry.getKey();
String value = entry.getValue() instanceof Collection<?> ? CollectionUtility.firstElement(entry.getValue()).toString() : entry.getValue().toString();
String originalValue = value;
for (IHttpHeaderFilter filter : getResponseHeaderFilters()) {
value = filter.filter(name, value);
}
if (value != null) {
resp.setHeader(entry.getKey(), value);
LOG.trace("Added response header: {}: {}", entry.getKey(), value);
}
else {
LOG.trace("Removed response header: {} (original value: {})", name, originalValue);
}
}
}
代码示例来源:origin: siom79/jdrivesync
private Range requestStatus(HttpRequestFactory requestFactory, GenericUrl uploadUri, File fileToUpload) throws IOException {
HttpRequest httpRequest = createHttpRequest(requestFactory, HttpMethods.PUT, uploadUri, new EmptyContent());
httpRequest.getHeaders().setContentRange("*/" + fileToUpload.length());
LOGGER.log(Level.FINE, "Executing status request.");
HttpResponse httpResponse = executeHttpRequest(httpRequest);
if(!httpResponse.isSuccessStatusCode()) {
throw new IOException("Status request was not successful. Status-Code: " + httpResponse.getStatusCode());
}
String range = httpResponse.getHeaders().getRange();
return Range.valueOf(range);
}
代码示例来源:origin: siom79/jdrivesync
private String requestUploadLocation(java.io.File fileToUpload, String mimeType, HttpRequestFactory requestFactory, com.google.api.services.drive.model.File remoteFile) throws IOException {
GenericUrl initializationUrl = new GenericUrl("https://www.googleapis.com/upload/drive/v2/files");
initializationUrl.put("uploadType", "resumable");
HttpRequest httpRequest = createHttpRequest(requestFactory, HttpMethods.POST, initializationUrl, new JsonHttpContent(DriveFactory.getJsonFactory(), remoteFile));
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.put("X-Upload-Content-Type", mimeType);
httpHeaders.put("X-Upload-Content-Length", fileToUpload.length());
httpRequest.getHeaders().putAll(httpHeaders);
LOGGER.log(Level.FINE, "Executing initial upload location request.");
HttpResponse httpResponse = executeHttpRequest(httpRequest);
if(!httpResponse.isSuccessStatusCode()) {
throw new IOException("Request for upload location was not successful. Status-Code: " + httpResponse.getStatusCode());
}
String location = httpResponse.getHeaders().getLocation();
LOGGER.log(Level.FINE, "URL for resumable upload: " + location);
return location;
}
代码示例来源:origin: com.google.cloud/google-cloud-bigquery
@Override
public String open(Job loadJob) {
try {
String builder = BASE_RESUMABLE_URI + options.getProjectId() + "/jobs";
GenericUrl url = new GenericUrl(builder);
url.set("uploadType", "resumable");
JsonFactory jsonFactory = bigquery.getJsonFactory();
HttpRequestFactory requestFactory = bigquery.getRequestFactory();
HttpRequest httpRequest =
requestFactory.buildPostRequest(url, new JsonHttpContent(jsonFactory, loadJob));
httpRequest.getHeaders().set("X-Upload-Content-Value", "application/octet-stream");
HttpResponse response = httpRequest.execute();
return response.getHeaders().getLocation();
} catch (IOException ex) {
throw translate(ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!