本文整理汇总了Java中com.google.api.client.http.UrlEncodedContent类的典型用法代码示例。如果您正苦于以下问题:Java UrlEncodedContent类的具体用法?Java UrlEncodedContent怎么用?Java UrlEncodedContent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UrlEncodedContent类属于com.google.api.client.http包,在下文中一共展示了UrlEncodedContent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeStmt
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
public String executeStmt(String method, String urlString, String statement, List<NameValuePair> qparams)
throws IOException {
Check.notNull(statement);
GenericUrl url = setParams(new GenericUrl(urlString), qparams);
UrlEncodedContent urlEntity = setMediaType(getUrlEncodedSql(statement));
HttpRequestFactory rf = httpTransport.createRequestFactory(credential);
HttpResponse response = rf.buildRequest(method, url, urlEntity).execute();
String result = readGoogleResponse(response);
if (response.getStatusCode() != HttpServletResponse.SC_OK)
throw new RuntimeException(result.toString() + statement);
return result;
}
示例2: getGoogleIdToken
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
private static String getGoogleIdToken(String jwt) throws Exception {
final GenericData tokenRequest =
new GenericData().set("grant_type", JWT_BEARER_TOKEN_GRANT_TYPE).set("assertion", jwt);
final UrlEncodedContent content = new UrlEncodedContent(tokenRequest);
final HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
final HttpRequest request =
requestFactory
.buildPostRequest(new GenericUrl(OAUTH_TOKEN_URI), content)
.setParser(new JsonObjectParser(JacksonFactory.getDefaultInstance()));
HttpResponse response;
String idToken = null;
response = request.execute();
GenericData responseData = response.parseAs(GenericData.class);
idToken = (String) responseData.get("id_token");
return idToken;
}
示例3: loginUser
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
/**
* Login an exiting Kickflip User and make it active.
*
* @param username The Kickflip user's username
* @param password The Kickflip user's password
* @param cb This callback will receive a User in {@link io.kickflip.sdk.api.KickflipCallback#onSuccess(io.kickflip.sdk.api.json.Response)}
* or an Exception {@link io.kickflip.sdk.api.KickflipCallback#onError(io.kickflip.sdk.exception.KickflipException)}.
*/
public void loginUser(String username, final String password, final KickflipCallback cb) {
GenericData data = new GenericData();
data.put("username", username);
data.put("password", password);
post(GET_USER_PRIVATE, new UrlEncodedContent(data), User.class, new KickflipCallback() {
@Override
public void onSuccess(final Response response) {
if (VERBOSE)
Log.i(TAG, "loginUser response: " + response);
storeNewUserResponse((User) response, password);
postResponseToCallback(cb, response);
}
@Override
public void onError(final KickflipException error) {
Log.w(TAG, "loginUser Error: " + error);
postExceptionToCallback(cb, error);
}
});
}
示例4: getUserInfo
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
/**
* Get public user info
*
* @param username The Kickflip user's username
* @param cb This callback will receive a User in {@link io.kickflip.sdk.api.KickflipCallback#onSuccess(io.kickflip.sdk.api.json.Response)}
* or an Exception {@link io.kickflip.sdk.api.KickflipCallback#onError(io.kickflip.sdk.exception.KickflipException)}.
*/
public void getUserInfo(String username, final KickflipCallback cb) {
if (!assertActiveUserAvailable(cb)) return;
GenericData data = new GenericData();
data.put("username", username);
post(GET_USER_PUBLIC, new UrlEncodedContent(data), User.class, new KickflipCallback() {
@Override
public void onSuccess(final Response response) {
if (VERBOSE)
Log.i(TAG, "getUserInfo response: " + response);
postResponseToCallback(cb, response);
}
@Override
public void onError(final KickflipException error) {
Log.w(TAG, "getUserInfo Error: " + error);
postExceptionToCallback(cb, error);
}
});
}
示例5: startStreamWithUser
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
/**
* Start a new Stream owned by the given User. Must be called after
* {@link io.kickflip.sdk.api.KickflipApiClient#createNewUser(KickflipCallback)}
* Delivers stream endpoint destination data via a {@link io.kickflip.sdk.api.KickflipCallback}.
*
* @param user The Kickflip User on whose behalf this request is performed.
* @param cb This callback will receive a Stream subclass in {@link io.kickflip.sdk.api.KickflipCallback#onSuccess(io.kickflip.sdk.api.json.Response)}
* depending on the Kickflip account type. Implementors should
* check if the response is instanceof HlsStream, StartRtmpStreamResponse, etc.
*/
private void startStreamWithUser(User user, Stream stream, final KickflipCallback cb) {
checkNotNull(user);
checkNotNull(stream);
GenericData data = new GenericData();
data.put("uuid", user.getUUID());
data.put("private", stream.isPrivate());
if (stream.getTitle() != null) {
data.put("title", stream.getTitle());
}
if (stream.getDescription() != null) {
data.put("description", stream.getDescription());
}
if (stream.getExtraInfo() != null) {
data.put("extra_info", new Gson().toJson(stream.getExtraInfo()));
}
post(START_STREAM, new UrlEncodedContent(data), HlsStream.class, cb);
}
示例6: loadDataFromNetwork
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
/**
* <pre>
* status[drink_id]=50fb3d16ce007c40fc00080d&status[dealer_id]=52cd8b5e7a58b40eae004e40&status[status]=1
* </pre>
*/
@Override
public DrinkStatus loadDataFromNetwork() throws Exception {
Map<String, String> tempParameters = new HashMap<>();
tempParameters.put("status[drink_id]", drinkId);
tempParameters.put("status[dealer_id]",dealerId);
tempParameters.put("status[status]",drinkStatus.getStatusId());
HttpContent tempContent = new UrlEncodedContent(tempParameters);
HttpRequest request = getHttpRequestFactory().buildPostRequest(new GenericUrl(URL_BASE + URL_STATUS_UPDATE), tempContent);
GsonBuilder tmpBuilder = new GsonBuilder();
tmpBuilder.registerTypeAdapter(Dealer.class, new DealerDetailsDeserializer());
Gson tempGson = tmpBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
DrinkStatus tmpDealer;
try (InputStream in = request.execute().getContent()) {
tmpDealer = tempGson.fromJson(new InputStreamReader(in), DrinkStatus.class);
if (tmpDealer == null) {
Log.e(LOGTAG, "No dealer details downloaded");
} else {
Log.i(LOGTAG, "Downloaded dealer details: " + tmpDealer);
}
}
return tmpDealer;
}
示例7: extractPayload
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
private String extractPayload(HttpHeaders headers, @Nullable HttpContent content) {
StringBuilder messageBuilder = new StringBuilder();
if (headers != null) {
appendMapAsString(messageBuilder, headers);
}
if (content != null) {
messageBuilder.append(String.format("%nContent:%n"));
if (content instanceof UrlEncodedContent) {
UrlEncodedContent encodedContent = (UrlEncodedContent) content;
appendMapAsString(messageBuilder, Data.mapOf(encodedContent.getData()));
} else if (content != null) {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try {
content.writeTo(byteStream);
messageBuilder.append(byteStream.toString(StandardCharsets.UTF_8.name()));
} catch (IOException e) {
messageBuilder.append("Unable to read request content due to exception: " + e);
}
}
}
return messageBuilder.toString();
}
示例8: post
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
public void post() {
try {
HashMap<Object, Object> payloadToSend = Maps.newHashMap();
payloadToSend.put("payload", getPayloadAsJson());
requestFactory.buildPostRequest(new GenericUrl(url), new UrlEncodedContent(payloadToSend))
.execute();
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例9: buildAuthContent
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
UrlEncodedContent buildAuthContent() {
Map<String, String> content = new LinkedHashMap<>();
content.put("grant_type", "password");
content.put("client_id", this.config.consumerKey);
content.put("client_secret", this.config.consumerSecret);
content.put("username", this.config.username);
String password = String.format("%s%s", this.config.password, this.config.passwordToken);
content.put("password", password);
return new UrlEncodedContent(content);
}
示例10: intercept
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
@Override
public void intercept(HttpRequest request) throws IOException {
Map<String, Object> data = Data.mapOf(UrlEncodedContent.getContent(request).getData());
if (clientSecret != null) {
data.put("client_assertion", clientSecret);
}
data.put("client_assertion_type", CLIENT_ASSERTION_TYPE);
data.put("grant_type", GRANT_TYPE);
}
示例11: doPost
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
@Override
public final void doPost(final HttpServletRequest req, final HttpServletResponse resp)
throws IOException {
HttpTransport httpTransport;
try {
Map<Object, Object> params = new HashMap<>();
params.putAll(req.getParameterMap());
params.put("task", req.getHeader("X-AppEngine-TaskName"));
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = GoogleCredential.getApplicationDefault()
.createScoped(Collections.singleton("https://www.googleapis.com/auth/userinfo.email"));
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
GenericUrl url = new GenericUrl(ConfigurationConstants.IMAGE_RESIZER_URL);
HttpRequest request = requestFactory.buildPostRequest(url, new UrlEncodedContent(params));
credential.initialize(request);
HttpResponse response = request.execute();
if (!response.isSuccessStatusCode()) {
log("Call to the imageresizer failed: " + response.getContent().toString());
resp.setStatus(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
} else {
resp.setStatus(response.getStatusCode());
}
} catch (GeneralSecurityException | IOException e) {
log("Http request error: " + e.getMessage());
resp.setStatus(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
}
}
示例12: send
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
private void send(String s) throws IOException
{
HashMap<Object, Object> payloadToSend = Maps.newHashMap();
payloadToSend.put("payload", s);
requestFactory.buildPostRequest(new GenericUrl(url), new UrlEncodedContent(payloadToSend)).execute();
}
示例13: setUserInfo
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
/**
* Set the current active user's meta info. Pass a null argument to leave it as-is.
*
* @param newPassword the user's new password
* @param email the user's new email address
* @param displayName The desired display name
* @param extraInfo Arbitrary String data to associate with this user.
* @param cb This callback will receive a User in {@link io.kickflip.sdk.api.KickflipCallback#onSuccess(io.kickflip.sdk.api.json.Response)}
* or an Exception {@link io.kickflip.sdk.api.KickflipCallback#onError(io.kickflip.sdk.exception.KickflipException)}.
*/
public void setUserInfo(final String newPassword, String email, String displayName, Map extraInfo, final KickflipCallback cb) {
if (!assertActiveUserAvailable(cb)) return;
GenericData data = new GenericData();
final String finalPassword;
if (newPassword != null){
data.put("new_password", newPassword);
finalPassword = newPassword;
} else {
finalPassword = getPasswordForActiveUser();
}
if (email != null) data.put("email", email);
if (displayName != null) data.put("display_name", displayName);
if (extraInfo != null) data.put("extra_info", new Gson().toJson(extraInfo));
post(EDIT_USER, new UrlEncodedContent(data), User.class, new KickflipCallback() {
@Override
public void onSuccess(final Response response) {
if (VERBOSE)
Log.i(TAG, "setUserInfo response: " + response);
storeNewUserResponse((User) response, finalPassword);
postResponseToCallback(cb, response);
}
@Override
public void onError(final KickflipException error) {
Log.w(TAG, "setUserInfo Error: " + error);
postExceptionToCallback(cb, error);
}
});
}
示例14: stopStream
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
/**
* Stop a Stream owned by the given Kickflip User.
*
* @param cb This callback will receive a Stream subclass in #onSuccess(response)
* depending on the Kickflip account type. Implementors should
* check if the response is instanceof HlsStream, etc.
*/
private void stopStream(User user, Stream stream, final KickflipCallback cb) {
checkNotNull(stream);
// TODO: Add start / stop lat lon to Stream?
GenericData data = new GenericData();
data.put("stream_id", stream.getStreamId());
data.put("uuid", user.getUUID());
if (stream.getLatitude() != 0) {
data.put("lat", stream.getLatitude());
}
if (stream.getLongitude() != 0) {
data.put("lon", stream.getLongitude());
}
post(STOP_STREAM, new UrlEncodedContent(data), HlsStream.class, cb);
}
示例15: setStreamInfo
import com.google.api.client.http.UrlEncodedContent; //导入依赖的package包/类
/**
* Send Stream Metadata for a {@link io.kickflip.sdk.api.json.Stream}.
* The target Stream must be owned by the User created with {@link io.kickflip.sdk.api.KickflipApiClient#createNewUser(KickflipCallback)}
* from this KickflipApiClient.
*
* @param stream the {@link io.kickflip.sdk.api.json.Stream} to get Meta data for
* @param cb A callback to receive the updated Stream upon request completion
*/
public void setStreamInfo(Stream stream, final KickflipCallback cb) {
if (!assertActiveUserAvailable(cb)) return;
GenericData data = new GenericData();
data.put("stream_id", stream.getStreamId());
data.put("uuid", getActiveUser().getUUID());
if (stream.getTitle() != null) {
data.put("title", stream.getTitle());
}
if (stream.getDescription() != null) {
data.put("description", stream.getDescription());
}
if (stream.getExtraInfo() != null) {
data.put("extra_info", new Gson().toJson(stream.getExtraInfo()));
}
if (stream.getLatitude() != 0) {
data.put("lat", stream.getLatitude());
}
if (stream.getLongitude() != 0) {
data.put("lon", stream.getLongitude());
}
if (stream.getCity() != null) {
data.put("city", stream.getCity());
}
if (stream.getState() != null) {
data.put("state", stream.getState());
}
if (stream.getCountry() != null) {
data.put("country", stream.getCountry());
}
if (stream.getThumbnailUrl() != null) {
data.put("thumbnail_url", stream.getThumbnailUrl());
}
data.put("private", stream.isPrivate());
data.put("deleted", stream.isDeleted());
post(SET_META, new UrlEncodedContent(data), Stream.class, cb);
}