本文整理汇总了Java中com.google.api.client.http.HttpHeaders.set方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.set方法的具体用法?Java HttpHeaders.set怎么用?Java HttpHeaders.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.set方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
private <U, T extends ResponseEnvelope<U>> U execute(final HttpRequest httpRequest, final Class<T> responseType) throws IOException {
httpRequest.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
if (authToken != null) {
HttpHeaders headers = httpRequest.getHeaders();
headers.set("X-Auth-Token", authToken);
}
HttpResponse httpResponse = httpRequest.execute();
T response = httpResponse.parseAs(responseType);
// Update authToken, if necessary
if (response.getAuthToken() != null) {
authToken = response.getAuthToken();
}
return response.getData();
}
示例2: testUrlMismatch_verifyDisabled
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Tests behavior when URL validation is disabled.
*/
@Test
public void testUrlMismatch_verifyDisabled() throws IOException {
MockResponse mockResponse = new MockResponse("test response");
mockResponse.setValidateUrlMatches(false);
HttpRequest request =
mockHttpServer
.getHttpTransport()
.createRequestFactory()
.buildGetRequest(
new GenericUrl("http://www.example.com/does_not_match_mock_http_server_url"));
request.setContent(new ByteArrayContent("text", "test content".getBytes(UTF_8)));
HttpHeaders headers = new HttpHeaders();
headers.set("one", "1");
headers.set("two", "2");
request.setHeaders(headers);
mockHttpServer.setMockResponse(mockResponse);
HttpResponse response = request.execute();
ActualResponse actualResponse = mockHttpServer.getLastResponse();
assertEquals("Incorrect response code", 200, response.getStatusCode());
assertEquals(
"Request header 'one' incorrect", "1", actualResponse.getRequestHeader("one").get(0));
assertEquals(
"Request header 'two' incorrect", "2", actualResponse.getRequestHeader("two").get(0));
}
示例3: setUp
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
@Before
public void setUp() throws ConfigException {
config = new ConfigBuilder().setApiKey("test").setEndpoint("http://localhost:8001/").build();
handler = new Handler(config);
headers = new HttpHeaders();
headers.setContentType("application/json");
headers.set("postmen-api-key", "some-api-key");
headers.set("x-postmen-agent", "java-sdk-1.0.0");
headers.set("connection", "keep-alive");
}
示例4: downloadObject
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Downloads a CSEK-protected object from GCS. The download may continue in the background after
* this method returns. The caller of this method is responsible for closing the input stream.
*
* @param storage A Storage object, ready for use
* @param bucketName The name of the destination bucket
* @param objectName The name of the destination object
* @param base64CseKey An AES256 key, encoded as a base64 string.
* @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
*
* @return An InputStream that contains the decrypted contents of the object.
*
* @throws IOException if there was some error download from GCS.
*/
public static InputStream downloadObject(
Storage storage,
String bucketName,
String objectName,
String base64CseKey,
String base64CseKeyHash)
throws Exception {
Storage.Objects.Get getObject = storage.objects().get(bucketName, objectName);
// If you're using AppEngine, turn off setDirectDownloadEnabled:
// getObject.getMediaHttpDownloader().setDirectDownloadEnabled(false);
// Now set the CSEK headers
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("x-goog-encryption-algorithm", "AES256");
httpHeaders.set("x-goog-encryption-key", base64CseKey);
httpHeaders.set("x-goog-encryption-key-sha256", base64CseKeyHash);
getObject.setRequestHeaders(httpHeaders);
try {
return getObject.executeMediaAsInputStream();
} catch (GoogleJsonResponseException e) {
System.out.println("Error downloading: " + e.getContent());
System.exit(1);
return null;
}
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:43,代码来源:CustomerSuppliedEncryptionKeysSamples.java
示例5: uploadObject
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Uploads an object to GCS, to be stored with a customer-supplied key (CSEK). The upload may
* continue in the background after this method returns. The caller of this method is responsible
* for closing the input stream.
*
* @param storage A Storage object, ready for use
* @param bucketName The name of the destination bucket
* @param objectName The name of the destination object
* @param data An InputStream containing the contents of the object to upload
* @param base64CseKey An AES256 key, encoded as a base64 string.
* @param base64CseKeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
* @throws IOException if there was some error uploading to GCS.
*/
public static void uploadObject(
Storage storage,
String bucketName,
String objectName,
InputStream data,
String base64CseKey,
String base64CseKeyHash)
throws IOException {
InputStreamContent mediaContent = new InputStreamContent("text/plain", data);
Storage.Objects.Insert insertObject =
storage.objects().insert(bucketName, null, mediaContent).setName(objectName);
// The client library's default gzip setting may cause objects to be stored with gzip encoding,
// which can be desirable in some circumstances but has some disadvantages as well, such as
// making it difficult to read only a certain range of the original object.
insertObject.getMediaHttpUploader().setDisableGZipContent(true);
// Now set the CSEK headers
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("x-goog-encryption-algorithm", "AES256");
httpHeaders.set("x-goog-encryption-key", base64CseKey);
httpHeaders.set("x-goog-encryption-key-sha256", base64CseKeyHash);
insertObject.setRequestHeaders(httpHeaders);
try {
insertObject.execute();
} catch (GoogleJsonResponseException e) {
System.out.println("Error uploading: " + e.getContent());
System.exit(1);
}
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:45,代码来源:CustomerSuppliedEncryptionKeysSamples.java
示例6: initialize
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Initialize this channel object for writing.
*
* @throws IOException
*/
public void initialize() throws IOException {
// Create a pipe such that its one end is connected to the input stream used by
// the uploader and the other end is the write channel used by the caller.
pipeSource = new PipedInputStream(pipeBufferSize);
pipeSink = new PipedOutputStream(pipeSource);
pipeSinkChannel = Channels.newChannel(pipeSink);
// Connect pipe-source to the stream used by uploader.
InputStreamContent objectContentStream =
new InputStreamContent(contentType, pipeSource);
// Indicate that we do not know length of file in advance.
objectContentStream.setLength(-1);
objectContentStream.setCloseInputStream(false);
T request = createRequest(objectContentStream);
request.setDisableGZipContent(true);
// Set a larger backend upload-chunk granularity than system defaults.
HttpHeaders headers = clientRequestHelper.getRequestHeaders(request);
headers.set("X-Goog-Upload-Desired-Chunk-Granularity",
Math.min(GCS_UPLOAD_GRANULARITY, uploadBufferSize));
// Legacy check. Will be phased out.
if (limitFileSizeTo250Gb) {
headers.set("X-Goog-Upload-Max-Raw-Size", UPLOAD_MAX_SIZE);
}
// Change chunk size from default value (10MB) to one that yields higher performance.
clientRequestHelper.setChunkSize(request, uploadBufferSize);
// Given that the two ends of the pipe must operate asynchronous relative
// to each other, we need to start the upload operation on a separate thread.
uploadOperation = threadPool.submit(new UploadOperation(request, pipeSource));
isInitialized = true;
}
示例7: createHeaders
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
private HttpHeaders createHeaders(String merchantId, String userId, String authKey, String authMethod, String testbedToken) {
HttpHeaders headers = new HttpHeaders();
headers.set("X-Mcash-Merchant", merchantId);
headers.set("X-Mcash-User", userId);
headers.setAccept("application/vnd.mcash.api.merchant.v1+json");
if (testbedToken != null) {
headers.set("X-Testbed-Token", testbedToken);
}
if (authMethod.equals("SECRET")) {
headers.setAuthorization(String.format("SECRET %s", authKey));
} else {
throw new IllegalArgumentException("Invalid auth method " + authMethod);
}
return headers;
}
示例8: getStreetModel
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
public static InputStream getStreetModel() throws RequestFailedException, IOException {
if (authToken == null)
initBlockingUILogin();
InputStream data = null;
HttpRequest getRequest;
HttpResponse response;
getRequest = requestFactory.buildGetRequest(getStreetModelUrl);
HttpHeaders headers = getRequest.getHeaders();
headers.set(authTokenKeyName, authToken);
getRequest.setHeaders(headers);
response = getRequest.execute();
if (response.getStatusCode() == UNAUTHORIZED_STATUS_CODE)
initBlockingUILogin();
else if (!response.isSuccessStatusCode()) {
int status = response.getStatusCode();
String error = status + ": " + response.getStatusMessage();
throw new RequestFailedException(error);
}
data = response.getContent();
return data;
}
示例9: createHeaders
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Creates the http headers object for this request, populated from data in
* the session.
* @throws AuthenticationException If OAuth authorization fails.
*/
private HttpHeaders createHeaders(String reportUrl, String version)
throws AuthenticationException {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAuthorization(
authorizationHeaderProvider.getAuthorizationHeader(session, reportUrl));
httpHeaders.setUserAgent(userAgentCombiner.getUserAgent(session.getUserAgent()));
httpHeaders.set("developerToken", session.getDeveloperToken());
httpHeaders.set("clientCustomerId", session.getClientCustomerId());
ReportingConfiguration reportingConfiguration = session.getReportingConfiguration();
if (reportingConfiguration != null) {
reportingConfiguration.validate(version);
if (reportingConfiguration.isSkipReportHeader() != null) {
httpHeaders.set("skipReportHeader",
Boolean.toString(reportingConfiguration.isSkipReportHeader()));
}
if (reportingConfiguration.isSkipColumnHeader() != null) {
httpHeaders.set("skipColumnHeader",
Boolean.toString(reportingConfiguration.isSkipColumnHeader()));
}
if (reportingConfiguration.isSkipReportSummary() != null) {
httpHeaders.set("skipReportSummary",
Boolean.toString(reportingConfiguration.isSkipReportSummary()));
}
if (reportingConfiguration.isIncludeZeroImpressions() != null) {
httpHeaders.set(
"includeZeroImpressions",
Boolean.toString(reportingConfiguration.isIncludeZeroImpressions()));
}
if (reportingConfiguration.isUseRawEnumValues() != null) {
httpHeaders.set(
"useRawEnumValues",
Boolean.toString(reportingConfiguration.isUseRawEnumValues()));
}
}
return httpHeaders;
}
示例10: rotateKey
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Given an existing, CSEK-protected object, changes the key used to store that object.
*
* @param storage A Storage object, ready for use
* @param bucketName The name of the destination bucket
* @param objectName The name of the destination object
* @param originalBase64Key The AES256 key currently associated with this object,
* encoded as a base64 string.
* @param originalBase64KeyHash The SHA-256 hash of the above key,
* also encoded as a base64 string.
* @param newBase64Key An AES256 key which will replace the existing key,
* encoded as a base64 string.
* @param newBase64KeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
* @throws IOException if there was some error download from GCS.
*/
public static void rotateKey(
Storage storage,
String bucketName,
String objectName,
String originalBase64Key,
String originalBase64KeyHash,
String newBase64Key,
String newBase64KeyHash)
throws Exception {
Storage.Objects.Rewrite rewriteObject =
storage.objects().rewrite(bucketName, objectName, bucketName, objectName, null);
// Now set the CSEK headers
final HttpHeaders httpHeaders = new HttpHeaders();
// Specify the exiting object's current CSEK.
httpHeaders.set("x-goog-copy-source-encryption-algorithm", "AES256");
httpHeaders.set("x-goog-copy-source-encryption-key", originalBase64Key);
httpHeaders.set("x-goog-copy-source-encryption-key-sha256", originalBase64KeyHash);
// Specify the new CSEK that we would like to apply.
httpHeaders.set("x-goog-encryption-algorithm", "AES256");
httpHeaders.set("x-goog-encryption-key", newBase64Key);
httpHeaders.set("x-goog-encryption-key-sha256", newBase64KeyHash);
rewriteObject.setRequestHeaders(httpHeaders);
try {
RewriteResponse rewriteResponse = rewriteObject.execute();
// If an object is very large, you may need to continue making successive calls to
// rewrite until the operation completes.
while (!rewriteResponse.getDone()) {
System.out.println("Rewrite did not complete. Resuming...");
rewriteObject.setRewriteToken(rewriteResponse.getRewriteToken());
rewriteResponse = rewriteObject.execute();
}
} catch (GoogleJsonResponseException e) {
System.out.println("Error rotating key: " + e.getContent());
System.exit(1);
}
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:58,代码来源:CustomerSuppliedEncryptionKeysSamples.java
示例11: createHeaders
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
private HttpHeaders createHeaders(String token, boolean debug) {
HttpHeaders headers = new HttpHeaders();
headers.set("X-Custom-Authorization", token);
headers.set("X-Debug", debug);
return headers;
}
示例12: writeTo
import com.google.api.client.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public void writeTo(OutputStream out) throws IOException {
Writer writer = new OutputStreamWriter(out, getCharset());
String boundary = getBoundary();
for (Part part : parts) {
HttpHeaders headers = new HttpHeaders().setAcceptEncoding(null);
if (part.headers != null) {
headers.fromHttpHeaders(part.headers);
}
headers.setContentEncoding(null).setUserAgent(null).setContentType(null).setContentLength(null);
// analyze the content
HttpContent content = part.content;
StreamingContent streamingContent = null;
String contentDisposition = String.format("form-data; name=\"%s\"", part.name);
if (part.filename != null) {
headers.setContentType(content.getType());
contentDisposition += String.format("; filename=\"%s\"", part.filename);
}
headers.set("Content-Disposition", contentDisposition);
HttpEncoding encoding = part.encoding;
if (encoding == null) {
streamingContent = content;
} else {
headers.setContentEncoding(encoding.getName());
streamingContent = new HttpEncodingStreamingContent(content, encoding);
}
// write separator
writer.write(TWO_DASHES);
writer.write(boundary);
writer.write(NEWLINE);
// write headers
HttpHeaders.serializeHeadersForMultipartRequests(headers, null, null, writer);
// write content
if (streamingContent != null) {
writer.write(NEWLINE);
writer.flush();
streamingContent.writeTo(out);
writer.write(NEWLINE);
}
}
// write end separator
writer.write(TWO_DASHES);
writer.write(boundary);
writer.write(TWO_DASHES);
writer.write(NEWLINE);
writer.flush();
}