Package com.google.api.client.http

Examples of com.google.api.client.http.HttpRequestFactory


    long time = System.currentTimeMillis();
    boolean success = false;
    final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

    try {
      HttpRequestFactory requestFactory = HTTP_TRANSPORT
          .createRequestFactory(new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest request) {
            }
          });
      GenericUrl url = new GenericUrl(_url);

      HttpContent hc = new AbstractHttpContent("text/json") {
        String content = serialize(jsonServiceRequest_);
        @Override
        public long getLength() throws IOException {
          return content.getBytes("utf-8").length;
        }
        @Override
        public void writeTo(OutputStream out_) throws IOException {
          boolean logArgs = !servicesToNotLogArgs.contains(jsonServiceRequest_.getService());
          if (logArgs) {
            if (maxPayloadLengthToLog < 0 || content.length() <= maxPayloadLengthToLog) {
              logger.info("calling service: {}", content);
            } else {
              if (logger.isDebugEnabled()) {
                logger.info("calling service: {}", content);
              } else {
                String service = String.format("service: %s%s, reqId: %s, sessionId: %s, userId: %s",
                    _url, jsonServiceRequest_.getService(), jsonServiceRequest_.getReqId(),
                    jsonServiceRequest_.getSessionId(), jsonServiceRequest_.getUserId());

                int argsLen = content.length();
                String chunck = content.substring(0, maxPayloadLengthToLog);
                logger.info(String.format("calling %s, payload: %s... %d chars (truncated - full content in debug level)",
                  service, chunck, argsLen));
              }
            }
          } else {
            String service = String.format("service: %s%s, reqId: %s, sessionId: %s, userId: %s",
                _url, jsonServiceRequest_.getService(), jsonServiceRequest_.getReqId(),
                jsonServiceRequest_.getSessionId(), jsonServiceRequest_.getUserId());
            logger.info("calling {}, payload: /*censored*/",
                service);
          }
          out_.write(content.getBytes("utf-8"));
          out_.flush();
        }
      };

      HttpRequest request = requestFactory.buildPostRequest(url, hc);
      HttpResponse resp = request.execute();
      InputStream is = resp.getContent();
      String reqLogInfo = String.format("reqId: %s, sessionId: %s",
          jsonServiceRequest_.getReqId(), jsonServiceRequest_.getSessionId());
      StreamHandler jsh = getStreamHandler();
View Full Code Here


      // generate the signature
      params.computeSignature(requestMethod, url);

      // make the request
      HttpTransport transport = new NetHttpTransport();
      HttpRequestFactory f = null;
      if (useOAuth) {
        f = transport.createRequestFactory(params);
      } else {
        f = transport.createRequestFactory();
      }
      HttpRequest request = null;
      if ("POST".equals(requestMethod))
        if (postData == null)
          request = f.buildPostRequest(url, null);
        else
          request = f.buildPostRequest(url, new UrlEncodedContent(postData));
      else
        request = f.buildGetRequest(url);

      if (readTimeout != -1)
        request.setReadTimeout(readTimeout);
      if (connectionTimeout != -1)
        request.setConnectTimeout(connectionTimeout);
View Full Code Here

    // generate the signature
    params.computeSignature(requestMethod, url);

    // make the request
    HttpTransport transport = new NetHttpTransport();
    HttpRequestFactory f = null;
    if (useOAuth) {
      f = transport.createRequestFactory(params);
    } else {
      f = transport.createRequestFactory();
    }
    HttpRequest request = null;
    if ("POST".equals(requestMethod))
      if (postData == null)
        request = f.buildPostRequest(url, null);
      else
        request = f.buildPostRequest(url, new UrlEncodedContent(postData));
    else
      request = f.buildGetRequest(url);

    if (readTimeout != -1)
      request.setReadTimeout(readTimeout);
    if (connectionTimeout != -1)
      request.setConnectTimeout(connectionTimeout);
View Full Code Here

      // generate the signature
      params.computeSignature(requestMethod, url);

      // make the request
      HttpTransport transport = new NetHttpTransport();
      HttpRequestFactory f = null;
      if (useOAuth) {
        f = transport.createRequestFactory(params);
      } else {
        f = transport.createRequestFactory();
      }
      HttpRequest request = null;
      if ("POST".equals(requestMethod))
        if (postData == null)
          request = f.buildPostRequest(url, null);
        else
          request = f.buildPostRequest(url, new UrlEncodedContent(postData));
      else
        request = f.buildGetRequest(url);
      HttpHeaders headers = new HttpHeaders();
      headers.set("X-Factual-Lib", DRIVER_HEADER_TAG);
      headers.set("Host", host);
      request.setHeaders(headers);
