/** Logs in in via WebTls and return the auth cookie to use**/ public String loginViaCertificate() throws GeneralSecurityException, IOException { SSLSocketFactory sslSocketFactory = getSocketFactory(); HttpTransport transport = new NetHttpTransport.Builder() .setSslSocketFactory(sslSocketFactory) .build(); return makeCall(transport); }
new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer()
/** * Provides HttpTransport. If both proxyUrl and postStr is defined, it provides transport with Proxy. * @param proxyUrl Optional. * @param portStr Optional. String type for port so that user can easily pass null. (e.g: state.getProp(key)) * @return * @throws NumberFormatException * @throws GeneralSecurityException * @throws IOException */ public static HttpTransport newTransport(String proxyUrl, String portStr) throws NumberFormatException, GeneralSecurityException, IOException { if (!StringUtils.isEmpty(proxyUrl) && !StringUtils.isEmpty(portStr)) { return new NetHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()) .setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl, Integer.parseInt(portStr)))) .build(); } return GoogleNetHttpTransport.newTrustedTransport(); }
@Before public void setUp() throws IOException { httpRequest = new NetHttpTransport() .createRequestFactory() .buildRequest("GET", new GenericUrl("https://www.google.com"), null); }
return new NetHttpTransport.Builder().setProxy(proxy).build();
private static HttpTransport _createHttpTransport() throws GeneralSecurityException, IOException { HttpTransport httpTransport = new NetHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()) .build(); return httpTransport; }
@Override public HttpTransport create() { // Consider App Engine Standard if (PlatformInformation.isOnGAEStandard7()) { try { return new UrlFetchTransport(); } catch (Exception ignore) { // Maybe not on App Engine } } return new NetHttpTransport(); } }
NetHttpTransport.Builder transportBuilder = new NetHttpTransport.Builder() .trustCertificates(GoogleUtils.getCertificateTrustStore()); if (null != builder.proxyHost) { transportBuilder.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(builder.proxyHost, builder.proxyPort))); NetHttpTransport transport = transportBuilder.build();
HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); String[] SCOPESArray = {"https://spreadsheets.google.com/feeds", "https://spreadsheets.google.com/feeds/spreadsheets/private/full", "https://docs.google.com/feeds"};
try { final String token = result.getResult().getString(AccountManager.KEY_AUTHTOKEN); HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); Drive.Builder b = new Drive.Builder(httpTransport, jsonFactory, null);
private static HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); private static JsonFactory JSON_FACTORY = new com.google.api.client.json.jackson2.JacksonFactory();
extensionContext.registerService(HttpTransport.class, new NetHttpTransport()); extensionContext.registerService(JsonFactory.class, new JacksonFactory());
private static String getAppEngineProjectIdFromMetadataServer() throws IOException { String metadata = "http://metadata.google.internal"; String projectIdURL = "/computeMetadata/v1/project/project-id"; GenericUrl url = new GenericUrl(metadata + projectIdURL); HttpTransport netHttpTransport = new NetHttpTransport(); HttpRequestFactory requestFactory = netHttpTransport.createRequestFactory(); HttpRequest request = requestFactory .buildGetRequest(url) .setConnectTimeout(500) .setReadTimeout(500) .setHeaders(new HttpHeaders().set("Metadata-Flavor", "Google")); HttpResponse response = request.execute(); return headerContainsMetadataFlavor(response) ? response.parseAsString() : null; }
extensionContext.registerService(HttpTransport.class, new NetHttpTransport()); extensionContext.registerService(JsonFactory.class, new JacksonFactory()); extensionContext.registerService(HttpTransport.class, new NetHttpTransport()); extensionContext.registerService(JobStore.class, cloudExtension.getJobStore()); extensionContext.registerService(
/** * Performs all necessary setup steps for running requests against the API. * * @return An initialized AdSense service object. * @throws Exception */ private static AdSense initializeAdsense() throws Exception { // Authorization. Credential credential = authorize(); // Set up AdSense Management API client. AdSense adsense = new AdSense.Builder( new NetHttpTransport(), JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME) .build(); return adsense; }
/** * Performs all necessary setup steps for running requests against the API. * * @return An initialized AdExchangeSeller service object. * @throws Exception */ private static AdExchangeSeller initializeAdExchangeSeller() throws Exception { // Authorization. Credential credential = authorize(); // Set up Ad Exchange Seller REST API client. AdExchangeSeller adExchangeSeller = new AdExchangeSeller.Builder( new NetHttpTransport(), JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME) .build(); return adExchangeSeller; }
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken); Oauth2 oauth2 = new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName( "Oauth2").build(); Userinfoplus userinfo = oauth2.userinfo().get().execute(); userinfo.toPrettyString();
HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); GoogleCredential credential = new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(jsonFactory) .setClientSecrets("client_id", "client_secret").build(); credential.setAccessToken("access_token");
/** * Performs all necessary setup steps for running requests against the API. * * @return An initialized AdSenseHost service object. * @throws Exception */ private static AdSenseHost initializeAdsensehost() throws Exception { // Authorization. Credential credential = authorize(); // Set up AdSense Host API client. AdSenseHost adsensehost = new AdSenseHost.Builder( new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName( APPLICATION_NAME).build(); return adsensehost; }
import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import java.io.IOException; import java.io.InputStream; public class Network { static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); public void getRequest(String reqUrl) throws IOException { GenericUrl url = new GenericUrl(reqUrl); HttpRequest request = HTTP_TRANSPORT.createRequestFactory().buildGetRequest(url); HttpResponse response = request.execute(); System.out.println(response.getStatusCode()); InputStream is = response.getContent(); int ch; while ((ch = is.read()) != -1) { System.out.print((char) ch); } response.disconnect(); } }