當前位置: 首頁>>代碼示例>>Java>>正文


Java NetHttpTransport.Builder方法代碼示例

本文整理匯總了Java中com.google.api.client.http.javanet.NetHttpTransport.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java NetHttpTransport.Builder方法的具體用法?Java NetHttpTransport.Builder怎麽用?Java NetHttpTransport.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.http.javanet.NetHttpTransport的用法示例。


在下文中一共展示了NetHttpTransport.Builder方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import com.google.api.client.http.javanet.NetHttpTransport; //導入方法依賴的package包/類
private void init() {
    NetHttpTransport.Builder netBuilder = new NetHttpTransport.Builder();
    Proxy proxy = ProxyManager.getProxyIf();
    if (proxy != null) {
        netBuilder.setProxy(proxy);
    }
    this.customsearch = new Customsearch(netBuilder.build(), new JacksonFactory(), httpRequest -> {
    });
}
 
開發者ID:oxaoo,項目名稱:mingi,代碼行數:10,代碼來源:WebSearchFinder.java

示例2: getHttpTransport

import com.google.api.client.http.javanet.NetHttpTransport; //導入方法依賴的package包/類
public NetHttpTransport getHttpTransport() throws GeneralSecurityException, IOException {
    if (httpTransport == null) {
        GoogleDriveConnectionProperties conn = getConnectionProperties();
        if (conn.useSSL.getValue() || conn.useProxy.getValue()) {
            Builder tmpBuilder = new NetHttpTransport.Builder();
            if (conn.useProxy.getValue()) {
                Proxy proxy = new Proxy(HTTP, createUnresolved(conn.proxyHost.getValue(), conn.proxyPort.getValue()));
                tmpBuilder.setProxy(proxy);
            }
            if (conn.useSSL.getValue()) {
                TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                FileInputStream fi = new FileInputStream(conn.sslTrustStore.getValue());
                KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
                ks.load(fi, conn.sslTrustStorePassword.getValue().toCharArray());
                fi.close();
                tmf.init(ks);
                SSLContext sslContext = SSLContext.getInstance(conn.sslAlgorithm.getValue());
                sslContext.init(null, tmf.getTrustManagers(), new java.security.SecureRandom());
                tmpBuilder.setSslSocketFactory(sslContext.getSocketFactory());
            }
            httpTransport = tmpBuilder.build();
        } else {
            httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        }
    }

    return httpTransport;
}
 
開發者ID:Talend,項目名稱:components,代碼行數:29,代碼來源:GoogleDriveRuntime.java

示例3: executeMultipartRequest

import com.google.api.client.http.javanet.NetHttpTransport; //導入方法依賴的package包/類
/**
 * This method handles the final upload to the
 * {@link SteemJImageUploadConfig#getSteemitImagesEndpoint()
 * SteemitImagesEndpoint}.
 * 
 * @param accountName
 *            The Steem account used to sign the upload.
 * @param signature
 *            The signature for this upload.
 * @param fileToUpload
 *            The image to upload.
 * @return A URL object that contains the download URL of the image.
 * @throws HttpResponseException
 *             In case the
 *             {@link SteemJImageUploadConfig#getSteemitImagesEndpoint()
 *             SteemitImagesEndpoint} returned an error.
 */
private static URL executeMultipartRequest(AccountName accountName, String signature, File fileToUpload)
        throws IOException {
    NetHttpTransport.Builder builder = new NetHttpTransport.Builder();

    MultipartContent content = new MultipartContent().setMediaType(new HttpMediaType("multipart/form-data")
            .setParameter("boundary", "----WebKitFormBoundaryaAsqCuJ0UrJUS0dz"));

    FileContent fileContent = new FileContent(URLConnection.guessContentTypeFromName(fileToUpload.getName()),
            fileToUpload);

    MultipartContent.Part part = new MultipartContent.Part(fileContent);

    part.setHeaders(new HttpHeaders().set("Content-Disposition",
            String.format("form-data; name=\"image\"; filename=\"%s\"", fileToUpload.getName())));

    content.addPart(part);

    HttpRequest httpRequest = builder.build().createRequestFactory(new HttpClientRequestInitializer())
            .buildPostRequest(new GenericUrl(SteemJImageUploadConfig.getInstance().getSteemitImagesEndpoint() + "/"
                    + accountName.getName() + "/" + signature), content);

    LOGGER.debug("{} {}", httpRequest.getRequestMethod(), httpRequest.getUrl().toURI());

    HttpResponse httpResponse = httpRequest.execute();

    LOGGER.debug("{} {} {} ({})", httpResponse.getRequest().getRequestMethod(),
            httpResponse.getRequest().getUrl().toURI(), httpResponse.getStatusCode(),
            httpResponse.getStatusMessage());

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode response = objectMapper.readTree(httpResponse.parseAsString());

    return new URL(response.get("url").asText());
}
 
開發者ID:marvin-we,項目名稱:steemj-image-upload,代碼行數:52,代碼來源:SteemJImageUpload.java

示例4: start

import com.google.api.client.http.javanet.NetHttpTransport; //導入方法依賴的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);
  }
 
開發者ID:jcustenborder,項目名稱:kafka-connect-splunk,代碼行數:72,代碼來源:SplunkHttpSinkTask.java

示例5: createNetHttpTransport

import com.google.api.client.http.javanet.NetHttpTransport; //導入方法依賴的package包/類
/**
 * Create an {@link NetHttpTransport} for calling Google APIs with an optional HTTP proxy.
 *
 * @param proxy Optional HTTP proxy to use with the transport.
 * @return The resulting HttpTransport.
 * @throws IOException If there is an issue connecting to Google's certification server.
 * @throws GeneralSecurityException If there is a security issue with the keystore.
 */
public static NetHttpTransport createNetHttpTransport(@Nullable Proxy proxy)
    throws IOException, GeneralSecurityException {
  NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
  builder.trustCertificates(GoogleUtils.getCertificateTrustStore());
  builder.setProxy(proxy);
  return builder.build();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:bigdata-interop,代碼行數:16,代碼來源:HttpTransportFactory.java


注:本文中的com.google.api.client.http.javanet.NetHttpTransport.Builder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。