View Full Code Here

      // generate the signature
      params.computeSignature(requestMethod, url);

      // make the request
      HttpTransport transport = new NetHttpTransport();
      HttpRequestFactory f = null;
      if (useOAuth) {
        f = transport.createRequestFactory(params);
      } else {
        f = transport.createRequestFactory();
      }
      HttpRequest request = null;
      if ("POST".equals(requestMethod))
        if (postData == null)
          request = f.buildPostRequest(url, null);
        else
          request = f.buildPostRequest(url, new UrlEncodedContent(postData));
      else
        request = f.buildGetRequest(url);
      HttpHeaders headers = new HttpHeaders();
      headers.set("X-Factual-Lib", DRIVER_HEADER_TAG);
      headers.set("Host", host);

      if (headerProvider != null) {
View Full Code Here

    // generate the signature
    params.computeSignature(requestMethod, url);

    // make the request
    HttpTransport transport = new NetHttpTransport();
    HttpRequestFactory f = null;
    if (useOAuth) {
      f = transport.createRequestFactory(params);
    } else {
      f = transport.createRequestFactory();
    }
    HttpRequest request = null;
    if ("POST".equals(requestMethod))
      if (postData == null)
        request = f.buildPostRequest(url, null);
      else
        request = f.buildPostRequest(url, new UrlEncodedContent(postData));
    else
      request = f.buildGetRequest(url);

    if (readTimeout != -1)
      request.setReadTimeout(readTimeout);
    if (connectionTimeout != -1)
      request.setConnectTimeout(connectionTimeout);
View Full Code Here

        .build();
    when(authorizationHeaderProvider.getAuthorizationHeader(session, ENDPOINT_URL.build()))
        .thenReturn("GoogleLogin fooclientlogintoken");
    when(userAgentCombiner.getUserAgent(anyString())).thenReturn("foouseragent");
    ReportRequestFactoryHelper helper = new ReportRequestFactoryHelper(session, internals);
    HttpRequestFactory requestFactory = helper.getHttpRequestFactory(ENDPOINT_URL.build());
    HttpRequest request = requestFactory.buildPostRequest(
        ENDPOINT_URL, new AwqlReportBodyProvider("select 1", "csv").getHttpContent());
    assertEquals(42, request.getConnectTimeout());
    assertEquals(42, request.getReadTimeout());
    HttpHeaders headers = request.getHeaders();
    assertEquals("foodevtoken", headers.get("developerToken"));
View Full Code Here

      // generate the signature
      params.computeSignature(requestMethod, url);

      // make the request
      HttpTransport transport = new NetHttpTransport();
      HttpRequestFactory f = null;
      if (useOAuth) {
        f = transport.createRequestFactory(params);
      } else {
        f = transport.createRequestFactory();
      }
      HttpRequest request = null;
      if ("POST".equals(requestMethod))
        if (postData == null)
          request = f.buildPostRequest(url, null);
        else
          request = f.buildPostRequest(url, new UrlEncodedContent(postData));
      else
        request = f.buildGetRequest(url);
      HttpHeaders headers = new HttpHeaders();
      headers.set("X-Factual-Lib", DRIVER_HEADER_TAG);
      headers.set("Host", host);

      if (headerProvider != null) {
View Full Code Here

    // generate the signature
    params.computeSignature(requestMethod, url);

    // make the request
    HttpTransport transport = new NetHttpTransport();
    HttpRequestFactory f = null;
    if (useOAuth) {
      f = transport.createRequestFactory(params);
    } else {
      f = transport.createRequestFactory();
    }
    HttpRequest request = null;
    if ("POST".equals(requestMethod))
      if (postData == null)
        request = f.buildPostRequest(url, null);
      else
        request = f.buildPostRequest(url, new UrlEncodedContent(postData));
    else
      request = f.buildGetRequest(url);

    if (readTimeout != -1)
      request.setReadTimeout(readTimeout);
    if (connectionTimeout != -1)
      request.setConnectTimeout(connectionTimeout);
View Full Code Here

      // generate the signature
      params.computeSignature(requestMethod, url);

      // make the request
      HttpTransport transport = new NetHttpTransport();
      HttpRequestFactory f = null;
      if (useOAuth) {
        f = transport.createRequestFactory(params);
      } else {
        f = transport.createRequestFactory();
      }
      HttpRequest request = null;
      if ("POST".equals(requestMethod))
        if (postData == null)
          request = f.buildPostRequest(url, null);
        else
          request = f.buildPostRequest(url, new UrlEncodedContent(postData));
      else
        request = f.buildGetRequest(url);
      HttpHeaders headers = new HttpHeaders();
      headers.set("X-Factual-Lib", DRIVER_HEADER_TAG);
      headers.set("Host", host);
      request.setHeaders(headers);
View Full Code Here

TOP

Related Classes of com.google.api.client.http.HttpRequestFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.