本文整理匯總了Java中com.google.api.client.json.JsonObjectParser類的典型用法代碼示例。如果您正苦於以下問題:Java JsonObjectParser類的具體用法?Java JsonObjectParser怎麽用?Java JsonObjectParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JsonObjectParser類屬於com.google.api.client.json包,在下文中一共展示了JsonObjectParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deleteInstanceId
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
private Task<Void> deleteInstanceId(final String instanceId) {
checkArgument(!Strings.isNullOrEmpty(instanceId), "instance ID must not be null or empty");
return ImplFirebaseTrampolines.submitCallable(app, new Callable<Void>(){
@Override
public Void call() throws Exception {
String url = String.format(
"%s/project/%s/instanceId/%s", IID_SERVICE_URL, projectId, instanceId);
HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(url));
request.setParser(new JsonObjectParser(jsonFactory));
request.setResponseInterceptor(interceptor);
HttpResponse response = null;
try {
response = request.execute();
ByteStreams.exhaust(response.getContent());
} catch (Exception e) {
handleError(instanceId, e);
} finally {
if (response != null) {
response.disconnect();
}
}
return null;
}
});
}
示例2: signInWithCustomToken
import com.google.api.client.json.JsonObjectParser; //導入依賴的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();
}
}
示例3: constructHttpRequest
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
private HttpRequest constructHttpRequest(final String content) throws IOException {
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
result.setContentType("application/json");
result.setContent(content);
return result;
}
};
}
};
return transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com"))
.setParser(new JsonObjectParser(new JacksonFactory()));
}
示例4: getHttpRequestFactory
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
/**
* TODO(malcon): Consolidate GitHub and this one in one class
*/
private HttpRequestFactory getHttpRequestFactory(@Nullable UserPassword userPassword)
throws RepoException, ValidationException {
return httpTransport.createRequestFactory(
request -> {
request.setConnectTimeout((int) Duration.ofMinutes(1).toMillis());
request.setReadTimeout((int) Duration.ofMinutes(1).toMillis());
HttpHeaders httpHeaders = new HttpHeaders();
if (userPassword != null) {
httpHeaders.setBasicAuthentication(userPassword.getUsername(),
userPassword.getPassword_BeCareful());
}
request.setHeaders(httpHeaders);
request.setParser(new JsonObjectParser(JSON_FACTORY));
});
}
示例5: getTokenFromCode
import com.google.api.client.json.JsonObjectParser; //導入依賴的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());
}
示例6: getTokenFromRefreshToken
import com.google.api.client.json.JsonObjectParser; //導入依賴的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());
}
示例7: ROOneDriveProvider
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
public ROOneDriveProvider(final AuthorisationProvider authoriser) {
requestFactory =
HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) {
request.setParser(new JsonObjectParser(JSON_FACTORY));
request.setReadTimeout(60000);
request.setConnectTimeout(60000);
try {
request.getHeaders().setAuthorization("bearer " + authoriser.getAccessToken());
} catch (IOException e) {
throw Throwables.propagate(e);
}
request.setUnsuccessfulResponseHandler(new OneDriveResponseHandler(authoriser));
}
});
}
示例8: WikiMapiaRetriever
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
public WikiMapiaRetriever(Credentials credentials) throws Exception {
super(credentials);
if (credentials.getKey() == null) {
logger.error("Wikimapia requires an API key.");
throw new Exception("Wikimapia requires an API key.");
}
key = credentials.getKey();
requestFactory = HTTP_TRANSPORT.createRequestFactory(
new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) {
request.setParser(new JsonObjectParser(JSON_FACTORY));
}
});
}
示例9: getGoogleIdToken
import com.google.api.client.json.JsonObjectParser; //導入依賴的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;
}
示例10: testBuildSettingsFromFile
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
@Test
public void testBuildSettingsFromFile() throws IOException {
try {
FileReader fileReader = new FileReader("src/main/resources/example_settings_1.json");
JsonObjectParser parser = new JsonObjectParser(JSON_FACTORY);
Settings settings = parser.parseAndClose(fileReader, Settings.class);
assertEquals("1", settings.getId());
assertEquals("1", settings.getApiUser());
assertEquals("4ae0c36da907994c6458958e262c7b3f0677d035", settings.getApiToken());
assertEquals("C:\\focus24\\temp\\", settings.getTmpDirectory());
assertEquals("C:\\focus24\\", settings.getWorkingDirectory());
assertEquals("http://localhost:8000/", settings.getServer_ip());
assertEquals("mysqldump", settings.getMysqlDump());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
示例11: getRequestFactory
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
/**
* Gets request factory.
*
* @param parser the parser to use for the resulting object
* @param headers additional request headers
*
* @return the request factory
*/
private HttpRequestFactory getRequestFactory(final JsonObjectParser parser, final HttpHeaders headers) {
return getConf().getHttpTransport().createRequestFactory( new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
HttpRequestInitializer c = createCredentialWithRefreshToken();
c.initialize( request );
request.setParser( parser == null ? jsonObjectParser : parser );
request.setThrowExceptionOnExecuteError( false );
request.setSuppressUserAgentSuffix( true );
HttpHeaders head = getDefaultHeaders();
if ( headers != null ) {
if ( head != null ) {
headers.fromHttpHeaders( head );
}
head = headers;
}
request.setHeaders( head );
}
} );
}
示例12: testMediaFiles
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
/**
* Test media files.
*
* @throws AudioBoxException the audio box exception
*/
@Test
public void testMediaFiles() throws IOException {
final Playlist p = Playlists.getDropboxPlaylist( c );
p.addObserver( new Observer() {
@Override
public void update(Observable o, Object arg) {
assertSame( o, p );
assertTrue(arg instanceof ModelEvent );
ModelEvent e = ( ModelEvent ) arg;
assertTrue( e.source instanceof MediaFile );
assertTrue( e.target instanceof EventedModelList);
}
});
JsonObjectParser parser = new AudioBoxObjectParser( c, new MediaFiles.MediaCollectionCustomParser( p ) );
List<? extends MediaFile> m = p.getMediaFiles( c, parser );
assertNotNull( m );
}
示例13: Register
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
/**
* @param transport HTTP transport
* @param httpRequestInitializer HTTP request initializer or {@code null} for none
* @param rootUrl root URL of the service
* @param servicePath service path
* @param jsonObjectParser JSON object parser
* @param googleClientRequestInitializer Google request initializer or {@code null} for none
* @param applicationName application name to be sent in the User-Agent header of requests or
* {@code null} for none
* @param suppressPatternChecks whether discovery pattern checks should be suppressed on required
* parameters
*/
Register(HttpTransport transport,
HttpRequestInitializer httpRequestInitializer,
String rootUrl,
String servicePath,
JsonObjectParser jsonObjectParser,
GoogleClientRequestInitializer googleClientRequestInitializer,
String applicationName,
boolean suppressPatternChecks) {
super(transport,
httpRequestInitializer,
rootUrl,
servicePath,
jsonObjectParser,
googleClientRequestInitializer,
applicationName,
suppressPatternChecks);
}
示例14: Widerst
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
/**
* @param transport HTTP transport
* @param httpRequestInitializer HTTP request initializer or {@code null} for none
* @param rootUrl root URL of the service
* @param servicePath service path
* @param jsonObjectParser JSON object parser
* @param googleClientRequestInitializer Google request initializer or {@code null} for none
* @param applicationName application name to be sent in the User-Agent header of requests or
* {@code null} for none
* @param suppressPatternChecks whether discovery pattern checks should be suppressed on required
* parameters
*/
Widerst(HttpTransport transport,
HttpRequestInitializer httpRequestInitializer,
String rootUrl,
String servicePath,
JsonObjectParser jsonObjectParser,
GoogleClientRequestInitializer googleClientRequestInitializer,
String applicationName,
boolean suppressPatternChecks) {
super(transport,
httpRequestInitializer,
rootUrl,
servicePath,
jsonObjectParser,
googleClientRequestInitializer,
applicationName,
suppressPatternChecks);
}
示例15: RequestFactory
import com.google.api.client.json.JsonObjectParser; //導入依賴的package包/類
public RequestFactory(final String proto, final String host, final Integer port) {
this.proto = proto;
this.host = host;
this.port = port;
this.executeUrl = new GenericUrl(String.format("%s://%s:%d/db/execute", this.proto, this.host, this.port));
this.queryUrl = new GenericUrl(String.format("%s://%s:%d/db/query", this.proto, this.host, this.port));
this.statusUrl = new GenericUrl(String.format("%s://%s:%d/status", this.proto, this.host, this.port));
this.requestFactory = HTTP_TRANSPORT.createRequestFactory(new HttpRequestInitializer() {
public void initialize(HttpRequest request) {
request.setParser(new JsonObjectParser(JSON_FACTORY));
}
});
}