当前位置: 首页>>代码示例>>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;未经允许,请勿转载。