本文整理匯總了Java中com.google.api.client.http.HttpRequest.setParser方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequest.setParser方法的具體用法?Java HttpRequest.setParser怎麽用?Java HttpRequest.setParser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.setParser方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: signInWithCustomToken
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
private String signInWithCustomToken(String customToken) throws IOException {
GenericUrl url = new GenericUrl(ID_TOOLKIT_URL + "?key="
+ IntegrationTestUtils.getApiKey());
Map<String, Object> content = ImmutableMap.<String, Object>of(
"token", customToken, "returnSecureToken", true);
HttpRequest request = transport.createRequestFactory().buildPostRequest(url,
new JsonHttpContent(jsonFactory, content));
request.setParser(new JsonObjectParser(jsonFactory));
HttpResponse response = request.execute();
try {
GenericJson json = response.parseAs(GenericJson.class);
return json.get("idToken").toString();
} finally {
response.disconnect();
}
}
示例2: getTokenFromCode
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
private void getTokenFromCode(final String code) throws IOException {
log.debug("Fetching authorisation token using authorisation code");
HttpRequest request =
HTTP_TRANSPORT.createRequestFactory().buildGetRequest(new GenericUrl("https://login.live.com/oauth20_token.srf") {
@Key("client_id")
private String id = clientId;
@Key("client_secret")
private String secret = clientSecret;
@Key("code")
private String authCode = code;
@Key("grant_type")
private String grantType = "authorization_code";
@Key("redirect_uri")
private String redirect = "https://login.live.com/oauth20_desktop.srf";
});
request.setParser(new JsonObjectParser(JSON_FACTORY));
processResponse(request.execute());
}
示例3: getTokenFromRefreshToken
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
private void getTokenFromRefreshToken(final String refreshToken) throws IOException {
log.debug("Fetching authorisation token using refresh token");
HttpRequest request =
HTTP_TRANSPORT.createRequestFactory().buildGetRequest(new GenericUrl("https://login.live.com/oauth20_token.srf") {
@Key("client_id")
private String id = clientId;
@Key("client_secret")
private String secret = clientSecret;
@Key("refresh_token")
private String token = refreshToken;
@Key("grant_type")
private String grantType = "refresh_token";
@Key("redirect_uri")
private String redirect = "https://login.live.com/oauth20_desktop.srf";
});
request.setParser(new JsonObjectParser(JSON_FACTORY));
processResponse(request.execute());
}
示例4: buildPostRequest
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
private HttpRequest buildPostRequest(GenericUrl url, String[] stmts) throws IOException {
HttpRequest request = this.requestFactory.buildPostRequest(url, new JsonHttpContent(JSON_FACTORY, stmts));
return request.setParser(new JsonObjectParser(JSON_FACTORY));
}
示例5: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
request.setParser(new JsonObjectParser(JSON_FACTORY));
}
示例6: start
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void start(Map<String, String> map) {
this.config = new SplunkHttpSinkConnectorConfig(map);
java.util.logging.Logger logger = java.util.logging.Logger.getLogger(HttpTransport.class.getName());
logger.addHandler(new RequestLoggingHandler(log));
if (this.config.curlLoggingEnabled) {
logger.setLevel(Level.ALL);
} else {
logger.setLevel(Level.WARNING);
}
log.info("Starting...");
NetHttpTransport.Builder transportBuilder = new NetHttpTransport.Builder();
if (!this.config.validateCertificates) {
log.warn("Disabling ssl certificate verification.");
try {
transportBuilder.doNotValidateCertificate();
} catch (GeneralSecurityException e) {
throw new IllegalStateException("Exception thrown calling transportBuilder.doNotValidateCertificate()", e);
}
}
if (this.config.hasTrustStorePath) {
log.info("Loading trust store from {}.", this.config.trustStorePath);
try (FileInputStream inputStream = new FileInputStream(this.config.trustStorePath)) {
transportBuilder.trustCertificatesFromJavaKeyStore(inputStream, this.config.trustStorePassword);
} catch (GeneralSecurityException | IOException ex) {
throw new IllegalStateException("Exception thrown while setting up trust certificates.", ex);
}
}
this.transport = transportBuilder.build();
final String authHeaderValue = String.format("Splunk %s", this.config.authToken);
final JsonObjectParser jsonObjectParser = new JsonObjectParser(jsonFactory);
final String userAgent = String.format("kafka-connect-splunk/%s", version());
final boolean curlLogging = this.config.curlLoggingEnabled;
this.httpRequestInitializer = new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
httpRequest.getHeaders().setAuthorization(authHeaderValue);
httpRequest.getHeaders().setAccept(Json.MEDIA_TYPE);
httpRequest.getHeaders().setUserAgent(userAgent);
httpRequest.setParser(jsonObjectParser);
httpRequest.setEncoding(new GZipEncoding());
httpRequest.setThrowExceptionOnExecuteError(false);
httpRequest.setConnectTimeout(config.connectTimeout);
httpRequest.setReadTimeout(config.readTimeout);
httpRequest.setCurlLoggingEnabled(curlLogging);
// httpRequest.setLoggingEnabled(curlLogging);
}
};
this.httpRequestFactory = this.transport.createRequestFactory(this.httpRequestInitializer);
this.eventCollectorUrl = new GenericUrl();
this.eventCollectorUrl.setRawPath("/services/collector/event");
this.eventCollectorUrl.setPort(this.config.splunkPort);
this.eventCollectorUrl.setHost(this.config.splunkHost);
if (this.config.ssl) {
this.eventCollectorUrl.setScheme("https");
} else {
this.eventCollectorUrl.setScheme("http");
}
log.info("Setting Splunk Http Event Collector Url to {}", this.eventCollectorUrl);
}
示例7: prepare
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected void prepare(HttpRequest request) throws IOException {
super.prepare(request);
request.setParser(new XmlObjectParser(namespaceDictionary));
}
示例8: labelDataset
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
/**
* Add or modify a label on a dataset.
*
* <p>See <a href="https://cloud.google.com/bigquery/docs/labeling-datasets">the BigQuery
* documentation</a>.
*/
public static void labelDataset(
String projectId, String datasetId, String labelKey, String labelValue) throws IOException {
// Authenticate requests using Google Application Default credentials.
GoogleCredential credential = GoogleCredential.getApplicationDefault();
credential = credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/bigquery"));
// Get a new access token.
// Note that access tokens have an expiration. You can reuse a token rather than requesting a
// new one if it is not yet expired.
credential.refreshToken();
String accessToken = credential.getAccessToken();
// Set the content of the request.
Dataset dataset = new Dataset();
dataset.addLabel(labelKey, labelValue);
HttpContent content = new JsonHttpContent(JSON_FACTORY, dataset);
// Send the request to the BigQuery API.
String urlFormat =
"https://www.googleapis.com/bigquery/v2/projects/%s/datasets/%s"
+ "?fields=labels&access_token=%s";
GenericUrl url = new GenericUrl(String.format(urlFormat, projectId, datasetId, accessToken));
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
HttpRequest request = requestFactory.buildPostRequest(url, content);
request.setParser(JSON_FACTORY.createJsonObjectParser());
// Workaround for transports which do not support PATCH requests.
// See: http://stackoverflow.com/a/32503192/101923
request.setHeaders(new HttpHeaders().set("X-HTTP-Method-Override", "PATCH"));
HttpResponse response = request.execute();
// Check for errors.
if (response.getStatusCode() != 200) {
throw new RuntimeException(response.getStatusMessage());
}
Dataset responseDataset = response.parseAs(Dataset.class);
System.out.printf(
"Updated label \"%s\" with value \"%s\"\n",
labelKey, responseDataset.getLabels().get(labelKey));
}
示例9: labelTable
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
/**
* Add or modify a label on a table.
*
* <p>See <a href="https://cloud.google.com/bigquery/docs/labeling-datasets">the BigQuery
* documentation</a>.
*/
public static void labelTable(
String projectId,
String datasetId,
String tableId,
String labelKey,
String labelValue)
throws IOException {
// Authenticate requests using Google Application Default credentials.
GoogleCredential credential = GoogleCredential.getApplicationDefault();
credential = credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/bigquery"));
// Get a new access token.
// Note that access tokens have an expiration. You can reuse a token rather than requesting a
// new one if it is not yet expired.
credential.refreshToken();
String accessToken = credential.getAccessToken();
// Set the content of the request.
Table table = new Table();
table.addLabel(labelKey, labelValue);
HttpContent content = new JsonHttpContent(JSON_FACTORY, table);
// Send the request to the BigQuery API.
String urlFormat =
"https://www.googleapis.com/bigquery/v2/projects/%s/datasets/%s/tables/%s"
+ "?fields=labels&access_token=%s";
GenericUrl url =
new GenericUrl(String.format(urlFormat, projectId, datasetId, tableId, accessToken));
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
HttpRequest request = requestFactory.buildPostRequest(url, content);
request.setParser(JSON_FACTORY.createJsonObjectParser());
// Workaround for transports which do not support PATCH requests.
// See: http://stackoverflow.com/a/32503192/101923
request.setHeaders(new HttpHeaders().set("X-HTTP-Method-Override", "PATCH"));
HttpResponse response = request.execute();
// Check for errors.
if (response.getStatusCode() != 200) {
throw new RuntimeException(response.getStatusMessage());
}
Table responseTable = response.parseAs(Table.class);
System.out.printf(
"Updated label \"%s\" with value \"%s\"\n",
labelKey, responseTable.getLabels().get(labelKey));
}
示例10: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(final HttpRequest request) {
request.setParser(new JsonObjectParser(KazooConnection.JSON_FACTORY));
}